Skip to content

Commit

Permalink
Fix repositories not using type wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
lorefnon committed Apr 26, 2024
1 parent 9abe9f2 commit 4be5c99
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 66 deletions.
4 changes: 2 additions & 2 deletions docs/classes/Generator.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/CommonCustomTypesOptions.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/interfaces/CommonOptions.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/CommonPrimaryKeyOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/CommonTypeAdapterOptions.html

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/interfaces/ExportOptions.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/interfaces/FieldMapping.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/GeneratedField.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/interfaces/GeneratedFieldType.html

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions docs/interfaces/GeneratorOpts.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/interfaces/ImportedItem.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/TableInclusion.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/StrOrRegExp.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/fieldMappings.html

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,12 @@ export class Generator {
tableName: string,
tableKind: TableKind,
mapperClassName: string,
imports: ImportTmplInput[]
imports: ImportTmplInput[],

) {
const rowTypes = this.opts.export?.rowTypes
const isExported = this.opts.export?.rowTypes;
const hasRepo = this.opts.export?.crudRepository;
const rowTypes = (isExported || hasRepo)
? ({} as any)
: false;
if (rowTypes !== false) {
Expand All @@ -781,17 +784,20 @@ export class Generator {
`SelectedRow<${mapperClassName}>`,
imports
);
rowTypes.selected.isExported = isExported;
if (tableKind !== "View") {
rowTypes.insertable = this.getWrappedTypeInput(
this.getInsertableRowTypeName(tableName),
`InsertableRow<${mapperClassName}>`,
imports
);
rowTypes.insertable.isExported = isExported;
rowTypes.updatable = this.getWrappedTypeInput(
this.getUpdatableRowTypeName(tableName),
`UpdatableRow<${mapperClassName}>`,
imports
);
rowTypes.updatable.isExported = isExported;
}
}
return rowTypes
Expand Down
8 changes: 4 additions & 4 deletions src/template.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class {{repo.className}} {
{{/if}}
{{#if repo.methods.insertOne}}

{{repo.methods.insertOne}}(row: InsertableRow<{{className}}>, conn = this.getConnection()) {
{{repo.methods.insertOne}}(row: {{rowTypes.insertable.name}}, conn = this.getConnection()) {
return this.insert(conn)
.set(row)
.returning(this.tableCols)
Expand All @@ -171,7 +171,7 @@ export class {{repo.className}} {
{{/if}}
{{#if repo.methods.insertMany}}

{{repo.methods.insertMany}}(rows: InsertableRow<{{className}}>[], conn = this.getConnection()) {
{{repo.methods.insertMany}}(rows: {{rowTypes.insertable.name}}[], conn = this.getConnection()) {
return this.insert(conn)
.values(rows)
.returning(this.tableCols)
Expand All @@ -186,7 +186,7 @@ export class {{repo.className}} {
{{/if}}
{{#if repo.methods.updateOne}}

{{repo.methods.updateOne}}({{pkField.name}}: {{className}}Pk, update: UpdatableRow<{{className}}>, conn = this.getConnection()) {
{{repo.methods.updateOne}}({{pkField.name}}: {{className}}Pk, update: {{rowTypes.updatable.name}}, conn = this.getConnection()) {
return this.update(conn)
.set(update)
.where(this.table.{{pkField.name}}.equals({{pkField.name}}))
Expand All @@ -196,7 +196,7 @@ export class {{repo.className}} {
{{/if}}
{{#if repo.methods.updateMany}}

{{repo.methods.updateMany}}({{pkField.name}}List: {{className}}Pk[], update: UpdatableRow<{{className}}>, conn = this.getConnection()) {
{{repo.methods.updateMany}}({{pkField.name}}List: {{className}}Pk[], update: {{rowTypes.updatable.name}}, conn = this.getConnection()) {
return this.update(conn)
.set(update)
.where(this.table.{{pkField.name}}.in({{pkField.name}}List))
Expand Down

0 comments on commit 4be5c99

Please sign in to comment.