@@ -203,12 +203,12 @@ function generateIdentityParams(identity: Column['identity']) {
203
203
return `.generatedByDefaultAsIdentity(${ paramsObj } )` ;
204
204
}
205
205
206
- export const paramNameFor = ( name : string , schema ?: string ) => {
207
- const schemaSuffix = schema && schema !== 'public' ? `In${ schema . capitalise ( ) } ` : '' ;
206
+ export const paramNameFor = ( name : string , schema ?: string , omitSuffixForSchema = 'public' ) => {
207
+ const schemaSuffix = schema && schema !== omitSuffixForSchema ? `In${ schema . capitalise ( ) } ` : '' ;
208
208
return `${ name } ${ schemaSuffix } ` ;
209
209
} ;
210
210
211
- export const schemaToTypeScript = ( schema : GelSchemaInternal , casing : Casing ) => {
211
+ export const schemaToTypeScript = ( schema : GelSchemaInternal , casing : Casing , omitSuffixForSchema : string ) => {
212
212
// collectFKs
213
213
Object . values ( schema . tables ) . forEach ( ( table ) => {
214
214
Object . values ( table . foreignKeys ) . forEach ( ( fk ) => {
@@ -314,7 +314,7 @@ export const schemaToTypeScript = (schema: GelSchemaInternal, casing: Casing) =>
314
314
// .map((it) => {
315
315
// const enumSchema = schemas[it.schema];
316
316
// // const func = schema || schema === "public" ? "gelTable" : schema;
317
- // const paramName = paramNameFor(it.name, enumSchema);
317
+ // const paramName = paramNameFor(it.name, enumSchema, omitSuffixForSchema );
318
318
319
319
// const func = enumSchema ? `${enumSchema}.enum` : 'gelEnum';
320
320
@@ -329,7 +329,7 @@ export const schemaToTypeScript = (schema: GelSchemaInternal, casing: Casing) =>
329
329
// const sequencesStatements = Object.values(schema.sequences)
330
330
// .map((it) => {
331
331
// const seqSchema = schemas[it.schema];
332
- // const paramName = paramNameFor(it.name, seqSchema);
332
+ // const paramName = paramNameFor(it.name, seqSchema, omitSuffixForSchema );
333
333
334
334
// const func = seqSchema ? `${seqSchema}.sequence` : 'gelSequence';
335
335
@@ -390,7 +390,7 @@ export const schemaToTypeScript = (schema: GelSchemaInternal, casing: Casing) =>
390
390
391
391
const tableStatements = Object . values ( schema . tables ) . map ( ( table ) => {
392
392
const tableSchema = schemas [ table . schema ] ;
393
- const paramName = paramNameFor ( table . name , tableSchema ) ;
393
+ const paramName = paramNameFor ( table . name , tableSchema , omitSuffixForSchema ) ;
394
394
395
395
const func = tableSchema ? `${ tableSchema } .table` : 'gelTable' ;
396
396
let statement = `export const ${ withCasing ( paramName , casing ) } = ${ func } ("${ table . name } ", {\n` ;
@@ -403,6 +403,7 @@ export const schemaToTypeScript = (schema: GelSchemaInternal, casing: Casing) =>
403
403
schemas ,
404
404
casing ,
405
405
schema . internal ,
406
+ omitSuffixForSchema ,
406
407
) ;
407
408
statement += '}' ;
408
409
@@ -423,7 +424,7 @@ export const schemaToTypeScript = (schema: GelSchemaInternal, casing: Casing) =>
423
424
statement += ', ' ;
424
425
statement += '(table) => [' ;
425
426
statement += createTableIndexes ( table . name , Object . values ( table . indexes ) , casing ) ;
426
- statement += createTableFKs ( Object . values ( table . foreignKeys ) , schemas , casing ) ;
427
+ statement += createTableFKs ( Object . values ( table . foreignKeys ) , schemas , casing , omitSuffixForSchema ) ;
427
428
statement += createTablePKs (
428
429
Object . values ( table . compositePrimaryKeys ) ,
429
430
casing ,
@@ -452,7 +453,7 @@ export const schemaToTypeScript = (schema: GelSchemaInternal, casing: Casing) =>
452
453
// .map((it) => {
453
454
// const viewSchema = schemas[it.schema];
454
455
455
- // const paramName = paramNameFor(it.name, viewSchema);
456
+ // const paramName = paramNameFor(it.name, viewSchema, omitSuffixForSchema );
456
457
457
458
// const func = viewSchema
458
459
// ? (it.materialized ? `${viewSchema}.materializedView` : `${viewSchema}.view`)
@@ -704,12 +705,13 @@ const column = (
704
705
casing : Casing ,
705
706
defaultValue ?: any ,
706
707
internals ?: GelKitInternals ,
708
+ omitSuffixForSchema ?: string ,
707
709
) => {
708
710
const isExpression = internals ?. tables [ tableName ] ?. columns [ name ] ?. isDefaultAnExpression ?? false ;
709
711
const lowered = type . toLowerCase ( ) . replace ( '[]' , '' ) ;
710
712
711
713
if ( enumTypes . has ( `${ typeSchema } .${ type . replace ( '[]' , '' ) } ` ) ) {
712
- let out = `${ withCasing ( name , casing ) } : ${ withCasing ( paramNameFor ( type . replace ( '[]' , '' ) , typeSchema ) , casing ) } (${
714
+ let out = `${ withCasing ( name , casing ) } : ${ withCasing ( paramNameFor ( type . replace ( '[]' , '' ) , typeSchema , omitSuffixForSchema ) , casing ) } (${
713
715
dbColumnName ( { name, casing } )
714
716
} )`;
715
717
return out ;
@@ -839,6 +841,7 @@ const createTableColumns = (
839
841
schemas : Record < string , string > ,
840
842
casing : Casing ,
841
843
internals : GelKitInternals ,
844
+ omitSuffixForSchema ?: string ,
842
845
) : string => {
843
846
let statement = '' ;
844
847
@@ -866,6 +869,7 @@ const createTableColumns = (
866
869
casing ,
867
870
it . default ,
868
871
internals ,
872
+ omitSuffixForSchema ,
869
873
) ;
870
874
statement += '\t' ;
871
875
statement += columnStatement ;
@@ -882,7 +886,7 @@ const createTableColumns = (
882
886
statement += it . generated ? `.generatedAlwaysAs(sql\`${ it . generated . as } \`)` : '' ;
883
887
884
888
// const fks = fkByColumnName[it.name];
885
- // Andrii: I switched it off until we will get a custom naem setting in references
889
+ // Andrii: I switched it off until we will get a custom name setting in references
886
890
// if (fks) {
887
891
// const fksStatement = fks
888
892
// .map((it) => {
@@ -894,7 +898,7 @@ const createTableColumns = (
894
898
895
899
// const paramsStr = objToStatement2(params);
896
900
// const tableSchema = schemas[it.schemaTo || ''];
897
- // const paramName = paramNameFor(it.tableTo, tableSchema);
901
+ // const paramName = paramNameFor(it.tableTo, tableSchema, omitSuffixForSchema );
898
902
// if (paramsStr) {
899
903
// return `.references(()${typeSuffix} => ${
900
904
// withCasing(
@@ -1062,12 +1066,17 @@ const createTableChecks = (
1062
1066
return statement ;
1063
1067
} ;
1064
1068
1065
- const createTableFKs = ( fks : ForeignKey [ ] , schemas : Record < string , string > , casing : Casing ) : string => {
1069
+ const createTableFKs = (
1070
+ fks : ForeignKey [ ] ,
1071
+ schemas : Record < string , string > ,
1072
+ casing : Casing ,
1073
+ omitSuffixForSchema ?: string ,
1074
+ ) : string => {
1066
1075
let statement = '' ;
1067
1076
1068
1077
fks . forEach ( ( it ) => {
1069
1078
const tableSchema = schemas [ it . schemaTo || '' ] ;
1070
- const paramName = paramNameFor ( it . tableTo , tableSchema ) ;
1079
+ const paramName = paramNameFor ( it . tableTo , tableSchema , omitSuffixForSchema ) ;
1071
1080
1072
1081
const isSelf = it . tableTo === it . tableFrom ;
1073
1082
const tableTo = isSelf ? 'table' : `${ withCasing ( paramName , casing ) } ` ;
0 commit comments