@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.
- package/.babelrc +0 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/__tests__/connector.test.ts +0 -0
- package/__tests__/connectors/bigquery/out-files/schema.json +565 -0
- package/__tests__/connectors/mssql/connection.json +0 -0
- package/__tests__/connectors/mssql/expect-out-files/schema.json +424 -424
- package/__tests__/connectors/mssql/out-files/schema.json +1858 -0
- package/__tests__/connectors/mysql/connection.json +0 -0
- package/__tests__/connectors/mysql/expect-out-files/schema.json +0 -0
- package/__tests__/connectors/mysql/out-files/schema.json +1390 -0
- package/__tests__/connectors/postgres/connection.json +0 -0
- package/__tests__/connectors/postgres/expect-out-files/schema.json +356 -356
- package/__tests__/connectors/postgres/out-files/schema.json +1619 -0
- package/dist/connectors/bigqueryConnector.d.ts +0 -0
- package/dist/connectors/bigqueryConnector.js +2 -7
- package/dist/connectors/connector.d.ts +0 -0
- package/dist/connectors/connector.js +0 -0
- package/dist/connectors/mssqlConnector.d.ts +0 -0
- package/dist/connectors/mssqlConnector.js +4 -2
- package/dist/connectors/mysqlConnector.d.ts +0 -0
- package/dist/connectors/mysqlConnector.js +0 -0
- package/dist/connectors/postgresConnector.d.ts +0 -0
- package/dist/connectors/postgresConnector.js +37 -19
- package/dist/connectors/snowflakeConnector.d.ts +0 -0
- package/dist/connectors/snowflakeConnector.js +1 -1
- package/dist/connectors/types.d.ts +0 -0
- package/dist/connectors/types.js +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/utils/credential-loader.d.ts +0 -0
- package/dist/utils/credential-loader.js +0 -0
- package/dist/utils/helpers.d.ts +0 -0
- package/dist/utils/helpers.js +0 -0
- package/dist/utils/parseSchema.d.ts +0 -0
- package/dist/utils/parseSchema.js +0 -0
- package/jest.config.ts +0 -0
- package/jestHelpers.ts +0 -0
- package/package.json +2 -2
- package/src/connectors/bigqueryConnector.ts +2 -7
- package/src/connectors/connector.ts +0 -0
- package/src/connectors/mssqlConnector.ts +4 -2
- package/src/connectors/mysqlConnector.ts +0 -0
- package/src/connectors/postgresConnector.ts +37 -19
- package/src/connectors/snowflakeConnector.ts +1 -1
- package/src/connectors/types.ts +0 -0
- package/src/ddl_samples/bigquery.sql +0 -0
- package/src/ddl_samples/snowflake.sql +0 -0
- package/src/index.ts +0 -0
- package/src/utils/credential-loader.ts +0 -0
- package/src/utils/helpers.ts +0 -0
- package/src/utils/parseSchema.ts +0 -0
- 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.
|
|
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
|
-
|
|
227
|
-
|
|
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
|
|
86
|
-
|
|
87
|
-
pc.relname
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
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
|
-
|
|
162
|
+
t.created,
|
|
163
163
|
c.ordinal_position;
|
|
164
164
|
`;
|
|
165
165
|
const tablesAndFieldsResult = await executeQuery(conn, tablesAndFieldsSql);
|
|
File without changes
|
package/dist/connectors/types.js
CHANGED
|
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
|
package/dist/utils/helpers.d.ts
CHANGED
|
File without changes
|
package/dist/utils/helpers.js
CHANGED
|
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.
|
|
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": "
|
|
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.
|
|
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
|
-
|
|
269
|
-
|
|
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
|
|
124
|
-
|
|
125
|
-
pc.relname
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
193
|
+
tp.table_ordinal_position,
|
|
176
194
|
c.ordinal_position
|
|
177
195
|
;
|
|
178
196
|
`;
|
package/src/connectors/types.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/index.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/src/utils/helpers.ts
CHANGED
|
File without changes
|
package/src/utils/parseSchema.ts
CHANGED
|
File without changes
|
package/tsconfig.json
CHANGED
|
File without changes
|