@dbml/connector 3.9.2 → 3.9.3

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.
Files changed (53) hide show
  1. package/.babelrc +0 -0
  2. package/LICENSE +0 -0
  3. package/README.md +0 -0
  4. package/__tests__/connector.test.ts +0 -0
  5. package/__tests__/connectors/bigquery/out-files/schema.json +565 -0
  6. package/__tests__/connectors/mssql/connection.json +0 -0
  7. package/__tests__/connectors/mssql/expect-out-files/schema.json +424 -424
  8. package/__tests__/connectors/mssql/out-files/schema.json +1858 -0
  9. package/__tests__/connectors/mysql/connection.json +0 -0
  10. package/__tests__/connectors/mysql/expect-out-files/schema.json +0 -0
  11. package/__tests__/connectors/mysql/out-files/schema.json +1390 -0
  12. package/__tests__/connectors/postgres/connection.json +0 -0
  13. package/__tests__/connectors/postgres/expect-out-files/schema.json +356 -356
  14. package/__tests__/connectors/postgres/out-files/schema.json +1619 -0
  15. package/dist/connectors/bigqueryConnector.d.ts +0 -0
  16. package/dist/connectors/bigqueryConnector.js +2 -7
  17. package/dist/connectors/connector.d.ts +0 -0
  18. package/dist/connectors/connector.js +0 -0
  19. package/dist/connectors/mssqlConnector.d.ts +0 -0
  20. package/dist/connectors/mssqlConnector.js +4 -2
  21. package/dist/connectors/mysqlConnector.d.ts +0 -0
  22. package/dist/connectors/mysqlConnector.js +0 -0
  23. package/dist/connectors/postgresConnector.d.ts +0 -0
  24. package/dist/connectors/postgresConnector.js +37 -19
  25. package/dist/connectors/snowflakeConnector.d.ts +0 -0
  26. package/dist/connectors/snowflakeConnector.js +1 -1
  27. package/dist/connectors/types.d.ts +0 -0
  28. package/dist/connectors/types.js +0 -0
  29. package/dist/index.d.ts +0 -0
  30. package/dist/index.js +0 -0
  31. package/dist/utils/credential-loader.d.ts +0 -0
  32. package/dist/utils/credential-loader.js +0 -0
  33. package/dist/utils/helpers.d.ts +0 -0
  34. package/dist/utils/helpers.js +0 -0
  35. package/dist/utils/parseSchema.d.ts +0 -0
  36. package/dist/utils/parseSchema.js +0 -0
  37. package/jest.config.ts +0 -0
  38. package/jestHelpers.ts +0 -0
  39. package/package.json +2 -2
  40. package/src/connectors/bigqueryConnector.ts +2 -7
  41. package/src/connectors/connector.ts +0 -0
  42. package/src/connectors/mssqlConnector.ts +4 -2
  43. package/src/connectors/mysqlConnector.ts +0 -0
  44. package/src/connectors/postgresConnector.ts +37 -19
  45. package/src/connectors/snowflakeConnector.ts +1 -1
  46. package/src/connectors/types.ts +0 -0
  47. package/src/ddl_samples/bigquery.sql +0 -0
  48. package/src/ddl_samples/snowflake.sql +0 -0
  49. package/src/index.ts +0 -0
  50. package/src/utils/credential-loader.ts +0 -0
  51. package/src/utils/helpers.ts +0 -0
  52. package/src/utils/parseSchema.ts +0 -0
  53. package/tsconfig.json +0 -0
