@dbml/connector 3.13.1 → 3.13.2

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.
@@ -111,6 +111,13 @@
111
111
  "note": {
112
112
  "value": ""
113
113
  }
114
+ },
115
+ {
116
+ "name": "TestDescriptionTable",
117
+ "schemaName": "dbo",
118
+ "note": {
119
+ "value": "This is the custom comment name on table."
120
+ }
114
121
  }
115
122
  ],
116
123
  "fields": {
@@ -1611,6 +1618,34 @@
1611
1618
  "value": ""
1612
1619
  }
1613
1620
  }
1621
+ ],
1622
+ "dbo.TestDescriptionTable": [
1623
+ {
1624
+ "name": "Id",
1625
+ "type": {
1626
+ "type_name": "int(10)",
1627
+ "schemaName": null
1628
+ },
1629
+ "dbdefault": null,
1630
+ "not_null": false,
1631
+ "increment": false,
1632
+ "note": {
1633
+ "value": "Primary key identifier."
1634
+ }
1635
+ },
1636
+ {
1637
+ "name": "Name",
1638
+ "type": {
1639
+ "type_name": "nvarchar(100)",
1640
+ "schemaName": null
1641
+ },
1642
+ "dbdefault": null,
1643
+ "not_null": false,
1644
+ "increment": false,
1645
+ "note": {
1646
+ "value": "Name of the entity."
1647
+ }
1648
+ }
1614
1649
  ]
1615
1650
  },
1616
1651
  "enums": [
@@ -2002,4 +2037,4 @@
2002
2037
  }
2003
2038
  }
2004
2039
  }
2005
- }
2040
+ }
@@ -97,6 +97,27 @@
97
97
  "note": {
98
98
  "value": ""
99
99
  }
100
+ },
101
+ {
102
+ "name": "AddressInfo",
103
+ "schemaName": "dbo",
104
+ "note": {
105
+ "value": ""
106
+ }
107
+ },
108
+ {
109
+ "name": "AddressInfo2",
110
+ "schemaName": "dbo",
111
+ "note": {
112
+ "value": ""
113
+ }
114
+ },
115
+ {
116
+ "name": "TestDescriptionTable",
117
+ "schemaName": "dbo",
118
+ "note": {
119
+ "value": "This is the custom comment name on table."
120
+ }
100
121
  }
101
122
  ],
