@remix-run/data-table-postgres 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/lib/adapter.d.ts +12 -8
- package/dist/lib/adapter.d.ts.map +1 -1
- package/dist/lib/adapter.js +14 -406
- package/dist/lib/sql-compiler.js +173 -7
- package/package.json +4 -4
- package/src/lib/adapter.ts +15 -486
- package/src/lib/sql-compiler.ts +227 -8
package/src/lib/adapter.ts
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
DataMigrationRequest,
|
|
3
2
|
DataManipulationRequest,
|
|
4
|
-
DataMigrationResult,
|
|
5
|
-
DataMigrationOperation,
|
|
6
3
|
DataManipulationResult,
|
|
7
4
|
DataManipulationOperation,
|
|
8
5
|
DatabaseAdapter,
|
|
9
|
-
ColumnDefinition,
|
|
10
6
|
SqlStatement,
|
|
11
7
|
TableRef,
|
|
12
8
|
TransactionOptions,
|
|
13
9
|
TransactionToken,
|
|
14
10
|
} from '@remix-run/data-table'
|
|
15
11
|
import { getTablePrimaryKey } from '@remix-run/data-table'
|
|
16
|
-
import {
|
|
17
|
-
isDataManipulationOperation as isDataManipulationOperationHelper,
|
|
18
|
-
quoteLiteral as quoteLiteralHelper,
|
|
19
|
-
quoteTableRef as quoteTableRefHelper,
|
|
20
|
-
} from '@remix-run/data-table/sql-helpers'
|
|
21
12
|
import type {
|
|
22
13
|
Client as PostgresClient,
|
|
23
14
|
Pool as PostgresPool,
|
|
@@ -63,17 +54,13 @@ export class PostgresDatabaseAdapter implements DatabaseAdapter {
|
|
|
63
54
|
}
|
|
64
55
|
|
|
65
56
|
/**
|
|
66
|
-
* Compiles a data
|
|
57
|
+
* Compiles a data-manipulation operation to postgres SQL statements.
|
|
67
58
|
* @param operation Operation to compile.
|
|
68
59
|
* @returns Compiled SQL statements.
|
|
69
60
|
*/
|
|
70
|
-
compileSql(operation: DataManipulationOperation
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return [{ text: compiled.text, values: compiled.values }]
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return compilePostgresMigrationOperations(operation)
|
|
61
|
+
compileSql(operation: DataManipulationOperation): SqlStatement[] {
|
|
62
|
+
let compiled = compilePostgresOperation(operation)
|
|
63
|
+
return [{ text: compiled.text, values: compiled.values }]
|
|
77
64
|
}
|
|
78
65
|
|
|
79
66
|
/**
|
|
@@ -107,21 +94,17 @@ export class PostgresDatabaseAdapter implements DatabaseAdapter {
|
|
|
107
94
|
}
|
|
108
95
|
|
|
109
96
|
/**
|
|
110
|
-
* Executes postgres
|
|
111
|
-
*
|
|
112
|
-
*
|
|
97
|
+
* Executes a multi-statement postgres SQL script.
|
|
98
|
+
*
|
|
99
|
+
* Postgres natively supports multi-statement scripts when `query` is called
|
|
100
|
+
* without a parameter array.
|
|
101
|
+
* @param sql SQL script to execute.
|
|
102
|
+
* @param transaction Optional transaction token.
|
|
103
|
+
* @returns A promise that resolves once execution completes.
|
|
113
104
|
*/
|
|
114
|
-
async
|
|
115
|
-
let
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
for (let statement of statements) {
|
|
119
|
-
await client.query(statement.text, statement.values)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
affectedOperations: statements.length,
|
|
124
|
-
}
|
|
105
|
+
async executeScript(sql: string, transaction?: TransactionToken): Promise<void> {
|
|
106
|
+
let client = this.#resolveClient(transaction)
|
|
107
|
+
await client.query(sql)
|
|
125
108
|
}
|
|
126
109
|
|
|
127
110
|
/**
|
|
@@ -316,7 +299,7 @@ export class PostgresDatabaseAdapter implements DatabaseAdapter {
|
|
|
316
299
|
* ```ts
|
|
317
300
|
* import { Pool } from 'pg'
|
|
318
301
|
* import { createDatabase } from 'remix/data-table'
|
|
319
|
-
* import { createPostgresDatabaseAdapter } from 'remix/data-table
|
|
302
|
+
* import { createPostgresDatabaseAdapter } from 'remix/data-table/postgres'
|
|
320
303
|
*
|
|
321
304
|
* let pool = new Pool({ connectionString: process.env.DATABASE_URL })
|
|
322
305
|
* let adapter = createPostgresDatabaseAdapter(pool)
|
|
@@ -469,457 +452,3 @@ function isInsertOperation(
|
|
|
469
452
|
operation.kind === 'insert' || operation.kind === 'insertMany' || operation.kind === 'upsert'
|
|
470
453
|
)
|
|
471
454
|
}
|
|
472
|
-
|
|
473
|
-
function isDataManipulationOperation(
|
|
474
|
-
operation: DataManipulationOperation | DataMigrationOperation,
|
|
475
|
-
): operation is DataManipulationOperation {
|
|
476
|
-
return isDataManipulationOperationHelper(operation)
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
function compilePostgresMigrationOperations(operation: DataMigrationOperation): SqlStatement[] {
|
|
480
|
-
if (operation.kind === 'raw') {
|
|
481
|
-
return [{ text: operation.sql.text, values: [...operation.sql.values] }]
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
if (operation.kind === 'createTable') {
|
|
485
|
-
let columns = Object.keys(operation.columns).map(
|
|
486
|
-
(columnName) =>
|
|
487
|
-
quoteIdentifier(columnName) + ' ' + compilePostgresColumn(operation.columns[columnName]),
|
|
488
|
-
)
|
|
489
|
-
let tableConstraints: string[] = []
|
|
490
|
-
|
|
491
|
-
if (operation.primaryKey) {
|
|
492
|
-
tableConstraints.push(
|
|
493
|
-
'constraint ' +
|
|
494
|
-
quoteIdentifier(operation.primaryKey.name) +
|
|
495
|
-
' primary key (' +
|
|
496
|
-
operation.primaryKey.columns.map((column) => quoteIdentifier(column)).join(', ') +
|
|
497
|
-
')',
|
|
498
|
-
)
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
for (let unique of operation.uniques ?? []) {
|
|
502
|
-
tableConstraints.push(
|
|
503
|
-
'constraint ' +
|
|
504
|
-
quoteIdentifier(unique.name) +
|
|
505
|
-
' ' +
|
|
506
|
-
'unique (' +
|
|
507
|
-
unique.columns.map((column) => quoteIdentifier(column)).join(', ') +
|
|
508
|
-
')',
|
|
509
|
-
)
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
for (let check of operation.checks ?? []) {
|
|
513
|
-
tableConstraints.push(
|
|
514
|
-
'constraint ' + quoteIdentifier(check.name) + ' ' + 'check (' + check.expression + ')',
|
|
515
|
-
)
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
for (let foreignKey of operation.foreignKeys ?? []) {
|
|
519
|
-
let clause =
|
|
520
|
-
'constraint ' +
|
|
521
|
-
quoteIdentifier(foreignKey.name) +
|
|
522
|
-
' ' +
|
|
523
|
-
'foreign key (' +
|
|
524
|
-
foreignKey.columns.map((column) => quoteIdentifier(column)).join(', ') +
|
|
525
|
-
') references ' +
|
|
526
|
-
quoteTableRef(foreignKey.references.table) +
|
|
527
|
-
' (' +
|
|
528
|
-
foreignKey.references.columns.map((column) => quoteIdentifier(column)).join(', ') +
|
|
529
|
-
')'
|
|
530
|
-
|
|
531
|
-
if (foreignKey.onDelete) {
|
|
532
|
-
clause += ' on delete ' + foreignKey.onDelete
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
if (foreignKey.onUpdate) {
|
|
536
|
-
clause += ' on update ' + foreignKey.onUpdate
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
tableConstraints.push(clause)
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
let sql =
|
|
543
|
-
'create table ' +
|
|
544
|
-
(operation.ifNotExists ? 'if not exists ' : '') +
|
|
545
|
-
quoteTableRef(operation.table) +
|
|
546
|
-
' (' +
|
|
547
|
-
[...columns, ...tableConstraints].join(', ') +
|
|
548
|
-
')'
|
|
549
|
-
let statements: SqlStatement[] = [{ text: sql, values: [] }]
|
|
550
|
-
|
|
551
|
-
if (operation.comment) {
|
|
552
|
-
statements.push({
|
|
553
|
-
text:
|
|
554
|
-
'comment on table ' +
|
|
555
|
-
quoteTableRef(operation.table) +
|
|
556
|
-
' is ' +
|
|
557
|
-
quoteLiteral(operation.comment),
|
|
558
|
-
values: [],
|
|
559
|
-
})
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
return statements
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
if (operation.kind === 'alterTable') {
|
|
566
|
-
let sqlStatements: SqlStatement[] = []
|
|
567
|
-
|
|
568
|
-
for (let change of operation.changes) {
|
|
569
|
-
let sql = 'alter table ' + quoteTableRef(operation.table) + ' '
|
|
570
|
-
|
|
571
|
-
if (change.kind === 'addColumn') {
|
|
572
|
-
sql +=
|
|
573
|
-
'add column ' +
|
|
574
|
-
quoteIdentifier(change.column) +
|
|
575
|
-
' ' +
|
|
576
|
-
compilePostgresColumn(change.definition)
|
|
577
|
-
} else if (change.kind === 'changeColumn') {
|
|
578
|
-
let typeSql = compilePostgresColumnType(change.definition)
|
|
579
|
-
sql += 'alter column ' + quoteIdentifier(change.column) + ' type ' + typeSql
|
|
580
|
-
} else if (change.kind === 'renameColumn') {
|
|
581
|
-
sql += 'rename column ' + quoteIdentifier(change.from) + ' to ' + quoteIdentifier(change.to)
|
|
582
|
-
} else if (change.kind === 'dropColumn') {
|
|
583
|
-
sql +=
|
|
584
|
-
'drop column ' + (change.ifExists ? 'if exists ' : '') + quoteIdentifier(change.column)
|
|
585
|
-
} else if (change.kind === 'addPrimaryKey') {
|
|
586
|
-
sql +=
|
|
587
|
-
'add ' +
|
|
588
|
-
'constraint ' +
|
|
589
|
-
quoteIdentifier(change.constraint.name) +
|
|
590
|
-
' ' +
|
|
591
|
-
'primary key (' +
|
|
592
|
-
change.constraint.columns.map((column) => quoteIdentifier(column)).join(', ') +
|
|
593
|
-
')'
|
|
594
|
-
} else if (change.kind === 'dropPrimaryKey') {
|
|
595
|
-
sql += 'drop constraint ' + quoteIdentifier(change.name)
|
|
596
|
-
} else if (change.kind === 'addUnique') {
|
|
597
|
-
sql +=
|
|
598
|
-
'add ' +
|
|
599
|
-
'constraint ' +
|
|
600
|
-
quoteIdentifier(change.constraint.name) +
|
|
601
|
-
' ' +
|
|
602
|
-
'unique (' +
|
|
603
|
-
change.constraint.columns.map((column) => quoteIdentifier(column)).join(', ') +
|
|
604
|
-
')'
|
|
605
|
-
} else if (change.kind === 'dropUnique') {
|
|
606
|
-
sql += 'drop constraint ' + quoteIdentifier(change.name)
|
|
607
|
-
} else if (change.kind === 'addForeignKey') {
|
|
608
|
-
sql +=
|
|
609
|
-
'add ' +
|
|
610
|
-
'constraint ' +
|
|
611
|
-
quoteIdentifier(change.constraint.name) +
|
|
612
|
-
' ' +
|
|
613
|
-
'foreign key (' +
|
|
614
|
-
change.constraint.columns.map((column) => quoteIdentifier(column)).join(', ') +
|
|
615
|
-
') references ' +
|
|
616
|
-
quoteTableRef(change.constraint.references.table) +
|
|
617
|
-
' (' +
|
|
618
|
-
change.constraint.references.columns.map((column) => quoteIdentifier(column)).join(', ') +
|
|
619
|
-
')'
|
|
620
|
-
} else if (change.kind === 'dropForeignKey') {
|
|
621
|
-
sql += 'drop constraint ' + quoteIdentifier(change.name)
|
|
622
|
-
} else if (change.kind === 'addCheck') {
|
|
623
|
-
sql +=
|
|
624
|
-
'add ' +
|
|
625
|
-
'constraint ' +
|
|
626
|
-
quoteIdentifier(change.constraint.name) +
|
|
627
|
-
' ' +
|
|
628
|
-
'check (' +
|
|
629
|
-
change.constraint.expression +
|
|
630
|
-
')'
|
|
631
|
-
} else if (change.kind === 'dropCheck') {
|
|
632
|
-
sql += 'drop constraint ' + quoteIdentifier(change.name)
|
|
633
|
-
} else if (change.kind === 'setTableComment') {
|
|
634
|
-
sqlStatements.push({
|
|
635
|
-
text:
|
|
636
|
-
'comment on table ' +
|
|
637
|
-
quoteTableRef(operation.table) +
|
|
638
|
-
' is ' +
|
|
639
|
-
quoteLiteral(change.comment),
|
|
640
|
-
values: [],
|
|
641
|
-
})
|
|
642
|
-
continue
|
|
643
|
-
} else {
|
|
644
|
-
continue
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
sqlStatements.push({ text: sql, values: [] })
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
return sqlStatements
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
if (operation.kind === 'renameTable') {
|
|
654
|
-
return [
|
|
655
|
-
{
|
|
656
|
-
text:
|
|
657
|
-
'alter table ' +
|
|
658
|
-
quoteTableRef(operation.from) +
|
|
659
|
-
' rename to ' +
|
|
660
|
-
quoteIdentifier(operation.to.name),
|
|
661
|
-
values: [],
|
|
662
|
-
},
|
|
663
|
-
]
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
if (operation.kind === 'dropTable') {
|
|
667
|
-
return [
|
|
668
|
-
{
|
|
669
|
-
text:
|
|
670
|
-
'drop table ' +
|
|
671
|
-
(operation.ifExists ? 'if exists ' : '') +
|
|
672
|
-
quoteTableRef(operation.table) +
|
|
673
|
-
(operation.cascade ? ' cascade' : ''),
|
|
674
|
-
values: [],
|
|
675
|
-
},
|
|
676
|
-
]
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
if (operation.kind === 'createIndex') {
|
|
680
|
-
return [
|
|
681
|
-
{
|
|
682
|
-
text:
|
|
683
|
-
'create ' +
|
|
684
|
-
(operation.index.unique ? 'unique ' : '') +
|
|
685
|
-
'index ' +
|
|
686
|
-
(operation.ifNotExists ? 'if not exists ' : '') +
|
|
687
|
-
quoteIdentifier(operation.index.name) +
|
|
688
|
-
' on ' +
|
|
689
|
-
quoteTableRef(operation.index.table) +
|
|
690
|
-
(operation.index.using ? ' using ' + operation.index.using : '') +
|
|
691
|
-
' (' +
|
|
692
|
-
operation.index.columns.map((column) => quoteIdentifier(column)).join(', ') +
|
|
693
|
-
')' +
|
|
694
|
-
(operation.index.where ? ' where ' + operation.index.where : ''),
|
|
695
|
-
values: [],
|
|
696
|
-
},
|
|
697
|
-
]
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
if (operation.kind === 'dropIndex') {
|
|
701
|
-
return [
|
|
702
|
-
{
|
|
703
|
-
text:
|
|
704
|
-
'drop index ' +
|
|
705
|
-
(operation.ifExists ? 'if exists ' : '') +
|
|
706
|
-
quoteIdentifier(operation.name),
|
|
707
|
-
values: [],
|
|
708
|
-
},
|
|
709
|
-
]
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
if (operation.kind === 'renameIndex') {
|
|
713
|
-
return [
|
|
714
|
-
{
|
|
715
|
-
text:
|
|
716
|
-
'alter index ' +
|
|
717
|
-
quoteIdentifier(operation.from) +
|
|
718
|
-
' rename to ' +
|
|
719
|
-
quoteIdentifier(operation.to),
|
|
720
|
-
values: [],
|
|
721
|
-
},
|
|
722
|
-
]
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
if (operation.kind === 'addForeignKey') {
|
|
726
|
-
return [
|
|
727
|
-
{
|
|
728
|
-
text:
|
|
729
|
-
'alter table ' +
|
|
730
|
-
quoteTableRef(operation.table) +
|
|
731
|
-
' add ' +
|
|
732
|
-
'constraint ' +
|
|
733
|
-
quoteIdentifier(operation.constraint.name) +
|
|
734
|
-
' ' +
|
|
735
|
-
'foreign key (' +
|
|
736
|
-
operation.constraint.columns.map((column) => quoteIdentifier(column)).join(', ') +
|
|
737
|
-
') references ' +
|
|
738
|
-
quoteTableRef(operation.constraint.references.table) +
|
|
739
|
-
' (' +
|
|
740
|
-
operation.constraint.references.columns
|
|
741
|
-
.map((column) => quoteIdentifier(column))
|
|
742
|
-
.join(', ') +
|
|
743
|
-
')' +
|
|
744
|
-
(operation.constraint.onDelete ? ' on delete ' + operation.constraint.onDelete : '') +
|
|
745
|
-
(operation.constraint.onUpdate ? ' on update ' + operation.constraint.onUpdate : ''),
|
|
746
|
-
values: [],
|
|
747
|
-
},
|
|
748
|
-
]
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
if (operation.kind === 'dropForeignKey') {
|
|
752
|
-
return [
|
|
753
|
-
{
|
|
754
|
-
text:
|
|
755
|
-
'alter table ' +
|
|
756
|
-
quoteTableRef(operation.table) +
|
|
757
|
-
' drop constraint ' +
|
|
758
|
-
quoteIdentifier(operation.name),
|
|
759
|
-
values: [],
|
|
760
|
-
},
|
|
761
|
-
]
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
if (operation.kind === 'addCheck') {
|
|
765
|
-
return [
|
|
766
|
-
{
|
|
767
|
-
text:
|
|
768
|
-
'alter table ' +
|
|
769
|
-
quoteTableRef(operation.table) +
|
|
770
|
-
' add ' +
|
|
771
|
-
'constraint ' +
|
|
772
|
-
quoteIdentifier(operation.constraint.name) +
|
|
773
|
-
' ' +
|
|
774
|
-
'check (' +
|
|
775
|
-
operation.constraint.expression +
|
|
776
|
-
')',
|
|
777
|
-
values: [],
|
|
778
|
-
},
|
|
779
|
-
]
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
if (operation.kind === 'dropCheck') {
|
|
783
|
-
return [
|
|
784
|
-
{
|
|
785
|
-
text:
|
|
786
|
-
'alter table ' +
|
|
787
|
-
quoteTableRef(operation.table) +
|
|
788
|
-
' drop constraint ' +
|
|
789
|
-
quoteIdentifier(operation.name),
|
|
790
|
-
values: [],
|
|
791
|
-
},
|
|
792
|
-
]
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
throw new Error('Unsupported data migration operation kind')
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
function compilePostgresColumn(definition: ColumnDefinition): string {
|
|
799
|
-
let parts = [compilePostgresColumnType(definition)]
|
|
800
|
-
|
|
801
|
-
if (definition.nullable === false) {
|
|
802
|
-
parts.push('not null')
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
if (definition.default) {
|
|
806
|
-
if (definition.default.kind === 'now') {
|
|
807
|
-
parts.push('default now()')
|
|
808
|
-
} else if (definition.default.kind === 'sql') {
|
|
809
|
-
parts.push('default ' + definition.default.expression)
|
|
810
|
-
} else {
|
|
811
|
-
parts.push('default ' + quoteLiteral(definition.default.value))
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
if (definition.primaryKey) {
|
|
816
|
-
parts.push('primary key')
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
if (definition.unique) {
|
|
820
|
-
parts.push('unique')
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
if (definition.computed) {
|
|
824
|
-
if (!definition.computed.stored) {
|
|
825
|
-
throw new Error('Postgres only supports stored computed/generated columns')
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
parts.push('generated always as (' + definition.computed.expression + ') stored')
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
if (definition.references) {
|
|
832
|
-
let clause =
|
|
833
|
-
'references ' +
|
|
834
|
-
quoteTableRef(definition.references.table) +
|
|
835
|
-
' (' +
|
|
836
|
-
definition.references.columns.map((column) => quoteIdentifier(column)).join(', ') +
|
|
837
|
-
')'
|
|
838
|
-
|
|
839
|
-
if (definition.references.onDelete) {
|
|
840
|
-
clause += ' on delete ' + definition.references.onDelete
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
if (definition.references.onUpdate) {
|
|
844
|
-
clause += ' on update ' + definition.references.onUpdate
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
parts.push(clause)
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
if (definition.checks && definition.checks.length > 0) {
|
|
851
|
-
for (let check of definition.checks) {
|
|
852
|
-
parts.push('check (' + check.expression + ')')
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
return parts.join(' ')
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
function compilePostgresColumnType(definition: ColumnDefinition): string {
|
|
860
|
-
if (definition.type === 'varchar') {
|
|
861
|
-
return 'varchar(' + String(definition.length ?? 255) + ')'
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
if (definition.type === 'text') {
|
|
865
|
-
return 'text'
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
if (definition.type === 'integer') {
|
|
869
|
-
return 'integer'
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
if (definition.type === 'bigint') {
|
|
873
|
-
return 'bigint'
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
if (definition.type === 'decimal') {
|
|
877
|
-
if (definition.precision !== undefined && definition.scale !== undefined) {
|
|
878
|
-
return 'decimal(' + String(definition.precision) + ', ' + String(definition.scale) + ')'
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
return 'decimal'
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
if (definition.type === 'boolean') {
|
|
885
|
-
return 'boolean'
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
if (definition.type === 'uuid') {
|
|
889
|
-
return 'uuid'
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
if (definition.type === 'date') {
|
|
893
|
-
return 'date'
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
if (definition.type === 'time') {
|
|
897
|
-
return definition.withTimezone ? 'time with time zone' : 'time without time zone'
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
if (definition.type === 'timestamp') {
|
|
901
|
-
return definition.withTimezone ? 'timestamp with time zone' : 'timestamp without time zone'
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
if (definition.type === 'json') {
|
|
905
|
-
return 'jsonb'
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
if (definition.type === 'binary') {
|
|
909
|
-
return 'bytea'
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
if (definition.type === 'enum') {
|
|
913
|
-
return 'text'
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
return 'text'
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
function quoteTableRef(table: TableRef): string {
|
|
920
|
-
return quoteTableRefHelper(table, quoteIdentifier)
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
function quoteLiteral(value: unknown): string {
|
|
924
|
-
return quoteLiteralHelper(value)
|
|
925
|
-
}
|