File without changes
@@ -93,14 +93,9 @@ async function generateTablesAndFields(client, projectId, datasetId) {
93
93
  t.table_schema = c.table_schema
94
94
  and t.table_name = c.table_name
95
95
  where t.table_type = 'BASE TABLE'
96
- order by t.table_name, c.ordinal_position;
96
+ order by t.create_time, c.ordinal_position;
97
97
  `;
98
- const [queryResult] = await client.query({
99
- query,
100
- params: {
101
- // stringRegex: STRING_REGEX,
102
- },
103
- });
98
+ const [queryResult] = await client.query({ query });
104
99
  const tableMap = {};
105
100
  const fieldMap = {};
106
101
  queryResult.forEach((row) => {
File without changes
File without changes
File without changes
@@ -136,7 +136,9 @@ const generateTablesFieldsAndEnums = async (client, schemas) => {
136
136
  SELECT
137
137
  s.name AS table_schema,
138
138
  t.name AS table_name,
139
+ t.create_date as table_create_date,
139
140
  c.name AS column_name,
141
+ c.column_id as column_id,
140
142
  ty.name AS data_type,
141
143
  c.max_length AS character_maximum_length,
142
144
  c.precision AS numeric_precision,
@@ -223,8 +225,8 @@ const generateTablesFieldsAndEnums = async (client, schemas) => {
223
225
  ${(0, parseSchema_1.buildSchemaQuery)('table_schema', schemas)}
224
226
  ORDER BY
225
227
  table_schema,
226
- table_name,
227
- column_name;
228
+ table_create_date,
229
+ column_id;
228
230
  `;
229
231
  const tablesAndFieldsResult = await client.query(tablesAndFieldsSql);
230
232
  const tables = tablesAndFieldsResult.recordset.reduce((acc, row) => {
File without changes
File without changes
File without changes
@@ -82,24 +82,40 @@ const generateField = (row) => {
82
82
  const generateTablesAndFields = async (client, schemas) => {
83
83
  const fields = {};
84
84
  const tablesAndFieldsSql = `
85
- WITH comments AS (
86
- SELECT DISTINCT ON (pc.relname, pn.nspname, pa.attname)
87
- pc.relname AS table_name,
88
- pn.nspname AS table_schema,
89
- pa.attname AS column_name,
90
- pd.description
91
- FROM
92
- pg_description pd
93
- JOIN
94
- pg_class pc ON pd.objoid = pc.oid
95
- JOIN
96
- pg_namespace pn ON pc.relnamespace = pn.oid
97
- LEFT JOIN
98
- pg_attribute pa ON pd.objoid = pa.attrelid AND pd.objsubid = pa.attnum
99
- WHERE
100
- pc.relkind = 'r'
101
- AND pn.nspname NOT IN ('pg_catalog', 'information_schema')
102
- )
85
+ WITH
86
+ comments AS (
87
+ SELECT DISTINCT ON (pc.relname, pn.nspname, pa.attname)
88
+ pc.relname AS table_name,
89
+ pn.nspname AS table_schema,
90
+ pa.attname AS column_name,
91
+ pd.description
92
+ FROM
93
+ pg_description pd
94
+ JOIN
95
+ pg_class pc ON pd.objoid = pc.oid
96
+ JOIN
97
+ pg_namespace pn ON pc.relnamespace = pn.oid
98
+ LEFT JOIN
99
+ pg_attribute pa ON pd.objoid = pa.attrelid AND pd.objsubid = pa.attnum
100
+ WHERE
101
+ pc.relkind = 'r'
102
+ AND pn.nspname NOT IN ('pg_catalog', 'information_schema')
103
+ ),
104
+ table_positions AS (
105
+ SELECT
106
+ pc.oid as table_ordinal_position,
107
+ pc.relname as table_name,
108
+ pn.nspname as table_schema
109
+ FROM pg_class pc
110
+ JOIN pg_namespace pn
111
+ ON pc.relnamespace = pn.oid
112
+ WHERE
113
+ -- r is ordinary table
114
+ -- see https://www.postgresql.org/docs/14/catalog-pg-class.html#:~:text=%3D%20temporary%20table-,relkind,-char
115
+ pc.relkind = 'r'
116
+ AND pn.nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast')
117
+ ${(0, parseSchema_1.buildSchemaQuery)('t.table_schema', schemas)}
118
+ )
103
119
  SELECT
104
120
  t.table_schema,
105
121
  t.table_name,
@@ -128,13 +144,15 @@ const generateTablesAndFields = async (client, schemas) => {
128
144
  information_schema.columns c
129
145
  JOIN
130
146
  information_schema.tables t ON c.table_name = t.table_name AND c.table_schema = t.table_schema
147
+ JOIN
148
+ table_positions tp ON tp.table_name = t.table_name AND tp.table_schema = t.table_schema
131
149
  WHERE
132
150
  t.table_type = 'BASE TABLE'
133
151
  AND t.table_schema NOT IN ('pg_catalog', 'information_schema')
134
152
  ${(0, parseSchema_1.buildSchemaQuery)('t.table_schema', schemas)}
135
153
  ORDER BY
136
154
  t.table_schema,
137
- t.table_name,
155
+ tp.table_ordinal_position,
138
156
  c.ordinal_position
139
157
  ;
140
158
  `;
File without changes
@@ -159,7 +159,7 @@ const generateTablesAndFields = async (conn, schemas) => {
159
159
  ${schemaSql}
160
160
  ORDER BY
161
161
  c.table_schema,
162
- c.table_name,
162
+ t.created,
163
163
  c.ordinal_position;
164
164
  `;
165
165
  const tablesAndFieldsResult = await executeQuery(conn, tablesAndFieldsSql);
File without changes
File without changes
package/dist/index.d.ts CHANGED
File without changes
package/dist/index.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/jest.config.ts CHANGED
File without changes
package/jestHelpers.ts CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbml/connector",
3
- "version": "3.9.2",
3
+ "version": "3.9.3",
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",
@@ -40,5 +40,5 @@
40
40
  "engines": {
41
41
  "node": ">=18"
42
42
  },
43
- "gitHead": "3e9e33e62a49bd91268a71e47fe89aed4a683518"
43
+ "gitHead": "f78c1f65fcf3f7edc472fbe2038abf1fd56dccdb"
44
44
  }
@@ -137,15 +137,10 @@ async function generateTablesAndFields(
137
137
  t.table_schema = c.table_schema
138
138
  and t.table_name = c.table_name
139
139
  where t.table_type = 'BASE TABLE'
140
- order by t.table_name, c.ordinal_position;
140
+ order by t.create_time, c.ordinal_position;
141
141
  `;
142
142
 
143
- const [queryResult] = await client.query({
144
- query,
145
- params: {
146
- // stringRegex: STRING_REGEX,
147
- },
148
- });
143
+ const [queryResult] = await client.query({ query });
149
144
 
150
145
  const tableMap: Record<string, Table> = {};
151
146
  const fieldMap: FieldsDictionary = {};
File without changes
@@ -178,7 +178,9 @@ const generateTablesFieldsAndEnums = async (client: sql.ConnectionPool, schemas:
178
178
  SELECT
179
179
  s.name AS table_schema,
180
180
  t.name AS table_name,
181
+ t.create_date as table_create_date,
181
182
  c.name AS column_name,
183
+ c.column_id as column_id,
182
184
  ty.name AS data_type,
183
185
  c.max_length AS character_maximum_length,
184
186
  c.precision AS numeric_precision,
@@ -265,8 +267,8 @@ const generateTablesFieldsAndEnums = async (client: sql.ConnectionPool, schemas:
265
267
  ${buildSchemaQuery('table_schema', schemas)}
266
268
  ORDER BY
267
269
  table_schema,
268
- table_name,
269
- column_name;
270
+ table_create_date,
271
+ column_id;
270
272
  `;
271
273
 
272
274
  const tablesAndFieldsResult = await client.query(tablesAndFieldsSql);
File without changes
@@ -120,24 +120,40 @@ const generateTablesAndFields = async (client: Client, schemas: string[]): Promi
120
120
  }> => {
121
121
  const fields: FieldsDictionary = {};
122
122
  const tablesAndFieldsSql = `
123
- WITH comments AS (
124
- SELECT DISTINCT ON (pc.relname, pn.nspname, pa.attname)
125
- pc.relname AS table_name,
126
- pn.nspname AS table_schema,
127
- pa.attname AS column_name,
128
- pd.description
129
- FROM
130
- pg_description pd
131
- JOIN
132
- pg_class pc ON pd.objoid = pc.oid
133
- JOIN
134
- pg_namespace pn ON pc.relnamespace = pn.oid
135
- LEFT JOIN
136
- pg_attribute pa ON pd.objoid = pa.attrelid AND pd.objsubid = pa.attnum
137
- WHERE
138
- pc.relkind = 'r'
139
- AND pn.nspname NOT IN ('pg_catalog', 'information_schema')
140
- )
123
+ WITH
124
+ comments AS (
125
+ SELECT DISTINCT ON (pc.relname, pn.nspname, pa.attname)
126
+ pc.relname AS table_name,
127
+ pn.nspname AS table_schema,
128
+ pa.attname AS column_name,
129
+ pd.description
130
+ FROM
131
+ pg_description pd
132
+ JOIN
133
+ pg_class pc ON pd.objoid = pc.oid
134
+ JOIN
135
+ pg_namespace pn ON pc.relnamespace = pn.oid
136
+ LEFT JOIN
137
+ pg_attribute pa ON pd.objoid = pa.attrelid AND pd.objsubid = pa.attnum
138
+ WHERE
139
+ pc.relkind = 'r'
140
+ AND pn.nspname NOT IN ('pg_catalog', 'information_schema')
141
+ ),
142
+ table_positions AS (
143
+ SELECT
144
+ pc.oid as table_ordinal_position,
145
+ pc.relname as table_name,
146
+ pn.nspname as table_schema
147
+ FROM pg_class pc
148
+ JOIN pg_namespace pn
149
+ ON pc.relnamespace = pn.oid
150
+ WHERE
151
+ -- r is ordinary table
152
+ -- see https://www.postgresql.org/docs/14/catalog-pg-class.html#:~:text=%3D%20temporary%20table-,relkind,-char
153
+ pc.relkind = 'r'
154
+ AND pn.nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast')
155
+ ${buildSchemaQuery('t.table_schema', schemas)}
156
+ )
141
157
  SELECT
142
158
  t.table_schema,
143
159
  t.table_name,
@@ -166,13 +182,15 @@ const generateTablesAndFields = async (client: Client, schemas: string[]): Promi
166
182
  information_schema.columns c
167
183
  JOIN
168
184
  information_schema.tables t ON c.table_name = t.table_name AND c.table_schema = t.table_schema
185
+ JOIN
186
+ table_positions tp ON tp.table_name = t.table_name AND tp.table_schema = t.table_schema
169
187
  WHERE
170
188
  t.table_type = 'BASE TABLE'
171
189
  AND t.table_schema NOT IN ('pg_catalog', 'information_schema')
172
190
  ${buildSchemaQuery('t.table_schema', schemas)}
173
191
  ORDER BY
174
192
  t.table_schema,
175
- t.table_name,
193
+ tp.table_ordinal_position,
176
194
  c.ordinal_position
177
195
  ;
178
196
  `;
@@ -212,7 +212,7 @@ const generateTablesAndFields = async (conn: Connection, schemas: string[]): Pro
212
212
  ${schemaSql}
213
213
  ORDER BY
214
214
  c.table_schema,
215
- c.table_name,
215
+ t.created,
216
216
  c.ordinal_position;
217
217
  `;
218
218
 
File without changes
File without changes
File without changes
package/src/index.ts CHANGED
File without changes
File without changes
File without changes
File without changes
package/tsconfig.json CHANGED
File without changes