Skip to content

Commit 7ea56fc

Browse files
committed
Add idField type
Change-type: patch
1 parent 305a695 commit 7ea56fc

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

src/generate.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ const relationshipsToInterfaceProps = (
240240
});
241241
};
242242

243+
const getIdField = (table: AbstractSqlTable) => {
244+
return table.idField;
245+
};
246+
243247
const tableToInterface = (
244248
m: RequiredModelSubset,
245249
table: AbstractSqlTable,
@@ -258,6 +262,7 @@ const tableToInterface = (
258262
}`;
259263
return trimNL`
260264
export interface ${modelNameToCamelCaseName(table.name)} {
265+
IDField: '${getIdField(table)}';
261266
Read: {
262267
${[
263268
...fieldsToInterfaceProps(m, table.fields, 'Read', opts),

test/index.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,42 @@ const testTable: Partial<AbstractSqlModel> = {
236236
},
237237
],
238238
},
239+
event: {
240+
fields: [
241+
{
242+
dataType: 'Date Time',
243+
fieldName: 'created at',
244+
required: true,
245+
defaultValue: 'CURRENT_TIMESTAMP',
246+
},
247+
{
248+
dataType: 'Date Time',
249+
fieldName: 'modified at',
250+
required: true,
251+
defaultValue: 'CURRENT_TIMESTAMP',
252+
},
253+
{
254+
dataType: 'Short Text',
255+
fieldName: 'uuid',
256+
required: true,
257+
index: 'PRIMARY KEY',
258+
computed: ['Field', 'uuid'],
259+
},
260+
],
261+
primitive: false,
262+
name: 'event',
263+
indexes: [],
264+
idField: 'uuid',
265+
resourceName: 'event',
266+
triggers: [
267+
{
268+
when: 'BEFORE',
269+
operation: 'UPDATE',
270+
level: 'ROW',
271+
fnName: 'trigger_update_modified_at',
272+
},
273+
],
274+
},
239275
},
240276
relationships: {
241277
test: {
@@ -311,6 +347,7 @@ test(
311347
testTable,
312348
source`
313349
export interface Parent {
350+
IDField: 'id';
314351
Read: {
315352
created_at: Types['Date Time']['Read'];
316353
modified_at: Types['Date Time']['Read'];
@@ -323,6 +360,7 @@ test(
323360
}
324361
325362
export interface Other {
363+
IDField: 'id';
326364
Read: {
327365
created_at: Types['Date Time']['Read'];
328366
modified_at: Types['Date Time']['Read'];
@@ -336,6 +374,7 @@ test(
336374
}
337375
338376
export interface Test {
377+
IDField: 'id';
339378
Read: {
340379
created_at: Types['Date Time']['Read'];
341380
modified_at: Types['Date Time']['Read'];
@@ -361,6 +400,7 @@ test(
361400
}
362401
363402
export interface TestTag {
403+
IDField: 'id';
364404
Read: {
365405
created_at: Types['Date Time']['Read'];
366406
modified_at: Types['Date Time']['Read'];
@@ -377,11 +417,25 @@ test(
377417
};
378418
}
379419
420+
export interface Event {
421+
IDField: 'uuid';
422+
Read: {
423+
created_at: Types['Date Time']['Read'];
424+
modified_at: Types['Date Time']['Read'];
425+
uuid: Types['Short Text']['Read'];
426+
};
427+
Write: {
428+
created_at: Types['Date Time']['Write'];
429+
modified_at: Types['Date Time']['Write'];
430+
};
431+
}
432+
380433
export default interface $Model {
381434
parent: Parent;
382435
other: Other;
383436
test: Test;
384437
test__has__tag_key: TestTag;
438+
event: Event;
385439
// Synonyms
386440
test_tag: TestTag;
387441
}
@@ -393,6 +447,7 @@ test(
393447
testTable,
394448
source`
395449
export interface Parent {
450+
IDField: 'id';
396451
Read: {
397452
created_at: Types['Date Time']['Read'];
398453
modified_at: Types['Date Time']['Read'];
@@ -405,6 +460,7 @@ test(
405460
}
406461
407462
export interface Other {
463+
IDField: 'id';
408464
Read: {
409465
created_at: Types['Date Time']['Read'];
410466
modified_at: Types['Date Time']['Read'];
@@ -418,6 +474,7 @@ test(
418474
}
419475
420476
export interface Test {
477+
IDField: 'id';
421478
Read: {
422479
created_at: Types['Date Time']['Read'];
423480
modified_at: Types['Date Time']['Read'];
@@ -443,6 +500,7 @@ test(
443500
}
444501
445502
export interface TestTag {
503+
IDField: 'id';
446504
Read: {
447505
created_at: Types['Date Time']['Read'];
448506
modified_at: Types['Date Time']['Read'];
@@ -459,11 +517,25 @@ test(
459517
};
460518
}
461519
520+
export interface Event {
521+
IDField: 'uuid';
522+
Read: {
523+
created_at: Types['Date Time']['Read'];
524+
modified_at: Types['Date Time']['Read'];
525+
uuid: Types['Short Text']['Read'];
526+
};
527+
Write: {
528+
created_at: Types['Date Time']['Write'];
529+
modified_at: Types['Date Time']['Write'];
530+
};
531+
}
532+
462533
export default interface $Model {
463534
parent: Parent;
464535
other: Other;
465536
test: Test;
466537
test__has__tag_key: TestTag;
538+
event: Event;
467539
// Synonyms
468540
test_tag: TestTag;
469541
}

0 commit comments

Comments
 (0)