102
123
  "fields": {
@@ -454,7 +475,7 @@
454
475
  {
455
476
  "name": "status",
456
477
  "type": {
457
- "type_name": "chk_status",
478
+ "type_name": "chk_status_status",
458
479
  "schemaName": "dbo"
459
480
  },
460
481
  "dbdefault": {
@@ -1141,7 +1162,7 @@
1141
1162
  },
1142
1163
  "dbdefault": {
1143
1164
  "type": "string",
1144
- "value": "<Books>\r\n <Book>\r\n <Title>The Great Gatsby</Title>\r\n <Author>F. Scott Fitzgerald</Author>\r\n <Year>1925</Year>\r\n <Price>10.99</Price>\r\n <Publisher>Scribner</Publisher>\r\n <Location>New York</Location>\r\n <Genre>Fiction</Genre>\r\n <Subgenre>Classic</Subgenre>\r\n </Book>\r\n <Book>\r\n <Title>1984</Title>\r\n <Author>George Orwell</Author>\r\n <Year>1949</Year>\r\n <Price>8.99</Price>\r\n <Publisher>Secker & Warburg</Publisher>\r\n <Location>London</Location>\r\n <Genre>Dystopian</Genre>\r\n <Subgenre>Political Fiction</Subgenre>\r\n </Book>\r\n </Books>"
1165
+ "value": "<Books>\n <Book>\n <Title>The Great Gatsby</Title>\n <Author>F. Scott Fitzgerald</Author>\n <Year>1925</Year>\n <Price>10.99</Price>\n <Publisher>Scribner</Publisher>\n <Location>New York</Location>\n <Genre>Fiction</Genre>\n <Subgenre>Classic</Subgenre>\n </Book>\n <Book>\n <Title>1984</Title>\n <Author>George Orwell</Author>\n <Year>1949</Year>\n <Price>8.99</Price>\n <Publisher>Secker & Warburg</Publisher>\n <Location>London</Location>\n <Genre>Dystopian</Genre>\n <Subgenre>Political Fiction</Subgenre>\n </Book>\n </Books>"
1145
1166
  },
1146
1167
  "not_null": false,
1147
1168
  "increment": false,
@@ -1275,7 +1296,7 @@
1275
1296
  {
1276
1297
  "name": "gender",
1277
1298
  "type": {
1278
- "type_name": "chk_gender",
1299
+ "type_name": "chk_gender_gender",
1279
1300
  "schemaName": "dbo"
1280
1301
  },
1281
1302
  "dbdefault": null,
@@ -1515,11 +1536,121 @@
1515
1536
  "value": ""
1516
1537
  }
1517
1538
  }
1539
+ ],
1540
+ "dbo.AddressInfo": [
1541
+ {
1542
+ "name": "AddressID",
1543
+ "type": {
1544
+ "type_name": "CK_Address_Valid_AddressID_AddressFormatID",
1545
+ "schemaName": "dbo"
1546
+ },
1547
+ "dbdefault": null,
1548
+ "not_null": true,
1549
+ "increment": false,
1550
+ "note": {
1551
+ "value": ""
1552
+ }
1553
+ },
1554
+ {
1555
+ "name": "AddressFormatID",
1556
+ "type": {
1557
+ "type_name": "CK_Address_Valid_AddressID_AddressFormatID",
1558
+ "schemaName": "dbo"
1559
+ },
1560
+ "dbdefault": null,
1561
+ "not_null": true,
1562
+ "increment": false,
1563
+ "note": {
1564
+ "value": ""
1565
+ }
1566
+ }
1567
+ ],
1568
+ "dbo.AddressInfo2": [
1569
+ {
1570
+ "name": "A1",
1571
+ "type": {
1572
+ "type_name": "CK_Address_Valid2_A1",
1573
+ "schemaName": "dbo"
1574
+ },
1575
+ "dbdefault": null,
1576
+ "not_null": true,
1577
+ "increment": false,
1578
+ "note": {
1579
+ "value": ""
1580
+ }
1581
+ },
1582
+ {
1583
+ "name": "A2",
1584
+ "type": {
1585
+ "type_name": "CK_Address_Valid2_A2_A3",
1586
+ "schemaName": "dbo"
1587
+ },
1588
+ "dbdefault": null,
1589
+ "not_null": true,
1590
+ "increment": false,
1591
+ "note": {
1592
+ "value": ""
1593
+ }
1594
+ },
1595
+ {
1596
+ "name": "A3",
1597
+ "type": {
1598
+ "type_name": "CK_Address_Valid2_A2_A3",
1599
+ "schemaName": "dbo"
1600
+ },
1601
+ "dbdefault": null,
1602
+ "not_null": true,
1603
+ "increment": false,
1604
+ "note": {
1605
+ "value": ""
1606
+ }
1607
+ },
1608
+ {
1609
+ "name": "A4",
1610
+ "type": {
1611
+ "type_name": "CK_Address_Valid2_A4",
1612
+ "schemaName": "dbo"
1613
+ },
1614
+ "dbdefault": null,
1615
+ "not_null": true,
1616
+ "increment": false,
1617
+ "note": {
1618
+ "value": ""
1619
+ }
1620
+ }
1621
+ ],
1622
+ "dbo.TestDescriptionTable": [
1623
+ {
1624
+ "name": "Id",
1625
+ "type": {
1626
+ "type_name": "int(10)",
1627
+ "schemaName": null
1628
+ },
1629
+ "dbdefault": null,
1630
+ "not_null": false,
1631
+ "increment": false,
1632
+ "note": {
1633
+ "value": "Primary key identifier."
1634
+ }
1635
+ },
1636
+ {
1637
+ "name": "Name",
1638
+ "type": {
1639
+ "type_name": "nvarchar(100)",
1640
+ "schemaName": null
1641
+ },
1642
+ "dbdefault": null,
1643
+ "not_null": false,
1644
+ "increment": false,
1645
+ "note": {
1646
+ "value": "Name of the entity."
1647
+ }
1648
+ }
1518
1649
  ]
1519
1650
  },
