Skip to content

Commit cdd1cd9

Browse files
williamluke4igalklebanov
authored andcommitted
feat(Introspect): add support for postgres & mysql foreign tables (#1494)
1 parent c9e7bf9 commit cdd1cd9

File tree

6 files changed

+29
-0
lines changed

6 files changed

+29
-0
lines changed

src/dialect/database-introspector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface DatabaseMetadata {
4343
export interface TableMetadata {
4444
readonly name: string
4545
readonly isView: boolean
46+
readonly isForeign: boolean
4647
readonly columns: ColumnMetadata[]
4748
readonly schema?: string
4849
}

src/dialect/mssql/mssql-introspector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export class MssqlIntrospector implements DatabaseIntrospector {
142142
tableDictionary[key] ||
143143
freeze({
144144
columns: [],
145+
isForeign: false,
145146
isView: rawColumn.table_type === 'V ',
146147
name: rawColumn.table_name,
147148
schema: rawColumn.table_schema_name ?? undefined,

src/dialect/mysql/mysql-introspector.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class MysqlIntrospector implements DatabaseIntrospector {
4747
'columns.TABLE_NAME',
4848
'columns.TABLE_SCHEMA',
4949
'tables.TABLE_TYPE',
50+
'tables.ENGINE',
5051
'columns.IS_NULLABLE',
5152
'columns.DATA_TYPE',
5253
'columns.EXTRA',
@@ -83,6 +84,7 @@ export class MysqlIntrospector implements DatabaseIntrospector {
8384
table = freeze({
8485
name: it.TABLE_NAME,
8586
isView: it.TABLE_TYPE === 'VIEW',
87+
isForeign: it.ENGINE === 'FEDERATED',
8688
schema: it.TABLE_SCHEMA,
8789
columns: [],
8890
})
@@ -116,6 +118,7 @@ interface RawColumnMetadata {
116118
TABLE_NAME: string
117119
TABLE_SCHEMA: string
118120
TABLE_TYPE: string
121+
ENGINE: string
119122
IS_NULLABLE: 'YES' | 'NO'
120123
DATA_TYPE: string
121124
EXTRA: string

src/dialect/postgres/postgres-introspector.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class PostgresIntrospector implements DatabaseIntrospector {
7070
'r' /*regular table*/,
7171
'v' /*view*/,
7272
'p' /*partitioned table*/,
73+
'f' /*foreign table*/,
7374
])
7475
.where('ns.nspname', '!~', '^pg_')
7576
.where('ns.nspname', '!=', 'information_schema')
@@ -112,6 +113,7 @@ export class PostgresIntrospector implements DatabaseIntrospector {
112113
table = freeze({
113114
name: it.table,
114115
isView: it.table_type === 'v',
116+
isForeign: it.table_type === 'f',
115117
schema: it.schema,
116118
columns: [],
117119
})

src/dialect/sqlite/sqlite-introspector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export class SqliteIntrospector implements DatabaseIntrospector {
135135
return {
136136
name: name,
137137
isView: type === 'view',
138+
isForeign: false,
138139
columns: columns.map((col) => ({
139140
name: col.name,
140141
dataType: col.type,

test/node/src/introspect.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ for (const dialect of DIALECTS) {
8585
expect(meta).to.eql([
8686
{
8787
name: 'person',
88+
isForeign: false,
8889
isView: false,
8990
schema: 'public',
9091
columns: [
@@ -157,6 +158,7 @@ for (const dialect of DIALECTS) {
157158
{
158159
name: 'pet',
159160
isView: false,
161+
isForeign: false,
160162
schema: 'public',
161163
columns: [
162164
{
@@ -200,6 +202,7 @@ for (const dialect of DIALECTS) {
200202
{
201203
name: 'toy',
202204
isView: false,
205+
isForeign: false,
203206
schema: 'public',
204207
columns: [
205208
{
@@ -242,6 +245,7 @@ for (const dialect of DIALECTS) {
242245
},
243246
{
244247
name: 'toy_names',
248+
isForeign: false,
245249
isView: true,
246250
schema: 'public',
247251
columns: [
@@ -258,6 +262,7 @@ for (const dialect of DIALECTS) {
258262
},
259263
{
260264
name: 'MixedCaseTable',
265+
isForeign: false,
261266
isView: false,
262267
schema: 'some_schema',
263268
columns: [
@@ -274,6 +279,7 @@ for (const dialect of DIALECTS) {
274279
},
275280
{
276281
name: 'pet',
282+
isForeign: false,
277283
isView: false,
278284
schema: 'some_schema',
279285
columns: [
@@ -299,6 +305,7 @@ for (const dialect of DIALECTS) {
299305
},
300306
{
301307
name: 'pet_partition',
308+
isForeign: false,
302309
isView: false,
303310
schema: 'some_schema',
304311
columns: [
@@ -318,6 +325,7 @@ for (const dialect of DIALECTS) {
318325
expect(meta).to.eql([
319326
{
320327
name: 'person',
328+
isForeign: false,
321329
isView: false,
322330
schema: 'kysely_test',
323331
columns: [
@@ -382,6 +390,7 @@ for (const dialect of DIALECTS) {
382390
},
383391
{
384392
name: 'pet',
393+
isForeign: false,
385394
isView: false,
386395
schema: 'kysely_test',
387396
columns: [
@@ -421,6 +430,7 @@ for (const dialect of DIALECTS) {
421430
},
422431
{
423432
name: 'toy',
433+
isForeign: false,
424434
isView: false,
425435
schema: 'kysely_test',
426436
columns: [
@@ -460,6 +470,7 @@ for (const dialect of DIALECTS) {
460470
},
461471
{
462472
name: 'toy_names',
473+
isForeign: false,
463474
isView: true,
464475
schema: 'kysely_test',
465476
columns: [
@@ -477,6 +488,7 @@ for (const dialect of DIALECTS) {
477488
} else if (dialect === 'mssql') {
478489
expect(meta).to.eql([
479490
{
491+
isForeign: false,
480492
isView: false,
481493
name: 'person',
482494
schema: 'dbo',
@@ -547,6 +559,7 @@ for (const dialect of DIALECTS) {
547559
],
548560
},
549561
{
562+
isForeign: false,
550563
isView: false,
551564
name: 'pet',
552565
schema: 'dbo',
@@ -590,6 +603,7 @@ for (const dialect of DIALECTS) {
590603
],
591604
},
592605
{
606+
isForeign: false,
593607
isView: false,
594608
name: 'toy',
595609
schema: 'dbo',
@@ -633,6 +647,7 @@ for (const dialect of DIALECTS) {
633647
],
634648
},
635649
{
650+
isForeign: false,
636651
isView: true,
637652
name: 'toy_names',
638653
schema: 'dbo',
@@ -649,6 +664,7 @@ for (const dialect of DIALECTS) {
649664
],
650665
},
651666
{
667+
isForeign: false,
652668
isView: false,
653669
name: 'pet',
654670
schema: 'some_schema',
@@ -678,6 +694,7 @@ for (const dialect of DIALECTS) {
678694
expect(meta).to.eql([
679695
{
680696
name: 'person',
697+
isForeign: false,
681698
isView: false,
682699
columns: [
683700
{
@@ -741,6 +758,7 @@ for (const dialect of DIALECTS) {
741758
},
742759
{
743760
name: 'pet',
761+
isForeign: false,
744762
isView: false,
745763
columns: [
746764
{
@@ -779,6 +797,7 @@ for (const dialect of DIALECTS) {
779797
},
780798
{
781799
name: 'toy',
800+
isForeign: false,
782801
isView: false,
783802
columns: [
784803
{
@@ -817,6 +836,7 @@ for (const dialect of DIALECTS) {
817836
},
818837
{
819838
name: 'toy_names',
839+
isForeign: false,
820840
isView: true,
821841
columns: [
822842
{
@@ -856,6 +876,7 @@ for (const dialect of DIALECTS) {
856876

857877
expect(testTable).to.eql({
858878
name: testTableName,
879+
isForeign: false,
859880
isView: false,
860881
columns: [
861882
{

0 commit comments

Comments
 (0)