@argos-js/data 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +799 -2
- package/dist/connection/index.d.ts +2 -0
- package/dist/connection/index.d.ts.map +1 -0
- package/dist/connection/index.js +18 -0
- package/dist/connection/index.js.map +1 -0
- package/dist/connection/manager.d.ts +93 -0
- package/dist/connection/manager.d.ts.map +1 -0
- package/dist/connection/manager.js +194 -0
- package/dist/connection/manager.js.map +1 -0
- package/dist/database.d.ts +29 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +276 -0
- package/dist/database.js.map +1 -0
- package/dist/drivers/base-driver.d.ts +18 -0
- package/dist/drivers/base-driver.d.ts.map +1 -0
- package/dist/drivers/base-driver.js +211 -0
- package/dist/drivers/base-driver.js.map +1 -0
- package/dist/drivers/index.d.ts +11 -0
- package/dist/drivers/index.d.ts.map +1 -0
- package/dist/drivers/index.js +55 -0
- package/dist/drivers/index.js.map +1 -0
- package/dist/drivers/mavedb-edge.d.ts +8 -0
- package/dist/drivers/mavedb-edge.d.ts.map +1 -0
- package/dist/drivers/mavedb-edge.js +18 -0
- package/dist/drivers/mavedb-edge.js.map +1 -0
- package/dist/drivers/mongodb.d.ts +8 -0
- package/dist/drivers/mongodb.d.ts.map +1 -0
- package/dist/drivers/mongodb.js +18 -0
- package/dist/drivers/mongodb.js.map +1 -0
- package/dist/drivers/mssql.d.ts +8 -0
- package/dist/drivers/mssql.d.ts.map +1 -0
- package/dist/drivers/mssql.js +18 -0
- package/dist/drivers/mssql.js.map +1 -0
- package/dist/drivers/mysql.d.ts +8 -0
- package/dist/drivers/mysql.d.ts.map +1 -0
- package/dist/drivers/mysql.js +18 -0
- package/dist/drivers/mysql.js.map +1 -0
- package/dist/drivers/postgres.d.ts +8 -0
- package/dist/drivers/postgres.d.ts.map +1 -0
- package/dist/drivers/postgres.js +18 -0
- package/dist/drivers/postgres.js.map +1 -0
- package/dist/drivers/redis.d.ts +9 -0
- package/dist/drivers/redis.d.ts.map +1 -0
- package/dist/drivers/redis.js +50 -0
- package/dist/drivers/redis.js.map +1 -0
- package/dist/drivers/sqlite.d.ts +8 -0
- package/dist/drivers/sqlite.d.ts.map +1 -0
- package/dist/drivers/sqlite.js +18 -0
- package/dist/drivers/sqlite.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/index.d.ts +7 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +23 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/migrator.d.ts +79 -0
- package/dist/migrations/migrator.d.ts.map +1 -0
- package/dist/migrations/migrator.js +274 -0
- package/dist/migrations/migrator.js.map +1 -0
- package/dist/migrations/schema-builder.d.ts +318 -0
- package/dist/migrations/schema-builder.d.ts.map +1 -0
- package/dist/migrations/schema-builder.js +957 -0
- package/dist/migrations/schema-builder.js.map +1 -0
- package/dist/migrations/types.d.ts +58 -0
- package/dist/migrations/types.d.ts.map +1 -0
- package/dist/migrations/types.js +3 -0
- package/dist/migrations/types.js.map +1 -0
- package/dist/model.d.ts +107 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +333 -0
- package/dist/model.js.map +1 -0
- package/dist/plugin.d.ts +38 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +83 -0
- package/dist/plugin.js.map +1 -0
- package/dist/query-builder.d.ts +58 -0
- package/dist/query-builder.d.ts.map +1 -0
- package/dist/query-builder.js +534 -0
- package/dist/query-builder.js.map +1 -0
- package/dist/schema-adapter.d.ts +34 -0
- package/dist/schema-adapter.d.ts.map +1 -0
- package/dist/schema-adapter.js +511 -0
- package/dist/schema-adapter.js.map +1 -0
- package/dist/schema.d.ts +104 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +190 -0
- package/dist/schema.js.map +1 -0
- package/dist/seeds/index.d.ts +3 -0
- package/dist/seeds/index.d.ts.map +1 -0
- package/dist/seeds/index.js +19 -0
- package/dist/seeds/index.js.map +1 -0
- package/dist/seeds/seeder.d.ts +27 -0
- package/dist/seeds/seeder.d.ts.map +1 -0
- package/dist/seeds/seeder.js +138 -0
- package/dist/seeds/seeder.js.map +1 -0
- package/dist/seeds/types.d.ts +60 -0
- package/dist/seeds/types.d.ts.map +1 -0
- package/dist/seeds/types.js +3 -0
- package/dist/seeds/types.js.map +1 -0
- package/dist/sync/dump.d.ts +80 -0
- package/dist/sync/dump.d.ts.map +1 -0
- package/dist/sync/dump.js +655 -0
- package/dist/sync/dump.js.map +1 -0
- package/dist/sync/index.d.ts +5 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +21 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/introspector.d.ts +49 -0
- package/dist/sync/introspector.d.ts.map +1 -0
- package/dist/sync/introspector.js +750 -0
- package/dist/sync/introspector.js.map +1 -0
- package/dist/sync/synchronizer.d.ts +50 -0
- package/dist/sync/synchronizer.d.ts.map +1 -0
- package/dist/sync/synchronizer.js +506 -0
- package/dist/sync/synchronizer.js.map +1 -0
- package/dist/sync/types.d.ts +83 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +3 -0
- package/dist/sync/types.js.map +1 -0
- package/dist/tenant/sequence.d.ts +36 -0
- package/dist/tenant/sequence.d.ts.map +1 -0
- package/dist/tenant/sequence.js +130 -0
- package/dist/tenant/sequence.js.map +1 -0
- package/dist/types.d.ts +81 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -3
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseIntrospector = void 0;
|
|
4
|
+
const schema_adapter_1 = require("../schema-adapter");
|
|
5
|
+
/**
|
|
6
|
+
* Agnostic Database Schema Introspector.
|
|
7
|
+
* Discovers and parses user tables, columns, primary keys, indices, and constraints
|
|
8
|
+
* across SQLite, PostgreSQL, and MySQL.
|
|
9
|
+
*/
|
|
10
|
+
class DatabaseIntrospector {
|
|
11
|
+
db;
|
|
12
|
+
dialect;
|
|
13
|
+
constructor(db) {
|
|
14
|
+
this.db = db;
|
|
15
|
+
this.dialect = (0, schema_adapter_1.normalizeDialect)(db.driverName);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Introspects the entire database schema and returns a normalized representation.
|
|
19
|
+
*/
|
|
20
|
+
async introspect() {
|
|
21
|
+
if (!this.db.isConnected) {
|
|
22
|
+
await this.db.connect();
|
|
23
|
+
}
|
|
24
|
+
const tableNames = await this.listTables();
|
|
25
|
+
const tables = [];
|
|
26
|
+
for (const tableName of tableNames) {
|
|
27
|
+
const table = await this.introspectTable(tableName);
|
|
28
|
+
tables.push(table);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
dialect: this.dialect,
|
|
32
|
+
tables,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Lists all relevant user tables in the database, ignoring internal system tables
|
|
37
|
+
* except for framework metadata tables (`_argos_migrations`, `_argos_tenant_sequences`).
|
|
38
|
+
*/
|
|
39
|
+
async listTables() {
|
|
40
|
+
if (this.dialect === 'postgres') {
|
|
41
|
+
const sql = `
|
|
42
|
+
SELECT table_name
|
|
43
|
+
FROM information_schema.tables
|
|
44
|
+
WHERE table_schema = 'public' AND table_type = 'BASE TABLE'
|
|
45
|
+
ORDER BY table_name;
|
|
46
|
+
`;
|
|
47
|
+
const res = await this.db.execute(sql);
|
|
48
|
+
return res.rows
|
|
49
|
+
.map((r) => r.table_name)
|
|
50
|
+
.filter((t) => this.isUserTable(t));
|
|
51
|
+
}
|
|
52
|
+
if (this.dialect === 'mysql' || this.dialect === 'mariadb') {
|
|
53
|
+
const sql = `
|
|
54
|
+
SELECT table_name
|
|
55
|
+
FROM information_schema.tables
|
|
56
|
+
WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE'
|
|
57
|
+
ORDER BY table_name;
|
|
58
|
+
`;
|
|
59
|
+
const res = await this.db.execute(sql);
|
|
60
|
+
return res.rows
|
|
61
|
+
.map((r) => r.table_name)
|
|
62
|
+
.filter((t) => this.isUserTable(t));
|
|
63
|
+
}
|
|
64
|
+
if (this.dialect === 'mssql') {
|
|
65
|
+
const sql = `
|
|
66
|
+
SELECT TABLE_NAME as table_name
|
|
67
|
+
FROM INFORMATION_SCHEMA.TABLES
|
|
68
|
+
WHERE TABLE_TYPE = 'BASE TABLE'
|
|
69
|
+
ORDER BY TABLE_NAME;
|
|
70
|
+
`;
|
|
71
|
+
const res = await this.db.execute(sql);
|
|
72
|
+
return res.rows
|
|
73
|
+
.map((r) => r.table_name)
|
|
74
|
+
.filter((t) => this.isUserTable(t));
|
|
75
|
+
}
|
|
76
|
+
if (this.dialect === 'oracle') {
|
|
77
|
+
const sql = `
|
|
78
|
+
SELECT table_name
|
|
79
|
+
FROM user_tables
|
|
80
|
+
ORDER BY table_name;
|
|
81
|
+
`;
|
|
82
|
+
const res = await this.db.execute(sql);
|
|
83
|
+
return res.rows
|
|
84
|
+
.map((r) => r.table_name.toLowerCase())
|
|
85
|
+
.filter((t) => this.isUserTable(t));
|
|
86
|
+
}
|
|
87
|
+
// SQLite
|
|
88
|
+
const sql = `
|
|
89
|
+
SELECT name
|
|
90
|
+
FROM sqlite_master
|
|
91
|
+
WHERE type = 'table' AND name NOT LIKE 'sqlite_%'
|
|
92
|
+
ORDER BY name;
|
|
93
|
+
`;
|
|
94
|
+
const res = await this.db.execute(sql);
|
|
95
|
+
return res.rows
|
|
96
|
+
.map((r) => r.name)
|
|
97
|
+
.filter((t) => this.isUserTable(t));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns true if the table should be included in synchronization.
|
|
101
|
+
* Preserves `_argos_migrations` and `_argos_tenant_sequences`, filters out system tables.
|
|
102
|
+
*/
|
|
103
|
+
isUserTable(name) {
|
|
104
|
+
if (name === '_argos_migrations' || name === '_argos_tenant_sequences') {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
const lower = name.toLowerCase();
|
|
108
|
+
if (lower.startsWith('sqlite_') ||
|
|
109
|
+
lower.startsWith('pg_') ||
|
|
110
|
+
lower.startsWith('information_schema') ||
|
|
111
|
+
lower.startsWith('performance_schema') ||
|
|
112
|
+
lower.startsWith('trace_xe_') ||
|
|
113
|
+
lower.startsWith('spt_') ||
|
|
114
|
+
lower === 'mysql' ||
|
|
115
|
+
lower === 'sys' ||
|
|
116
|
+
lower === 'msreplication_options' ||
|
|
117
|
+
lower === 'help') {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Introspects details for a single table.
|
|
124
|
+
*/
|
|
125
|
+
async introspectTable(tableName) {
|
|
126
|
+
if (this.dialect === 'postgres') {
|
|
127
|
+
return this.introspectPostgresTable(tableName);
|
|
128
|
+
}
|
|
129
|
+
if (this.dialect === 'mysql' || this.dialect === 'mariadb') {
|
|
130
|
+
return this.introspectMysqlTable(tableName);
|
|
131
|
+
}
|
|
132
|
+
if (this.dialect === 'mssql') {
|
|
133
|
+
return this.introspectMssqlTable(tableName);
|
|
134
|
+
}
|
|
135
|
+
if (this.dialect === 'oracle') {
|
|
136
|
+
return this.introspectOracleTable(tableName);
|
|
137
|
+
}
|
|
138
|
+
return this.introspectSqliteTable(tableName);
|
|
139
|
+
}
|
|
140
|
+
// =========================================================================
|
|
141
|
+
// SQLite Introspection
|
|
142
|
+
// =========================================================================
|
|
143
|
+
async introspectSqliteTable(tableName) {
|
|
144
|
+
// 1. Column information via PRAGMA table_xinfo (includes generated columns)
|
|
145
|
+
const colInfo = await this.db.execute(`PRAGMA table_xinfo("${tableName}")`);
|
|
146
|
+
// Check table create SQL to verify explicit AUTOINCREMENT
|
|
147
|
+
let tableSql = '';
|
|
148
|
+
const masterRes = await this.db.execute(`SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ?`, [tableName]);
|
|
149
|
+
if (masterRes.rows.length > 0 && masterRes.rows[0].sql) {
|
|
150
|
+
tableSql = masterRes.rows[0].sql;
|
|
151
|
+
}
|
|
152
|
+
// 2. Indices via PRAGMA index_list
|
|
153
|
+
const indexList = await this.db.execute(`PRAGMA index_list("${tableName}")`);
|
|
154
|
+
const indices = [];
|
|
155
|
+
const uniqueCols = new Set();
|
|
156
|
+
for (const idx of indexList.rows) {
|
|
157
|
+
const idxInfo = await this.db.execute(`PRAGMA index_info("${idx.name}")`);
|
|
158
|
+
const cols = idxInfo.rows.map((r) => r.name);
|
|
159
|
+
const isUnique = Boolean(idx.unique);
|
|
160
|
+
const isPrimary = idx.origin === 'pk';
|
|
161
|
+
if (isUnique && cols.length === 1 && !isPrimary) {
|
|
162
|
+
uniqueCols.add(cols[0]);
|
|
163
|
+
}
|
|
164
|
+
if (!idx.name.startsWith('sqlite_autoindex_')) {
|
|
165
|
+
indices.push({
|
|
166
|
+
name: idx.name,
|
|
167
|
+
columns: cols,
|
|
168
|
+
isUnique,
|
|
169
|
+
isPrimary,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// 3. Foreign Keys via PRAGMA foreign_key_list
|
|
174
|
+
const fkList = await this.db.execute(`PRAGMA foreign_key_list("${tableName}")`);
|
|
175
|
+
const foreignKeys = fkList.rows.map((fk) => ({
|
|
176
|
+
name: `fk_${tableName}_${fk.from}`,
|
|
177
|
+
column: fk.from,
|
|
178
|
+
referencedTable: fk.table,
|
|
179
|
+
referencedColumn: fk.to,
|
|
180
|
+
onUpdate: fk.on_update,
|
|
181
|
+
onDelete: fk.on_delete,
|
|
182
|
+
}));
|
|
183
|
+
const primaryKeys = [];
|
|
184
|
+
const columns = [];
|
|
185
|
+
for (const col of colInfo.rows) {
|
|
186
|
+
const isPk = col.pk > 0;
|
|
187
|
+
if (isPk) {
|
|
188
|
+
primaryKeys.push(col.name);
|
|
189
|
+
}
|
|
190
|
+
const rawType = col.type ? col.type.trim() : 'TEXT';
|
|
191
|
+
const hasAutoIncrementKeyword = new RegExp(`\\b${col.name}\\b[^,]*AUTOINCREMENT`, 'i').test(tableSql);
|
|
192
|
+
const isAutoIncrement = hasAutoIncrementKeyword ||
|
|
193
|
+
(isPk && primaryKeys.length <= 1 && rawType.toUpperCase() === 'INTEGER');
|
|
194
|
+
const isUnique = uniqueCols.has(col.name) || (isPk && primaryKeys.length === 1);
|
|
195
|
+
const type = this.mapAgnosticType(rawType, col.name, isPk, isAutoIncrement);
|
|
196
|
+
const { length, precision, scale } = this.parseTypeModifiers(rawType);
|
|
197
|
+
const genMatch = tableSql.match(new RegExp(`\\b${col.name}\\b.*?AS\\s*\\(([^)]+)\\)(\\s*(STORED|VIRTUAL))?`, 'i'));
|
|
198
|
+
const isGenerated = (col.hidden !== undefined && (col.hidden === 2 || col.hidden === 3)) || Boolean(genMatch);
|
|
199
|
+
const generatedExpression = genMatch ? genMatch[1].trim() : undefined;
|
|
200
|
+
const generatedMode = genMatch && genMatch[3]
|
|
201
|
+
? genMatch[3].trim().toLowerCase()
|
|
202
|
+
: col.hidden === 2
|
|
203
|
+
? 'virtual'
|
|
204
|
+
: isGenerated
|
|
205
|
+
? 'stored'
|
|
206
|
+
: undefined;
|
|
207
|
+
columns.push({
|
|
208
|
+
name: col.name,
|
|
209
|
+
type,
|
|
210
|
+
rawType,
|
|
211
|
+
length,
|
|
212
|
+
precision,
|
|
213
|
+
scale,
|
|
214
|
+
isNullable: col.notnull === 0,
|
|
215
|
+
isPrimaryKey: isPk,
|
|
216
|
+
isAutoIncrement,
|
|
217
|
+
isUnique,
|
|
218
|
+
defaultValue: this.normalizeDefaultValue(col.dflt_value),
|
|
219
|
+
hasDefault: col.dflt_value !== null && col.dflt_value !== undefined,
|
|
220
|
+
isGenerated,
|
|
221
|
+
generatedExpression,
|
|
222
|
+
generatedMode,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
tableName,
|
|
227
|
+
columns,
|
|
228
|
+
primaryKeys,
|
|
229
|
+
indices,
|
|
230
|
+
foreignKeys,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
// =========================================================================
|
|
234
|
+
// PostgreSQL Introspection
|
|
235
|
+
// =========================================================================
|
|
236
|
+
async introspectPostgresTable(tableName) {
|
|
237
|
+
const colSql = `
|
|
238
|
+
SELECT
|
|
239
|
+
c.column_name,
|
|
240
|
+
c.data_type,
|
|
241
|
+
c.udt_name,
|
|
242
|
+
c.character_maximum_length,
|
|
243
|
+
c.numeric_precision,
|
|
244
|
+
c.numeric_scale,
|
|
245
|
+
c.is_nullable,
|
|
246
|
+
c.column_default,
|
|
247
|
+
COALESCE(
|
|
248
|
+
(SELECT TRUE FROM information_schema.table_constraints tc
|
|
249
|
+
JOIN information_schema.constraint_column_usage ccu ON tc.constraint_name = ccu.constraint_name AND tc.table_schema = ccu.table_schema
|
|
250
|
+
WHERE tc.table_schema = c.table_schema AND tc.table_name = c.table_name AND ccu.column_name = c.column_name AND tc.constraint_type = 'PRIMARY KEY'),
|
|
251
|
+
FALSE
|
|
252
|
+
) AS is_pk,
|
|
253
|
+
COALESCE(c.is_identity = 'YES' OR c.column_default LIKE 'nextval(%' OR c.data_type LIKE 'serial%', FALSE) AS is_autoincrement
|
|
254
|
+
FROM information_schema.columns c
|
|
255
|
+
WHERE c.table_schema = 'public' AND c.table_name = $1
|
|
256
|
+
ORDER BY c.ordinal_position;
|
|
257
|
+
`;
|
|
258
|
+
const colRes = await this.db.execute(colSql, [tableName]);
|
|
259
|
+
const primaryKeys = [];
|
|
260
|
+
const columns = [];
|
|
261
|
+
for (const c of colRes.rows) {
|
|
262
|
+
if (c.is_pk) {
|
|
263
|
+
primaryKeys.push(c.column_name);
|
|
264
|
+
}
|
|
265
|
+
const rawType = c.udt_name || c.data_type;
|
|
266
|
+
const type = this.mapAgnosticType(rawType, c.column_name, c.is_pk, c.is_autoincrement);
|
|
267
|
+
columns.push({
|
|
268
|
+
name: c.column_name,
|
|
269
|
+
type,
|
|
270
|
+
rawType,
|
|
271
|
+
length: c.character_maximum_length || undefined,
|
|
272
|
+
precision: c.numeric_precision || undefined,
|
|
273
|
+
scale: c.numeric_scale || undefined,
|
|
274
|
+
isNullable: c.is_nullable === 'YES',
|
|
275
|
+
isPrimaryKey: c.is_pk,
|
|
276
|
+
isAutoIncrement: c.is_autoincrement,
|
|
277
|
+
isUnique: false, // will update from indices
|
|
278
|
+
defaultValue: this.normalizeDefaultValue(c.column_default),
|
|
279
|
+
hasDefault: c.column_default !== null,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
// Indices
|
|
283
|
+
const idxSql = `
|
|
284
|
+
SELECT
|
|
285
|
+
i.relname AS index_name,
|
|
286
|
+
ix.indisunique AS is_unique,
|
|
287
|
+
ix.indisprimary AS is_primary,
|
|
288
|
+
string_agg(a.attname, ',' ORDER BY k.n) AS columns
|
|
289
|
+
FROM pg_index ix
|
|
290
|
+
JOIN pg_class t ON t.oid = ix.indrelid
|
|
291
|
+
JOIN pg_class i ON i.oid = ix.indexrelid
|
|
292
|
+
JOIN pg_namespace n ON n.oid = t.relnamespace
|
|
293
|
+
JOIN LATERAL unnest(ix.indkey) WITH ORDINALITY AS k(attnum, n) ON true
|
|
294
|
+
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = k.attnum
|
|
295
|
+
WHERE n.nspname = 'public' AND t.relname = $1
|
|
296
|
+
GROUP BY i.relname, ix.indisunique, ix.indisprimary;
|
|
297
|
+
`;
|
|
298
|
+
let indices = [];
|
|
299
|
+
try {
|
|
300
|
+
const idxRes = await this.db.execute(idxSql, [tableName]);
|
|
301
|
+
indices = idxRes.rows.map((r) => {
|
|
302
|
+
const cols = (r.columns || '').split(',').map((s) => s.trim());
|
|
303
|
+
if (r.is_unique && cols.length === 1) {
|
|
304
|
+
const colObj = columns.find((c) => c.name === cols[0]);
|
|
305
|
+
if (colObj)
|
|
306
|
+
colObj.isUnique = true;
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
name: r.index_name,
|
|
310
|
+
columns: cols,
|
|
311
|
+
isUnique: r.is_unique,
|
|
312
|
+
isPrimary: r.is_primary,
|
|
313
|
+
};
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
catch {
|
|
317
|
+
// Fallback if catalog query fails
|
|
318
|
+
}
|
|
319
|
+
// Foreign Keys
|
|
320
|
+
const fkSql = `
|
|
321
|
+
SELECT
|
|
322
|
+
tc.constraint_name,
|
|
323
|
+
kcu.column_name,
|
|
324
|
+
ccu.table_name AS referenced_table,
|
|
325
|
+
ccu.column_name AS referenced_column,
|
|
326
|
+
rc.update_rule AS on_update,
|
|
327
|
+
rc.delete_rule AS on_delete
|
|
328
|
+
FROM information_schema.table_constraints tc
|
|
329
|
+
JOIN information_schema.key_column_usage kcu ON tc.constraint_name = kcu.constraint_name AND tc.table_schema = kcu.table_schema
|
|
330
|
+
JOIN information_schema.constraint_column_usage ccu ON ccu.constraint_name = tc.constraint_name AND ccu.table_schema = tc.table_schema
|
|
331
|
+
JOIN information_schema.referential_constraints rc ON tc.constraint_name = rc.constraint_name AND tc.table_schema = rc.constraint_schema
|
|
332
|
+
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_schema = 'public' AND tc.table_name = $1;
|
|
333
|
+
`;
|
|
334
|
+
let foreignKeys = [];
|
|
335
|
+
try {
|
|
336
|
+
const fkRes = await this.db.execute(fkSql, [tableName]);
|
|
337
|
+
foreignKeys = fkRes.rows.map((r) => ({
|
|
338
|
+
name: r.constraint_name,
|
|
339
|
+
column: r.column_name,
|
|
340
|
+
referencedTable: r.referenced_table,
|
|
341
|
+
referencedColumn: r.referenced_column,
|
|
342
|
+
onUpdate: r.on_update,
|
|
343
|
+
onDelete: r.on_delete,
|
|
344
|
+
}));
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
// Fallback
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
tableName,
|
|
351
|
+
columns,
|
|
352
|
+
primaryKeys,
|
|
353
|
+
indices,
|
|
354
|
+
foreignKeys,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
// =========================================================================
|
|
358
|
+
// MySQL Introspection
|
|
359
|
+
// =========================================================================
|
|
360
|
+
async introspectMysqlTable(tableName) {
|
|
361
|
+
const colSql = `
|
|
362
|
+
SELECT
|
|
363
|
+
COLUMN_NAME as column_name,
|
|
364
|
+
DATA_TYPE as data_type,
|
|
365
|
+
COLUMN_TYPE as column_type,
|
|
366
|
+
CHARACTER_MAXIMUM_LENGTH as character_maximum_length,
|
|
367
|
+
NUMERIC_PRECISION as numeric_precision,
|
|
368
|
+
NUMERIC_SCALE as numeric_scale,
|
|
369
|
+
IS_NULLABLE as is_nullable,
|
|
370
|
+
COLUMN_DEFAULT as column_default,
|
|
371
|
+
EXTRA as extra,
|
|
372
|
+
COLUMN_KEY as column_key
|
|
373
|
+
FROM information_schema.columns
|
|
374
|
+
WHERE table_schema = DATABASE() AND table_name = ?
|
|
375
|
+
ORDER BY ORDINAL_POSITION;
|
|
376
|
+
`;
|
|
377
|
+
const colRes = await this.db.execute(colSql, [tableName]);
|
|
378
|
+
const primaryKeys = [];
|
|
379
|
+
const columns = [];
|
|
380
|
+
for (const c of colRes.rows) {
|
|
381
|
+
const isPk = c.column_key === 'PRI';
|
|
382
|
+
if (isPk) {
|
|
383
|
+
primaryKeys.push(c.column_name);
|
|
384
|
+
}
|
|
385
|
+
const isAutoIncrement = (c.extra || '').toLowerCase().includes('auto_increment');
|
|
386
|
+
const isUnique = c.column_key === 'UNI';
|
|
387
|
+
const rawType = c.column_type || c.data_type;
|
|
388
|
+
const type = this.mapAgnosticType(rawType, c.column_name, isPk, isAutoIncrement);
|
|
389
|
+
columns.push({
|
|
390
|
+
name: c.column_name,
|
|
391
|
+
type,
|
|
392
|
+
rawType,
|
|
393
|
+
length: c.character_maximum_length || undefined,
|
|
394
|
+
precision: c.numeric_precision || undefined,
|
|
395
|
+
scale: c.numeric_scale || undefined,
|
|
396
|
+
isNullable: c.is_nullable === 'YES',
|
|
397
|
+
isPrimaryKey: isPk,
|
|
398
|
+
isAutoIncrement,
|
|
399
|
+
isUnique,
|
|
400
|
+
defaultValue: this.normalizeDefaultValue(c.column_default),
|
|
401
|
+
hasDefault: c.column_default !== null,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
// Indices via SHOW INDEX
|
|
405
|
+
let indices = [];
|
|
406
|
+
try {
|
|
407
|
+
const idxRes = await this.db.execute(`SHOW INDEX FROM \`${tableName}\``);
|
|
408
|
+
const idxMap = new Map();
|
|
409
|
+
for (const row of idxRes.rows) {
|
|
410
|
+
if (!idxMap.has(row.Key_name)) {
|
|
411
|
+
idxMap.set(row.Key_name, {
|
|
412
|
+
unique: row.Non_unique === 0,
|
|
413
|
+
isPrimary: row.Key_name === 'PRIMARY',
|
|
414
|
+
columns: [],
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
idxMap.get(row.Key_name).columns.push(row.Column_name);
|
|
418
|
+
}
|
|
419
|
+
indices = Array.from(idxMap.entries()).map(([name, data]) => ({
|
|
420
|
+
name,
|
|
421
|
+
columns: data.columns,
|
|
422
|
+
isUnique: data.unique,
|
|
423
|
+
isPrimary: data.isPrimary,
|
|
424
|
+
}));
|
|
425
|
+
}
|
|
426
|
+
catch {
|
|
427
|
+
// Ignore index errors
|
|
428
|
+
}
|
|
429
|
+
// Foreign Keys
|
|
430
|
+
const fkSql = `
|
|
431
|
+
SELECT
|
|
432
|
+
CONSTRAINT_NAME as constraint_name,
|
|
433
|
+
COLUMN_NAME as column_name,
|
|
434
|
+
REFERENCED_TABLE_NAME as referenced_table,
|
|
435
|
+
REFERENCED_COLUMN_NAME as referenced_column
|
|
436
|
+
FROM information_schema.KEY_COLUMN_USAGE
|
|
437
|
+
WHERE table_schema = DATABASE() AND table_name = ? AND REFERENCED_TABLE_NAME IS NOT NULL;
|
|
438
|
+
`;
|
|
439
|
+
let foreignKeys = [];
|
|
440
|
+
try {
|
|
441
|
+
const fkRes = await this.db.execute(fkSql, [tableName]);
|
|
442
|
+
foreignKeys = fkRes.rows.map((r) => ({
|
|
443
|
+
name: r.constraint_name,
|
|
444
|
+
column: r.column_name,
|
|
445
|
+
referencedTable: r.referenced_table,
|
|
446
|
+
referencedColumn: r.referenced_column,
|
|
447
|
+
}));
|
|
448
|
+
}
|
|
449
|
+
catch {
|
|
450
|
+
// Fallback
|
|
451
|
+
}
|
|
452
|
+
return {
|
|
453
|
+
tableName,
|
|
454
|
+
columns,
|
|
455
|
+
primaryKeys,
|
|
456
|
+
indices,
|
|
457
|
+
foreignKeys,
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
// =========================================================================
|
|
461
|
+
// MS SQL Server Introspection
|
|
462
|
+
// =========================================================================
|
|
463
|
+
async introspectMssqlTable(tableName) {
|
|
464
|
+
const colSql = `
|
|
465
|
+
SELECT
|
|
466
|
+
c.COLUMN_NAME as column_name,
|
|
467
|
+
c.DATA_TYPE as data_type,
|
|
468
|
+
c.CHARACTER_MAXIMUM_LENGTH as character_maximum_length,
|
|
469
|
+
c.NUMERIC_PRECISION as numeric_precision,
|
|
470
|
+
c.NUMERIC_SCALE as numeric_scale,
|
|
471
|
+
c.IS_NULLABLE as is_nullable,
|
|
472
|
+
c.COLUMN_DEFAULT as column_default,
|
|
473
|
+
COLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') as is_identity
|
|
474
|
+
FROM INFORMATION_SCHEMA.COLUMNS c
|
|
475
|
+
WHERE c.TABLE_NAME = ?
|
|
476
|
+
ORDER BY c.ORDINAL_POSITION;
|
|
477
|
+
`;
|
|
478
|
+
const colRes = await this.db.execute(colSql, [tableName]);
|
|
479
|
+
const pkSql = `
|
|
480
|
+
SELECT kcu.COLUMN_NAME as column_name
|
|
481
|
+
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
|
|
482
|
+
JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu ON tc.CONSTRAINT_NAME = kcu.CONSTRAINT_NAME
|
|
483
|
+
WHERE tc.CONSTRAINT_TYPE = 'PRIMARY KEY' AND tc.TABLE_NAME = ?;
|
|
484
|
+
`;
|
|
485
|
+
let primaryKeys = [];
|
|
486
|
+
try {
|
|
487
|
+
const pkRes = await this.db.execute(pkSql, [tableName]);
|
|
488
|
+
primaryKeys = pkRes.rows.map((r) => r.column_name);
|
|
489
|
+
}
|
|
490
|
+
catch { }
|
|
491
|
+
const columns = [];
|
|
492
|
+
for (const c of colRes.rows) {
|
|
493
|
+
const isPk = primaryKeys.includes(c.column_name);
|
|
494
|
+
const isAutoIncrement = c.is_identity === 1;
|
|
495
|
+
const rawType = c.data_type;
|
|
496
|
+
const type = this.mapAgnosticType(rawType, c.column_name, isPk, isAutoIncrement);
|
|
497
|
+
columns.push({
|
|
498
|
+
name: c.column_name,
|
|
499
|
+
type,
|
|
500
|
+
rawType,
|
|
501
|
+
length: c.character_maximum_length && c.character_maximum_length > 0 ? c.character_maximum_length : undefined,
|
|
502
|
+
precision: c.numeric_precision || undefined,
|
|
503
|
+
scale: c.numeric_scale || undefined,
|
|
504
|
+
isNullable: c.is_nullable === 'YES',
|
|
505
|
+
isPrimaryKey: isPk,
|
|
506
|
+
isAutoIncrement,
|
|
507
|
+
isUnique: isPk && primaryKeys.length === 1,
|
|
508
|
+
defaultValue: this.normalizeDefaultValue(c.column_default),
|
|
509
|
+
hasDefault: c.column_default !== null,
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
const indices = [];
|
|
513
|
+
const fkSql = `
|
|
514
|
+
SELECT
|
|
515
|
+
tc.CONSTRAINT_NAME as constraint_name,
|
|
516
|
+
kcu.COLUMN_NAME as column_name,
|
|
517
|
+
ccu.TABLE_NAME as referenced_table,
|
|
518
|
+
ccu.COLUMN_NAME as referenced_column
|
|
519
|
+
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
|
|
520
|
+
JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu ON tc.CONSTRAINT_NAME = kcu.CONSTRAINT_NAME
|
|
521
|
+
JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu ON ccu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
|
|
522
|
+
WHERE tc.CONSTRAINT_TYPE = 'FOREIGN KEY' AND tc.TABLE_NAME = ?;
|
|
523
|
+
`;
|
|
524
|
+
let foreignKeys = [];
|
|
525
|
+
try {
|
|
526
|
+
const fkRes = await this.db.execute(fkSql, [tableName]);
|
|
527
|
+
foreignKeys = fkRes.rows.map((r) => ({
|
|
528
|
+
name: r.constraint_name,
|
|
529
|
+
column: r.column_name,
|
|
530
|
+
referencedTable: r.referenced_table,
|
|
531
|
+
referencedColumn: r.referenced_column,
|
|
532
|
+
}));
|
|
533
|
+
}
|
|
534
|
+
catch { }
|
|
535
|
+
return {
|
|
536
|
+
tableName,
|
|
537
|
+
columns,
|
|
538
|
+
primaryKeys,
|
|
539
|
+
indices,
|
|
540
|
+
foreignKeys,
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
// =========================================================================
|
|
544
|
+
// Oracle Introspection
|
|
545
|
+
// =========================================================================
|
|
546
|
+
async introspectOracleTable(tableName) {
|
|
547
|
+
const colSql = `
|
|
548
|
+
SELECT
|
|
549
|
+
c.column_name,
|
|
550
|
+
c.data_type,
|
|
551
|
+
c.data_length as character_maximum_length,
|
|
552
|
+
c.data_precision as numeric_precision,
|
|
553
|
+
c.data_scale as numeric_scale,
|
|
554
|
+
c.nullable as is_nullable,
|
|
555
|
+
c.data_default as column_default,
|
|
556
|
+
c.identity_column as is_identity
|
|
557
|
+
FROM user_tab_columns c
|
|
558
|
+
WHERE UPPER(c.table_name) = UPPER(?)
|
|
559
|
+
ORDER BY c.column_id
|
|
560
|
+
`;
|
|
561
|
+
const colRes = await this.db.execute(colSql, [tableName]);
|
|
562
|
+
const pkSql = `
|
|
563
|
+
SELECT cc.column_name
|
|
564
|
+
FROM user_constraints c
|
|
565
|
+
JOIN user_cons_columns cc ON c.constraint_name = cc.constraint_name
|
|
566
|
+
WHERE c.constraint_type = 'P' AND UPPER(c.table_name) = UPPER(?)
|
|
567
|
+
`;
|
|
568
|
+
let primaryKeys = [];
|
|
569
|
+
try {
|
|
570
|
+
const pkRes = await this.db.execute(pkSql, [tableName]);
|
|
571
|
+
primaryKeys = pkRes.rows.map((r) => r.column_name);
|
|
572
|
+
}
|
|
573
|
+
catch { }
|
|
574
|
+
const columns = [];
|
|
575
|
+
for (const c of colRes.rows) {
|
|
576
|
+
const colName = c.column_name.toLowerCase();
|
|
577
|
+
const isPk = primaryKeys.some((p) => p.toLowerCase() === colName);
|
|
578
|
+
const isAutoIncrement = c.is_identity === 'YES';
|
|
579
|
+
const rawType = c.data_type;
|
|
580
|
+
const type = this.mapAgnosticType(rawType, colName, isPk, isAutoIncrement);
|
|
581
|
+
columns.push({
|
|
582
|
+
name: colName,
|
|
583
|
+
type,
|
|
584
|
+
rawType,
|
|
585
|
+
length: c.character_maximum_length && c.character_maximum_length > 0 ? c.character_maximum_length : undefined,
|
|
586
|
+
precision: c.numeric_precision || undefined,
|
|
587
|
+
scale: c.numeric_scale || undefined,
|
|
588
|
+
isNullable: c.is_nullable === 'Y',
|
|
589
|
+
isPrimaryKey: isPk,
|
|
590
|
+
isAutoIncrement,
|
|
591
|
+
isUnique: isPk && primaryKeys.length === 1,
|
|
592
|
+
defaultValue: this.normalizeDefaultValue(c.column_default),
|
|
593
|
+
hasDefault: c.column_default !== null,
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
const indices = [];
|
|
597
|
+
const foreignKeys = [];
|
|
598
|
+
return {
|
|
599
|
+
tableName,
|
|
600
|
+
columns,
|
|
601
|
+
primaryKeys: primaryKeys.map((p) => p.toLowerCase()),
|
|
602
|
+
indices,
|
|
603
|
+
foreignKeys,
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
// =========================================================================
|
|
607
|
+
// Type Inference & Utilities
|
|
608
|
+
// =========================================================================
|
|
609
|
+
/**
|
|
610
|
+
* Maps a raw SQL dialect type to an agnostic primitive column type.
|
|
611
|
+
*/
|
|
612
|
+
mapAgnosticType(rawType, columnName, isPrimaryKey, isAutoIncrement) {
|
|
613
|
+
const raw = (rawType || '').toLowerCase().trim();
|
|
614
|
+
const col = columnName.toLowerCase();
|
|
615
|
+
// Primary ID check
|
|
616
|
+
if (isPrimaryKey && (isAutoIncrement || raw === 'integer' || raw === 'serial' || raw === 'bigserial')) {
|
|
617
|
+
return 'id';
|
|
618
|
+
}
|
|
619
|
+
// UUID
|
|
620
|
+
if (raw.includes('uuid')) {
|
|
621
|
+
return 'uuid';
|
|
622
|
+
}
|
|
623
|
+
// Timestamps
|
|
624
|
+
if (col === 'created_at')
|
|
625
|
+
return 'timestamp_created';
|
|
626
|
+
if (col === 'updated_at')
|
|
627
|
+
return 'timestamp_updated';
|
|
628
|
+
if (col === 'deleted_at')
|
|
629
|
+
return 'soft_delete';
|
|
630
|
+
if (raw.includes('timestamp'))
|
|
631
|
+
return 'timestamp';
|
|
632
|
+
if (raw.includes('datetime'))
|
|
633
|
+
return 'datetime';
|
|
634
|
+
// Pure Date & Time
|
|
635
|
+
if (raw === 'date')
|
|
636
|
+
return 'date';
|
|
637
|
+
if (raw === 'time' || raw.startsWith('time('))
|
|
638
|
+
return 'time';
|
|
639
|
+
// Network types
|
|
640
|
+
if (raw.includes('inet') || raw.includes('cidr'))
|
|
641
|
+
return 'inet';
|
|
642
|
+
if (raw.includes('macaddr'))
|
|
643
|
+
return 'macaddr';
|
|
644
|
+
// Vector
|
|
645
|
+
if (raw.includes('vector'))
|
|
646
|
+
return 'vector';
|
|
647
|
+
// Money
|
|
648
|
+
if (raw.includes('money'))
|
|
649
|
+
return 'money';
|
|
650
|
+
// JSON & JSONB
|
|
651
|
+
if (raw.includes('jsonb'))
|
|
652
|
+
return 'jsonb';
|
|
653
|
+
if (raw.includes('json'))
|
|
654
|
+
return 'json';
|
|
655
|
+
// Enum
|
|
656
|
+
if (raw.includes('enum'))
|
|
657
|
+
return 'enum';
|
|
658
|
+
// Booleans
|
|
659
|
+
if (raw === 'boolean' || raw === 'bool' || raw === 'tinyint(1)' || raw === 'bit') {
|
|
660
|
+
return 'boolean';
|
|
661
|
+
}
|
|
662
|
+
// Oracle number boolean check: NUMBER(1)
|
|
663
|
+
if (raw === 'number(1)' || (raw === 'number' && (col.includes('is_') || col.includes('has_') || col.includes('active')))) {
|
|
664
|
+
return 'boolean';
|
|
665
|
+
}
|
|
666
|
+
// Integers
|
|
667
|
+
if (raw.includes('bigint') || raw.includes('int8') || raw === 'number(19)') {
|
|
668
|
+
return 'bigint';
|
|
669
|
+
}
|
|
670
|
+
if (raw.includes('int') ||
|
|
671
|
+
raw.includes('tinyint') ||
|
|
672
|
+
raw.includes('smallint') ||
|
|
673
|
+
raw.includes('mediumint') ||
|
|
674
|
+
raw === 'number(10)') {
|
|
675
|
+
return 'integer';
|
|
676
|
+
}
|
|
677
|
+
// Decimals & Floats
|
|
678
|
+
if (raw.includes('decimal') || raw.includes('numeric') || (raw.startsWith('number(') && raw.includes(','))) {
|
|
679
|
+
return 'decimal';
|
|
680
|
+
}
|
|
681
|
+
if (raw.includes('float') || raw.includes('double') || raw.includes('real') || raw.includes('binary_float')) {
|
|
682
|
+
return 'float';
|
|
683
|
+
}
|
|
684
|
+
// Binaries
|
|
685
|
+
if (raw.includes('blob') || raw.includes('bytea') || raw.includes('binary') || raw.includes('varbinary')) {
|
|
686
|
+
return 'binary';
|
|
687
|
+
}
|
|
688
|
+
// Text & String
|
|
689
|
+
if (raw.includes('text') || raw.includes('clob')) {
|
|
690
|
+
return 'text';
|
|
691
|
+
}
|
|
692
|
+
if (raw.includes('char') ||
|
|
693
|
+
raw.includes('string') ||
|
|
694
|
+
raw.includes('varchar') ||
|
|
695
|
+
raw.includes('nvarchar') ||
|
|
696
|
+
raw.includes('varchar2')) {
|
|
697
|
+
return 'string';
|
|
698
|
+
}
|
|
699
|
+
return 'text';
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Parses modifiers like length, precision, scale from e.g. "VARCHAR(255)" or "DECIMAL(10,2)".
|
|
703
|
+
*/
|
|
704
|
+
parseTypeModifiers(rawType) {
|
|
705
|
+
const match = rawType.match(/\(([^)]+)\)/);
|
|
706
|
+
if (!match) {
|
|
707
|
+
return {};
|
|
708
|
+
}
|
|
709
|
+
const parts = match[1].split(',').map((p) => Number(p.trim()));
|
|
710
|
+
if (parts.length === 1 && !Number.isNaN(parts[0])) {
|
|
711
|
+
return { length: parts[0] };
|
|
712
|
+
}
|
|
713
|
+
if (parts.length === 2 && !Number.isNaN(parts[0]) && !Number.isNaN(parts[1])) {
|
|
714
|
+
return { precision: parts[0], scale: parts[1] };
|
|
715
|
+
}
|
|
716
|
+
return {};
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Cleans default values parsed from table definitions.
|
|
720
|
+
*/
|
|
721
|
+
normalizeDefaultValue(val) {
|
|
722
|
+
if (val === null || val === undefined)
|
|
723
|
+
return null;
|
|
724
|
+
if (typeof val === 'string') {
|
|
725
|
+
let trimmed = val.trim();
|
|
726
|
+
// Remove MySQL 8 collation prefixes like _utf8mb4'...' or COLLATE ...
|
|
727
|
+
trimmed = trimmed.replace(/^_\w+'(.*)'$/, '$1');
|
|
728
|
+
trimmed = trimmed.replace(/\s+COLLATE\s+[\w_]+/i, '').trim();
|
|
729
|
+
if (trimmed.toUpperCase() === 'NULL' || trimmed === "''")
|
|
730
|
+
return null;
|
|
731
|
+
if (trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
732
|
+
return trimmed.slice(1, -1);
|
|
733
|
+
}
|
|
734
|
+
if (trimmed.toUpperCase() === 'SYSUTCDATETIME()' || trimmed.toUpperCase() === 'GETDATE()') {
|
|
735
|
+
return 'CURRENT_TIMESTAMP';
|
|
736
|
+
}
|
|
737
|
+
if (!Number.isNaN(Number(trimmed))) {
|
|
738
|
+
return Number(trimmed);
|
|
739
|
+
}
|
|
740
|
+
if (trimmed.toLowerCase() === 'true' || trimmed === 'b\'1\'' || trimmed === '(1)')
|
|
741
|
+
return true;
|
|
742
|
+
if (trimmed.toLowerCase() === 'false' || trimmed === 'b\'0\'' || trimmed === '(0)')
|
|
743
|
+
return false;
|
|
744
|
+
return trimmed;
|
|
745
|
+
}
|
|
746
|
+
return val;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
exports.DatabaseIntrospector = DatabaseIntrospector;
|
|
750
|
+
//# sourceMappingURL=introspector.js.map
|