@dbml/connector 5.3.1 → 5.4.1
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/__tests__/connector.test.ts +2 -2
- package/__tests__/connectors/mssql/out-files/schema.json +350 -43
- package/__tests__/connectors/mysql/out-files/schema.json +1520 -0
- package/__tests__/connectors/oracle/out-files/schema.json +3866 -0
- package/__tests__/connectors/postgres/out-files/schema.json +1830 -0
- package/{jestHelpers.ts → __tests__/testHelpers.ts} +2 -6
- package/dist/connectors/mssql/index.js +26 -21
- package/dist/connectors/mysql/index.js +34 -30
- package/dist/connectors/postgres/index.js +28 -24
- package/eslint.config.ts +1 -1
- package/jest.config.ts +9 -1
- package/package.json +4 -3
- package/src/connectors/mssql/index.ts +28 -24
- package/src/connectors/mysql/index.ts +41 -38
- package/src/connectors/postgres/index.ts +29 -26
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export function scanDirNames (dirname: string, subpath: string): string[] {
|
|
5
5
|
const dirPath = path.join(dirname, subpath);
|
|
6
6
|
const sanitizedDirPath = path.normalize(dirPath);
|
|
7
7
|
const dirs = fs.readdirSync(sanitizedDirPath);
|
|
8
8
|
return dirs;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
scanDirNames,
|
|
13
|
-
};
|
|
9
|
+
}
|
|
@@ -456,26 +456,31 @@ const generateIndexesAndConstraints = async (client, schemas) => {
|
|
|
456
456
|
const fetchSchemaJson = async (connection) => {
|
|
457
457
|
const { connectionString, schemas } = (0, parseSchema_1.parseConnectionString)(connection, 'odbc');
|
|
458
458
|
const client = await getValidatedClient(connectionString);
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
459
|
+
try {
|
|
460
|
+
const tablesRes = generateTablesFields(client, schemas);
|
|
461
|
+
const indexesAndConstraintsRes = generateIndexesAndConstraints(client, schemas);
|
|
462
|
+
const refsRes = generateRefs(client, schemas);
|
|
463
|
+
const res = await Promise.all([
|
|
464
|
+
tablesRes,
|
|
465
|
+
indexesAndConstraintsRes,
|
|
466
|
+
refsRes,
|
|
467
|
+
]);
|
|
468
|
+
const { tables, fields } = res[0];
|
|
469
|
+
const { indexes, tableConstraints, checks } = res[1];
|
|
470
|
+
const refs = res[2];
|
|
471
|
+
return {
|
|
472
|
+
tables,
|
|
473
|
+
fields,
|
|
474
|
+
// MSSQL doesn't support the notion of enums
|
|
475
|
+
enums: [],
|
|
476
|
+
refs,
|
|
477
|
+
indexes,
|
|
478
|
+
tableConstraints,
|
|
479
|
+
checks,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
finally {
|
|
483
|
+
await client.close();
|
|
484
|
+
}
|
|
480
485
|
};
|
|
481
486
|
exports.fetchSchemaJson = fetchSchemaJson;
|
|
@@ -416,35 +416,39 @@ async function fetchSchemaJson(connection) {
|
|
|
416
416
|
if (!schemaName) {
|
|
417
417
|
throw new Error('Cannot get schema name from the connection');
|
|
418
418
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
419
|
+
try {
|
|
420
|
+
const result = await Promise.all([
|
|
421
|
+
generateTablesAndFields(client, schemaName),
|
|
422
|
+
generateEnums(client, schemaName),
|
|
423
|
+
generateIndexes(client, schemaName),
|
|
424
|
+
generatePrimaryAndUniqueConstraint(client, schemaName),
|
|
425
|
+
generateForeignKeys(client, schemaName),
|
|
426
|
+
generateCheckConstraints(client, schemaName),
|
|
427
|
+
]);
|
|
428
|
+
const [{ tableList, fieldMap }, enumList, rawIndexMap, { primaryAndUniqueConstraintMap, compositeConstraintMap }, foreignKeyList, { checks: tableCheckConstraintMap, tableConstraints: columnCheckConstraintMap },] = result;
|
|
429
|
+
// combine normal index and composite key
|
|
430
|
+
const indexMap = combineIndexAndCompositeConstraint(rawIndexMap, compositeConstraintMap);
|
|
431
|
+
const tableConstraints = { ...primaryAndUniqueConstraintMap };
|
|
432
|
+
Object.keys(columnCheckConstraintMap).forEach((tableName) => {
|
|
433
|
+
if (!tableConstraints[tableName])
|
|
434
|
+
tableConstraints[tableName] = {};
|
|
435
|
+
Object.keys(columnCheckConstraintMap[tableName]).forEach((colName) => {
|
|
436
|
+
if (!tableConstraints[tableName][colName])
|
|
437
|
+
tableConstraints[tableName][colName] = { checks: [] };
|
|
438
|
+
tableConstraints[tableName][colName].checks.push(...columnCheckConstraintMap[tableName][colName].checks);
|
|
439
|
+
});
|
|
439
440
|
});
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
}
|
|
441
|
+
return {
|
|
442
|
+
tables: tableList,
|
|
443
|
+
fields: fieldMap,
|
|
444
|
+
refs: foreignKeyList,
|
|
445
|
+
enums: enumList,
|
|
446
|
+
indexes: indexMap,
|
|
447
|
+
tableConstraints,
|
|
448
|
+
checks: tableCheckConstraintMap,
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
finally {
|
|
452
|
+
await client.end();
|
|
453
|
+
}
|
|
450
454
|
}
|
|
@@ -485,29 +485,33 @@ const generateRawEnums = async (client, schemas) => {
|
|
|
485
485
|
const fetchSchemaJson = async (connection) => {
|
|
486
486
|
const { connectionString, schemas } = (0, parseSchema_1.parseConnectionString)(connection, 'jdbc');
|
|
487
487
|
const client = await getValidatedClient(connectionString);
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
488
|
+
try {
|
|
489
|
+
const tablesAndFieldsRes = generateTablesAndFields(client, schemas);
|
|
490
|
+
const indexesRes = generateIndexesAndConstraints(client, schemas);
|
|
491
|
+
const refsRes = generateRawRefs(client, schemas);
|
|
492
|
+
const enumsRes = generateRawEnums(client, schemas);
|
|
493
|
+
const res = await Promise.all([
|
|
494
|
+
tablesAndFieldsRes,
|
|
495
|
+
indexesRes,
|
|
496
|
+
refsRes,
|
|
497
|
+
enumsRes,
|
|
498
|
+
]);
|
|
499
|
+
const { tables, fields } = res[0];
|
|
500
|
+
const { indexes, tableConstraints, checks } = res[1];
|
|
501
|
+
const refs = res[2];
|
|
502
|
+
const enums = res[3];
|
|
503
|
+
return {
|
|
504
|
+
tables,
|
|
505
|
+
fields,
|
|
506
|
+
refs,
|
|
507
|
+
enums,
|
|
508
|
+
indexes,
|
|
509
|
+
tableConstraints,
|
|
510
|
+
checks,
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
finally {
|
|
514
|
+
await client.end();
|
|
515
|
+
}
|
|
512
516
|
};
|
|
513
517
|
exports.fetchSchemaJson = fetchSchemaJson;
|
package/eslint.config.ts
CHANGED
package/jest.config.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { type Config } from 'jest';
|
|
2
|
+
|
|
3
|
+
const config: Config = {
|
|
4
|
+
testMatch: ["**/?(*.)+(spec|test).?([mc])[jt]s?(x)"],
|
|
2
5
|
preset: 'ts-jest',
|
|
3
6
|
testEnvironment: 'node',
|
|
4
7
|
transform: {
|
|
@@ -7,4 +10,9 @@ module.exports = {
|
|
|
7
10
|
moduleNameMapper: {
|
|
8
11
|
'\\.(css|less|scss)$': 'identity-obj-proxy',
|
|
9
12
|
},
|
|
13
|
+
collectCoverage: true,
|
|
14
|
+
coverageReporters: ['json', 'json-summary', 'html', 'text'],
|
|
15
|
+
coverageDirectory: 'coverage',
|
|
10
16
|
};
|
|
17
|
+
|
|
18
|
+
export default config;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@dbml/connector",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.4.1",
|
|
5
5
|
"description": "This package was created to fetch the schema JSON from many kind of databases.",
|
|
6
6
|
"author": "huy.phung.sw@gmail.com",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsc",
|
|
38
38
|
"start": "node dist/index.js",
|
|
39
|
-
"test": "jest",
|
|
39
|
+
"test": "jest --coverage=false",
|
|
40
|
+
"coverage": "jest --coverage",
|
|
40
41
|
"lint": "eslint .",
|
|
41
42
|
"lint:fix": "eslint --fix ."
|
|
42
43
|
},
|
|
@@ -55,5 +56,5 @@
|
|
|
55
56
|
"engines": {
|
|
56
57
|
"node": ">=18"
|
|
57
58
|
},
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "f5c8bf0c9d95948e3874cfb6cc777f65c4180891"
|
|
59
60
|
}
|
|
@@ -553,30 +553,34 @@ const fetchSchemaJson = async (connection: string): Promise<DatabaseSchema> => {
|
|
|
553
553
|
const { connectionString, schemas } = parseConnectionString(connection, 'odbc');
|
|
554
554
|
const client = await getValidatedClient(connectionString);
|
|
555
555
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
556
|
+
try {
|
|
557
|
+
const tablesRes = generateTablesFields(client, schemas);
|
|
558
|
+
const indexesAndConstraintsRes = generateIndexesAndConstraints(client, schemas);
|
|
559
|
+
const refsRes = generateRefs(client, schemas);
|
|
560
|
+
|
|
561
|
+
const res = await Promise.all([
|
|
562
|
+
tablesRes,
|
|
563
|
+
indexesAndConstraintsRes,
|
|
564
|
+
refsRes,
|
|
565
|
+
]);
|
|
566
|
+
|
|
567
|
+
const { tables, fields } = res[0];
|
|
568
|
+
const { indexes, tableConstraints, checks } = res[1];
|
|
569
|
+
const refs = res[2];
|
|
570
|
+
|
|
571
|
+
return {
|
|
572
|
+
tables,
|
|
573
|
+
fields,
|
|
574
|
+
// MSSQL doesn't support the notion of enums
|
|
575
|
+
enums: [],
|
|
576
|
+
refs,
|
|
577
|
+
indexes,
|
|
578
|
+
tableConstraints,
|
|
579
|
+
checks,
|
|
580
|
+
};
|
|
581
|
+
} finally {
|
|
582
|
+
await client.close();
|
|
583
|
+
}
|
|
580
584
|
};
|
|
581
585
|
|
|
582
586
|
export {
|
|
@@ -531,46 +531,49 @@ async function fetchSchemaJson (connection: string): Promise<DatabaseSchema> {
|
|
|
531
531
|
throw new Error('Cannot get schema name from the connection');
|
|
532
532
|
}
|
|
533
533
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
534
|
+
try {
|
|
535
|
+
const result = await Promise.all([
|
|
536
|
+
generateTablesAndFields(client, schemaName),
|
|
537
|
+
generateEnums(client, schemaName),
|
|
538
|
+
generateIndexes(client, schemaName),
|
|
539
|
+
generatePrimaryAndUniqueConstraint(client, schemaName),
|
|
540
|
+
generateForeignKeys(client, schemaName),
|
|
541
|
+
generateCheckConstraints(client, schemaName),
|
|
542
|
+
]);
|
|
543
|
+
|
|
544
|
+
const [
|
|
545
|
+
{ tableList, fieldMap },
|
|
546
|
+
enumList,
|
|
547
|
+
rawIndexMap,
|
|
548
|
+
{ primaryAndUniqueConstraintMap, compositeConstraintMap },
|
|
549
|
+
foreignKeyList,
|
|
550
|
+
{ checks: tableCheckConstraintMap, tableConstraints: columnCheckConstraintMap },
|
|
551
|
+
] = result;
|
|
552
|
+
|
|
553
|
+
// combine normal index and composite key
|
|
554
|
+
const indexMap = combineIndexAndCompositeConstraint(rawIndexMap, compositeConstraintMap);
|
|
555
|
+
|
|
556
|
+
const tableConstraints: TableConstraintsDictionary = { ...primaryAndUniqueConstraintMap };
|
|
557
|
+
Object.keys(columnCheckConstraintMap).forEach((tableName) => {
|
|
558
|
+
if (!tableConstraints[tableName]) tableConstraints[tableName] = {};
|
|
559
|
+
Object.keys(columnCheckConstraintMap[tableName]).forEach((colName) => {
|
|
560
|
+
if (!tableConstraints[tableName][colName]) tableConstraints[tableName][colName] = { checks: [] };
|
|
561
|
+
tableConstraints[tableName][colName].checks.push(...columnCheckConstraintMap[tableName][colName].checks);
|
|
562
|
+
});
|
|
562
563
|
});
|
|
563
|
-
});
|
|
564
564
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
565
|
+
return {
|
|
566
|
+
tables: tableList,
|
|
567
|
+
fields: fieldMap,
|
|
568
|
+
refs: foreignKeyList,
|
|
569
|
+
enums: enumList,
|
|
570
|
+
indexes: indexMap,
|
|
571
|
+
tableConstraints,
|
|
572
|
+
checks: tableCheckConstraintMap,
|
|
573
|
+
};
|
|
574
|
+
} finally {
|
|
575
|
+
await client.end();
|
|
576
|
+
}
|
|
574
577
|
}
|
|
575
578
|
|
|
576
579
|
export {
|
|
@@ -576,33 +576,36 @@ const fetchSchemaJson = async (connection: string): Promise<DatabaseSchema> => {
|
|
|
576
576
|
const { connectionString, schemas } = parseConnectionString(connection, 'jdbc');
|
|
577
577
|
const client = await getValidatedClient(connectionString);
|
|
578
578
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
579
|
+
try {
|
|
580
|
+
const tablesAndFieldsRes = generateTablesAndFields(client, schemas);
|
|
581
|
+
const indexesRes = generateIndexesAndConstraints(client, schemas);
|
|
582
|
+
const refsRes = generateRawRefs(client, schemas);
|
|
583
|
+
const enumsRes = generateRawEnums(client, schemas);
|
|
584
|
+
|
|
585
|
+
const res = await Promise.all([
|
|
586
|
+
tablesAndFieldsRes,
|
|
587
|
+
indexesRes,
|
|
588
|
+
refsRes,
|
|
589
|
+
enumsRes,
|
|
590
|
+
]);
|
|
591
|
+
|
|
592
|
+
const { tables, fields } = res[0];
|
|
593
|
+
const { indexes, tableConstraints, checks } = res[1];
|
|
594
|
+
const refs = res[2];
|
|
595
|
+
const enums = res[3];
|
|
596
596
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
597
|
+
return {
|
|
598
|
+
tables,
|
|
599
|
+
fields,
|
|
600
|
+
refs,
|
|
601
|
+
enums,
|
|
602
|
+
indexes,
|
|
603
|
+
tableConstraints,
|
|
604
|
+
checks,
|
|
605
|
+
};
|
|
606
|
+
} finally {
|
|
607
|
+
await client.end();
|
|
608
|
+
}
|
|
606
609
|
};
|
|
607
610
|
|
|
608
611
|
export {
|