1520
1651
  "enums": [
1521
1652
  {
1522
- "name": "chk_status",
1653
+ "name": "chk_status_status",
1523
1654
  "schemaName": "dbo",
1524
1655
  "values": [
1525
1656
  {
@@ -1540,7 +1671,7 @@
1540
1671
  ]
1541
1672
  },
1542
1673
  {
1543
- "name": "chk_gender",
1674
+ "name": "chk_gender_gender",
1544
1675
  "schemaName": "dbo",
1545
1676
  "values": [
1546
1677
  {
@@ -1553,6 +1684,57 @@
1553
1684
  "name": "Male"
1554
1685
  }
1555
1686
  ]
1687
+ },
1688
+ {
1689
+ "name": "CK_Address_Valid_AddressID_AddressFormatID",
1690
+ "schemaName": "dbo",
1691
+ "values": [
1692
+ {
1693
+ "name": "176029FA-D6D3-49E1-A48C-000000000002"
1694
+ },
1695
+ {
1696
+ "name": "176029FA-D6D3-49E1-A48C-000000000001"
1697
+ }
1698
+ ]
1699
+ },
1700
+ {
1701
+ "name": "CK_Address_Valid2_A1",
1702
+ "schemaName": "dbo",
1703
+ "values": [
1704
+ {
1705
+ "name": "333"
1706
+ },
1707
+ {
1708
+ "name": "2222"
1709
+ },
1710
+ {
1711
+ "name": "1111"
1712
+ }
1713
+ ]
1714
+ },
1715
+ {
1716
+ "name": "CK_Address_Valid2_A2_A3",
1717
+ "schemaName": "dbo",
1718
+ "values": [
1719
+ {
1720
+ "name": "2222"
1721
+ },
1722
+ {
1723
+ "name": "1111"
1724
+ }
1725
+ ]
1726
+ },
1727
+ {
1728
+ "name": "CK_Address_Valid2_A4",
1729
+ "schemaName": "dbo",
1730
+ "values": [
1731
+ {
1732
+ "name": "3333"
1733
+ },
1734
+ {
1735
+ "name": "2222"
1736
+ }
1737
+ ]
1556
1738
  }
1557
1739
  ],
1558
1740
  "refs": [
@@ -1,3 +1,3 @@
1
1
  import { DatabaseSchema } from './types';
2
2
  declare const fetchSchemaJson: (connection: string) => Promise<DatabaseSchema>;
3
- export { fetchSchemaJson };
3
+ export { fetchSchemaJson, };
@@ -131,15 +131,15 @@ const getEnumValues = (definition, constraint_name) => {
131
131
  Object.keys(colMap).forEach((key) => {
132
132
  if (processedKeys.has(key))
133
133
  return;
134
- let mergedColumns = [key];
135
- const values = colMap[key];
134
+ const mergedColumns = [key];
135
+ const colValues = colMap[key];
136
136
  Object.keys(colMap).forEach((innerKey) => {
137
- if (key !== innerKey && arraysEqual(values, colMap[innerKey])) {
137
+ if (key !== innerKey && arraysEqual(colValues, colMap[innerKey])) {
138
138
  mergedColumns.push(innerKey);
139
139
  processedKeys.add(innerKey);
140
140
  }
141
141
  });
142
- const enumValues = values.map((value) => ({ name: value }));
142
+ const enumValues = colValues.map((value) => ({ name: value }));
143
143
  result.push({ columns: mergedColumns, enumValues, constraint_name: `${constraint_name}_${mergedColumns.join('_')}` });
144
144
  processedKeys.add(key);
145
145
  });
@@ -196,11 +196,11 @@ const generateTablesFieldsAndEnums = async (client, schemas) => {
196
196
  JOIN sys.columns c ON t.object_id = c.object_id
197
197
  JOIN sys.types ty ON c.user_type_id = ty.user_type_id
198
198
  LEFT JOIN sys.extended_properties p ON p.major_id = t.object_id
199
- AND p.name = 'MS_Description'
199
+ AND p.name like '%description%'
200
200
  AND p.minor_id = 0 -- Ensure minor_id is 0 for table comments
201
201
  LEFT JOIN sys.extended_properties ep ON ep.major_id = c.object_id
202
202
  AND ep.minor_id = c.column_id
203
- AND ep.name = 'MS_Description'
203
+ AND ep.name like '%description%'
204
204
  WHERE
205
205
  t.type = 'U' -- User-defined tables
206
206
  ),
@@ -347,10 +347,10 @@ const generateRefs = async (client, schemas) => {
347
347
  const endpointsEqual = (ep1, ep2) => {
348
348
  if (ep1.length !== ep2.length)
349
349
  return false;
350
- return ep1.every((endpoint, index) => endpoint.tableName === ep2[index].tableName &&
351
- endpoint.schemaName === ep2[index].schemaName &&
352
- endpoint.fieldNames.length === ep2[index].fieldNames.length &&
353
- endpoint.fieldNames.every((field, fieldIndex) => field === ep2[index].fieldNames[fieldIndex]));
350
+ return ep1.every((endpoint, index) => endpoint.tableName === ep2[index].tableName
351
+ && endpoint.schemaName === ep2[index].schemaName
352
+ && endpoint.fieldNames.length === ep2[index].fieldNames.length
353
+ && endpoint.fieldNames.every((field, fieldIndex) => field === ep2[index].fieldNames[fieldIndex]));
354
354
  };
355
355
  refsQueryResult.recordset.forEach((refRow) => {
356
356
  const { table_schema, fk_constraint_name, table_name, column_names, foreign_table_schema, foreign_table_name, foreign_column_names, on_delete, on_update, } = refRow;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbml/connector",
3
- "version": "3.13.1",
3
+ "version": "3.13.2",
4
4
  "description": "This package was created to fetch the schema JSON from many kind of databases.",
5
5
  "author": "huy.phung.sw@gmail.com",
6
6
  "license": "MIT",
@@ -44,5 +44,5 @@
44
44
  "engines": {
45
45
  "node": ">=18"
46
46
  },
47
- "gitHead": "8baea3c6a612f433f188efd6df5d24d1d5e16f2c"
47
+ "gitHead": "f9be31a9b9b3b509183637dc2527f1be8c260add"
48
48
  }
@@ -6,7 +6,6 @@ import {
6
6
  DefaultInfo,
7
7
  DefaultType,
8
8
  Enum,
9
- EnumValue,
10
9
  Field,
11
10
  FieldsDictionary,
12
11
  IndexesDictionary,
@@ -155,16 +154,16 @@ const getEnumValues = (definition: string, constraint_name: string): EnumValuesD
155
154
  Object.keys(colMap).forEach((key) => {
156
155
  if (processedKeys.has(key)) return;
157
156
 
158
- let mergedColumns = [key];
159
- const values = colMap[key];
157
+ const mergedColumns = [key];
158
+ const colValues = colMap[key];
160
159
 
161
160
  Object.keys(colMap).forEach((innerKey) => {
162
- if (key !== innerKey && arraysEqual(values, colMap[innerKey])) {
161
+ if (key !== innerKey && arraysEqual(colValues, colMap[innerKey])) {
163
162
  mergedColumns.push(innerKey);
164
163
  processedKeys.add(innerKey);
165
164
  }
166
165
  });
167
- const enumValues = values.map((value) => ({ name: value }));
166
+ const enumValues = colValues.map((value) => ({ name: value }));
168
167
  result.push({ columns: mergedColumns, enumValues, constraint_name: `${constraint_name}_${mergedColumns.join('_')}` });
169
168
  processedKeys.add(key);
170
169
  });
@@ -243,11 +242,11 @@ const generateTablesFieldsAndEnums = async (client: sql.ConnectionPool, schemas:
243
242
  JOIN sys.columns c ON t.object_id = c.object_id
244
243
  JOIN sys.types ty ON c.user_type_id = ty.user_type_id
245
244
  LEFT JOIN sys.extended_properties p ON p.major_id = t.object_id
246
- AND p.name = 'MS_Description'
245
+ AND p.name like '%description%'
247
246
  AND p.minor_id = 0 -- Ensure minor_id is 0 for table comments
248
247
  LEFT JOIN sys.extended_properties ep ON ep.major_id = c.object_id
249
248
  AND ep.minor_id = c.column_id
250
- AND ep.name = 'MS_Description'
249
+ AND ep.name like '%description%'
251
250
  WHERE
252
251
  t.type = 'U' -- User-defined tables
253
252
  ),
@@ -410,11 +409,11 @@ const generateRefs = async (client: sql.ConnectionPool, schemas: string[]): Prom
410
409
 
411
410
  const endpointsEqual = (ep1: RefEndpoint[], ep2: RefEndpoint[]): boolean => {
412
411
  if (ep1.length !== ep2.length) return false;
413
- return ep1.every((endpoint, index) =>
414
- endpoint.tableName === ep2[index].tableName &&
415
- endpoint.schemaName === ep2[index].schemaName &&
416
- endpoint.fieldNames.length === ep2[index].fieldNames.length &&
417
- endpoint.fieldNames.every((field, fieldIndex) => field === ep2[index].fieldNames[fieldIndex])
412
+ return ep1.every(
413
+ (endpoint, index) => endpoint.tableName === ep2[index].tableName
414
+ && endpoint.schemaName === ep2[index].schemaName
415
+ && endpoint.fieldNames.length === ep2[index].fieldNames.length
416
+ && endpoint.fieldNames.every((field, fieldIndex) => field === ep2[index].fieldNames[fieldIndex]),
418
417
  );
419
418
  };
420
419
 
@@ -651,5 +650,5 @@ const fetchSchemaJson = async (connection: string): Promise<DatabaseSchema> => {
651
650
  };
652
651
 
653
652
  export {
654
- fetchSchemaJson
653
+ fetchSchemaJson,
655
654
  };