kysely-gen 0.12.1 → 0.13.0
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/dist/cli.js +81 -7
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -109898,6 +109898,44 @@ function parseMssqlOrChain(definition) {
|
|
|
109898
109898
|
}
|
|
109899
109899
|
return values.length > 0 ? values : null;
|
|
109900
109900
|
}
|
|
109901
|
+
var MYSQL_IN_REGEX = /^[\s(]*`?(\w+)`?\s+IN\s*\(([^)]+)\)/i;
|
|
109902
|
+
function parseMysqlCheckConstraint(definition) {
|
|
109903
|
+
if (!definition || definition.trim() === "")
|
|
109904
|
+
return null;
|
|
109905
|
+
const match = definition.match(MYSQL_IN_REGEX);
|
|
109906
|
+
if (!match)
|
|
109907
|
+
return null;
|
|
109908
|
+
const columnName = match[1];
|
|
109909
|
+
const valuesPart = match[2];
|
|
109910
|
+
if (!valuesPart || valuesPart.trim() === "")
|
|
109911
|
+
return null;
|
|
109912
|
+
const numericValues = parseNumericArray(valuesPart);
|
|
109913
|
+
if (numericValues !== null) {
|
|
109914
|
+
if (isBooleanPattern(numericValues)) {
|
|
109915
|
+
return { columnName, constraint: { type: "boolean" } };
|
|
109916
|
+
}
|
|
109917
|
+
return { columnName, constraint: { type: "number", values: numericValues } };
|
|
109918
|
+
}
|
|
109919
|
+
const stringValues = parseMysqlStringArray(valuesPart);
|
|
109920
|
+
if (stringValues !== null && stringValues.length > 0) {
|
|
109921
|
+
return { columnName, constraint: { type: "string", values: stringValues } };
|
|
109922
|
+
}
|
|
109923
|
+
return null;
|
|
109924
|
+
}
|
|
109925
|
+
function parseMysqlStringArray(arrayContent) {
|
|
109926
|
+
const values = [];
|
|
109927
|
+
const mysqlValueRegex = /_\w+\\'([^'\\]*)\\'/g;
|
|
109928
|
+
let match;
|
|
109929
|
+
while ((match = mysqlValueRegex.exec(arrayContent)) !== null) {
|
|
109930
|
+
let value = match[1];
|
|
109931
|
+
value = value.replace(/''/g, "'");
|
|
109932
|
+
values.push(value);
|
|
109933
|
+
}
|
|
109934
|
+
if (values.length > 0) {
|
|
109935
|
+
return values;
|
|
109936
|
+
}
|
|
109937
|
+
return parseStringArray(arrayContent);
|
|
109938
|
+
}
|
|
109901
109939
|
|
|
109902
109940
|
// src/dialects/postgres/introspect.ts
|
|
109903
109941
|
async function introspectPostgres(db, options) {
|
|
@@ -110441,11 +110479,22 @@ function isEnumType(columnType) {
|
|
|
110441
110479
|
|
|
110442
110480
|
// src/dialects/mysql/introspect.ts
|
|
110443
110481
|
async function introspectMysql(db, options) {
|
|
110444
|
-
const [baseTables, views] = await Promise.all([
|
|
110482
|
+
const [baseTables, views, checkConstraints] = await Promise.all([
|
|
110445
110483
|
introspectTables2(db, options.schemas),
|
|
110446
|
-
introspectViews2(db, options.schemas)
|
|
110484
|
+
introspectViews2(db, options.schemas),
|
|
110485
|
+
introspectCheckConstraints2(db, options.schemas)
|
|
110447
110486
|
]);
|
|
110448
|
-
const tables = [...baseTables, ...views]
|
|
110487
|
+
const tables = [...baseTables, ...views].map((table) => ({
|
|
110488
|
+
...table,
|
|
110489
|
+
columns: table.columns.map((column) => {
|
|
110490
|
+
const key = `${table.schema}.${table.name}.${column.name}`;
|
|
110491
|
+
const checkConstraint = checkConstraints.get(key);
|
|
110492
|
+
return {
|
|
110493
|
+
...column,
|
|
110494
|
+
...checkConstraint && { checkConstraint }
|
|
110495
|
+
};
|
|
110496
|
+
})
|
|
110497
|
+
}));
|
|
110449
110498
|
const enums = extractEnums(tables);
|
|
110450
110499
|
return {
|
|
110451
110500
|
tables,
|
|
@@ -110560,6 +110609,31 @@ function extractEnums(tables) {
|
|
|
110560
110609
|
}
|
|
110561
110610
|
return Array.from(enumMap.values());
|
|
110562
110611
|
}
|
|
110612
|
+
async function introspectCheckConstraints2(db, schemas) {
|
|
110613
|
+
const rawConstraints = await sql`
|
|
110614
|
+
SELECT
|
|
110615
|
+
tc.TABLE_SCHEMA AS CONSTRAINT_SCHEMA,
|
|
110616
|
+
tc.TABLE_NAME,
|
|
110617
|
+
cc.CHECK_CLAUSE
|
|
110618
|
+
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
|
|
110619
|
+
JOIN INFORMATION_SCHEMA.CHECK_CONSTRAINTS cc
|
|
110620
|
+
ON tc.CONSTRAINT_SCHEMA = cc.CONSTRAINT_SCHEMA
|
|
110621
|
+
AND tc.CONSTRAINT_NAME = cc.CONSTRAINT_NAME
|
|
110622
|
+
WHERE tc.CONSTRAINT_TYPE = 'CHECK'
|
|
110623
|
+
AND tc.TABLE_SCHEMA IN (${sql.join(schemas.map((s) => sql`${s}`))})
|
|
110624
|
+
`.execute(db);
|
|
110625
|
+
const constraintMap = new Map;
|
|
110626
|
+
for (const row of rawConstraints.rows) {
|
|
110627
|
+
const parsed = parseMysqlCheckConstraint(row.CHECK_CLAUSE);
|
|
110628
|
+
if (!parsed)
|
|
110629
|
+
continue;
|
|
110630
|
+
const key = `${row.CONSTRAINT_SCHEMA}.${row.TABLE_NAME}.${parsed.columnName}`;
|
|
110631
|
+
if (constraintMap.has(key))
|
|
110632
|
+
continue;
|
|
110633
|
+
constraintMap.set(key, parsed.constraint);
|
|
110634
|
+
}
|
|
110635
|
+
return constraintMap;
|
|
110636
|
+
}
|
|
110563
110637
|
|
|
110564
110638
|
// src/dialects/mysql/type-mapper.ts
|
|
110565
110639
|
function createColumnType(selectType, insertType, updateType) {
|
|
@@ -110736,7 +110810,7 @@ function parseSqliteTableDDL(sql2) {
|
|
|
110736
110810
|
|
|
110737
110811
|
// src/dialects/sqlite/introspect.ts
|
|
110738
110812
|
async function introspectSqlite(db, _options) {
|
|
110739
|
-
const checkConstraints = await
|
|
110813
|
+
const checkConstraints = await introspectCheckConstraints3(db);
|
|
110740
110814
|
const [baseTables, views] = await Promise.all([
|
|
110741
110815
|
introspectTables3(db, checkConstraints),
|
|
110742
110816
|
introspectViews3(db)
|
|
@@ -110809,7 +110883,7 @@ function normalizeDataType2(type) {
|
|
|
110809
110883
|
}
|
|
110810
110884
|
return lowerType;
|
|
110811
110885
|
}
|
|
110812
|
-
async function
|
|
110886
|
+
async function introspectCheckConstraints3(db) {
|
|
110813
110887
|
const result = await sql`
|
|
110814
110888
|
SELECT name, sql FROM sqlite_master
|
|
110815
110889
|
WHERE type = 'table'
|
|
@@ -110910,7 +110984,7 @@ async function introspectMssql(db, options) {
|
|
|
110910
110984
|
const [baseTables, views, checkConstraints] = await Promise.all([
|
|
110911
110985
|
introspectTables4(db, options.schemas),
|
|
110912
110986
|
introspectViews4(db, options.schemas),
|
|
110913
|
-
|
|
110987
|
+
introspectCheckConstraints4(db, options.schemas)
|
|
110914
110988
|
]);
|
|
110915
110989
|
const tables = [...baseTables, ...views].map((table) => ({
|
|
110916
110990
|
...table,
|
|
@@ -110998,7 +111072,7 @@ function buildTableMetadata2(rows, isView) {
|
|
|
110998
111072
|
}
|
|
110999
111073
|
return Array.from(tableMap.values());
|
|
111000
111074
|
}
|
|
111001
|
-
async function
|
|
111075
|
+
async function introspectCheckConstraints4(db, schemas) {
|
|
111002
111076
|
const rawConstraints = await sql`
|
|
111003
111077
|
SELECT
|
|
111004
111078
|
s.name AS schema_name,
|