@vibeorm/sql 2.1.0 → 2.2.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/ast.d.ts +4 -2
- package/dist/ast.d.ts.map +1 -1
- package/dist/codecs.d.ts.map +1 -1
- package/dist/dialects/migration-objects.d.ts.map +1 -1
- package/dist/dialects/postgres-default-identity.d.ts +10 -0
- package/dist/dialects/postgres-default-identity.d.ts.map +1 -0
- package/dist/dialects/postgres-rls-readiness.d.ts +3 -0
- package/dist/dialects/postgres-rls-readiness.d.ts.map +1 -1
- package/dist/dialects/sqlite-session.d.ts +12 -0
- package/dist/dialects/sqlite-session.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +169 -57
- package/dist/index.js.map +13 -10
- package/dist/module-journal.d.ts +25 -0
- package/dist/module-journal.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// packages/sql/src/composable.ts
|
|
3
|
-
import { VibeError } from "@vibeorm/schema";
|
|
4
|
-
|
|
5
2
|
// packages/sql/src/params.ts
|
|
6
3
|
class ParamCollector {
|
|
7
4
|
dialect;
|
|
@@ -19,7 +16,47 @@ class ParamCollector {
|
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
|
|
19
|
+
// packages/sql/src/module-journal.ts
|
|
20
|
+
var MODULE_JOURNAL_COLUMN = "module_origin";
|
|
21
|
+
function renderModuleJournal(params) {
|
|
22
|
+
const { dialect, operation } = params;
|
|
23
|
+
const q = (name) => dialect.quoteIdent({ name });
|
|
24
|
+
const table = q(params.table);
|
|
25
|
+
const column = q(MODULE_JOURNAL_COLUMN);
|
|
26
|
+
const collector = new ParamCollector(dialect);
|
|
27
|
+
let text;
|
|
28
|
+
switch (operation.kind) {
|
|
29
|
+
case "columns":
|
|
30
|
+
text = dialect.name === "sqlite" ? `PRAGMA table_info(${table})` : `SELECT column_name AS name FROM information_schema.columns WHERE table_schema = ${dialect.name === "postgres" ? "current_schema()" : "DATABASE()"} AND table_name = ${collector.add(params.table)}`;
|
|
31
|
+
break;
|
|
32
|
+
case "addColumn":
|
|
33
|
+
text = `ALTER TABLE ${table} ADD COLUMN ${column} ${dialect.name === "mysql" ? "LONGTEXT" : "TEXT"}`;
|
|
34
|
+
break;
|
|
35
|
+
case "read":
|
|
36
|
+
text = `SELECT * FROM ${table} ORDER BY ${q("id")}`;
|
|
37
|
+
break;
|
|
38
|
+
case "insert":
|
|
39
|
+
text = `INSERT INTO ${table} (${["name", "checksum", "statement_index", MODULE_JOURNAL_COLUMN].map(q).join(", ")}) VALUES (${collector.addMany([operation.name, operation.checksum, operation.index, operation.entry]).join(", ")})`;
|
|
40
|
+
break;
|
|
41
|
+
case "complete":
|
|
42
|
+
text = `UPDATE ${table} SET ${column} = ${collector.add(operation.entry)} WHERE ${q("name")} = ${collector.add(operation.name)}`;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return { text, values: collector.values };
|
|
46
|
+
}
|
|
47
|
+
// packages/sql/src/dialects/sqlite-session.ts
|
|
48
|
+
var SQLITE_SESSION_SQL = Object.freeze({
|
|
49
|
+
lockingMode: "PRAGMA main.locking_mode",
|
|
50
|
+
exclusive: "PRAGMA main.locking_mode = EXCLUSIVE",
|
|
51
|
+
normal: "PRAGMA main.locking_mode = NORMAL",
|
|
52
|
+
acquire: "BEGIN EXCLUSIVE",
|
|
53
|
+
commit: "COMMIT",
|
|
54
|
+
rollback: "ROLLBACK",
|
|
55
|
+
touch: "SELECT name FROM main.sqlite_schema LIMIT 1",
|
|
56
|
+
foreignKeysOn: "PRAGMA foreign_keys = ON"
|
|
57
|
+
});
|
|
22
58
|
// packages/sql/src/composable.ts
|
|
59
|
+
import { VibeError } from "@vibeorm/schema";
|
|
23
60
|
var fragments = new WeakMap;
|
|
24
61
|
function invalid(message) {
|
|
25
62
|
throw new VibeError({ code: "VIBE_VALIDATION", message });
|
|
@@ -246,9 +283,11 @@ var bigIntCodec = {
|
|
|
246
283
|
decode: (value) => {
|
|
247
284
|
if (typeof value === "bigint")
|
|
248
285
|
return value;
|
|
249
|
-
if (typeof value === "string"
|
|
286
|
+
if (typeof value === "string" && /^[+-]?\d+$/.test(value.trim()))
|
|
287
|
+
return BigInt(value.trim());
|
|
288
|
+
if (typeof value === "number" && Number.isSafeInteger(value))
|
|
250
289
|
return BigInt(value);
|
|
251
|
-
|
|
290
|
+
throw new VibeError2({ code: "VIBE_DATA_INVALID", message: "BigInt requires an integer string or a safe integer", meta: { value } });
|
|
252
291
|
}
|
|
253
292
|
};
|
|
254
293
|
var decimalCodec = {
|
|
@@ -292,7 +331,10 @@ var dateNativeCodec = {
|
|
|
292
331
|
var dateTextCodec = {
|
|
293
332
|
encode: (value) => {
|
|
294
333
|
dateNativeCodec.encode(value);
|
|
295
|
-
|
|
334
|
+
const date = value instanceof Date ? value : typeof value === "string" ? parseDateTimeText({ text: value }) : typeof value === "number" ? new Date(value) : undefined;
|
|
335
|
+
if (date !== undefined && Number.isFinite(date.getTime()))
|
|
336
|
+
return date.toISOString();
|
|
337
|
+
throw new VibeError2({ code: "VIBE_VALIDATION", message: "DateTime parameters require a valid finite timestamp" });
|
|
296
338
|
},
|
|
297
339
|
decode: dateNativeCodec.decode
|
|
298
340
|
};
|
|
@@ -879,10 +921,12 @@ function isSetOperation(value) {
|
|
|
879
921
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
880
922
|
return false;
|
|
881
923
|
const keys = Object.keys(value);
|
|
882
|
-
if (
|
|
924
|
+
if (!keys.includes("__op") || !keys.includes("value"))
|
|
883
925
|
return false;
|
|
884
926
|
const candidate = value;
|
|
885
|
-
|
|
927
|
+
if (keys.length !== 2 && !(keys.length === 3 && keys.includes("numericType") && candidate.numericType === "Decimal"))
|
|
928
|
+
return false;
|
|
929
|
+
return typeof candidate.__op === "string" && SET_OPERATORS.includes(candidate.__op) && (typeof candidate.value === "number" && Number.isFinite(candidate.value) || typeof candidate.value === "string" || typeof candidate.value === "bigint");
|
|
886
930
|
}
|
|
887
931
|
var LIST_SET_OPERATORS = ["append", "concat"];
|
|
888
932
|
function isListSetOperation(value) {
|
|
@@ -1454,7 +1498,7 @@ function renderRlsRole(params) {
|
|
|
1454
1498
|
|
|
1455
1499
|
// packages/sql/src/dialects/postgres-rls-readiness.ts
|
|
1456
1500
|
var NATIVE_RLS_PROBE_POLICY = "vibeorm_probe";
|
|
1457
|
-
var
|
|
1501
|
+
var CATALOG_READS = Object.freeze({
|
|
1458
1502
|
identity: `SELECT current_user::text AS "currentUser",
|
|
1459
1503
|
session_user::text AS "sessionUser",
|
|
1460
1504
|
r.rolsuper AS "super",
|
|
@@ -1517,17 +1561,6 @@ FROM pg_catalog.pg_policy p
|
|
|
1517
1561
|
JOIN pg_catalog.pg_class c ON c.oid = p.polrelid
|
|
1518
1562
|
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
|
1519
1563
|
WHERE n.nspname = $1
|
|
1520
|
-
ORDER BY c.relname, p.polname`,
|
|
1521
|
-
expressions: `SELECT c.relname::text AS "table",
|
|
1522
|
-
p.polname::text AS "name",
|
|
1523
|
-
(n.nspname <> $1) AS "probe",
|
|
1524
|
-
pg_catalog.pg_get_expr(p.polqual, p.polrelid) AS "using",
|
|
1525
|
-
pg_catalog.pg_get_expr(p.polwithcheck, p.polrelid) AS "withCheck"
|
|
1526
|
-
FROM pg_catalog.pg_policy p
|
|
1527
|
-
JOIN pg_catalog.pg_class c ON c.oid = p.polrelid
|
|
1528
|
-
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
|
1529
|
-
WHERE (n.nspname = $1 AND p.polname = $2)
|
|
1530
|
-
OR (c.relnamespace = pg_catalog.pg_my_temp_schema() AND p.polname = $3)
|
|
1531
1564
|
ORDER BY c.relname, p.polname`,
|
|
1532
1565
|
views: `SELECT n.nspname::text AS "schema",
|
|
1533
1566
|
c.relname::text AS "name",
|
|
@@ -1575,7 +1608,35 @@ JOIN pg_catalog.pg_proc f ON f.oid = t.tgfoid
|
|
|
1575
1608
|
WHERE n.nspname = $1
|
|
1576
1609
|
AND NOT t.tgisinternal
|
|
1577
1610
|
AND f.prosecdef
|
|
1578
|
-
ORDER BY c.relname, t.tgname
|
|
1611
|
+
ORDER BY c.relname, t.tgname`
|
|
1612
|
+
});
|
|
1613
|
+
var RLS_READINESS_CATALOG_KEYS = Object.freeze(["identity", "elevatedRoles", "schemaControl", "tables", "policies", "views", "routines", "triggers"]);
|
|
1614
|
+
var COMPOSITE_CATALOG = `SELECT
|
|
1615
|
+
${RLS_READINESS_CATALOG_KEYS.map((key) => ` (SELECT json_agg(t)::text FROM (
|
|
1616
|
+
${CATALOG_READS[key]}
|
|
1617
|
+
) t) AS "${key}"`).join(`,
|
|
1618
|
+
`)}`;
|
|
1619
|
+
var RLS_READINESS_SQL = Object.freeze({
|
|
1620
|
+
identity: CATALOG_READS.identity,
|
|
1621
|
+
elevatedRoles: CATALOG_READS.elevatedRoles,
|
|
1622
|
+
schemaControl: CATALOG_READS.schemaControl,
|
|
1623
|
+
tables: CATALOG_READS.tables,
|
|
1624
|
+
policies: CATALOG_READS.policies,
|
|
1625
|
+
expressions: `SELECT c.relname::text AS "table",
|
|
1626
|
+
p.polname::text AS "name",
|
|
1627
|
+
(n.nspname <> $1) AS "probe",
|
|
1628
|
+
pg_catalog.pg_get_expr(p.polqual, p.polrelid) AS "using",
|
|
1629
|
+
pg_catalog.pg_get_expr(p.polwithcheck, p.polrelid) AS "withCheck"
|
|
1630
|
+
FROM pg_catalog.pg_policy p
|
|
1631
|
+
JOIN pg_catalog.pg_class c ON c.oid = p.polrelid
|
|
1632
|
+
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
|
1633
|
+
WHERE (n.nspname = $1 AND p.polname = $2)
|
|
1634
|
+
OR (c.relnamespace = pg_catalog.pg_my_temp_schema() AND p.polname = $3)
|
|
1635
|
+
ORDER BY c.relname, p.polname`,
|
|
1636
|
+
views: CATALOG_READS.views,
|
|
1637
|
+
routines: CATALOG_READS.routines,
|
|
1638
|
+
triggers: CATALOG_READS.triggers,
|
|
1639
|
+
catalog: COMPOSITE_CATALOG,
|
|
1579
1640
|
readSearchPath: `SELECT pg_catalog.current_setting('search_path') AS "searchPath"`,
|
|
1580
1641
|
setSearchPath: `SELECT pg_catalog.set_config('search_path', $1, true)`
|
|
1581
1642
|
});
|
|
@@ -1995,18 +2056,27 @@ function renderJsonFilter(params) {
|
|
|
1995
2056
|
}
|
|
1996
2057
|
if (dialect.jsonPathMode === "sqliteExtract") {
|
|
1997
2058
|
const column2 = quoteCol(dialect, expr.column);
|
|
1998
|
-
const
|
|
1999
|
-
if (typeof value === "
|
|
2000
|
-
return `${
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2059
|
+
const typeMatches = (type, value) => {
|
|
2060
|
+
if (typeof value === "number")
|
|
2061
|
+
return `${type} IN ('integer', 'real')`;
|
|
2062
|
+
const tag = typeof value === "boolean" ? String(value) : value === null ? "null" : Array.isArray(value) ? "array" : typeof value === "object" ? "object" : "text";
|
|
2063
|
+
return `${type} = '${tag}'`;
|
|
2064
|
+
};
|
|
2065
|
+
const compareExtracted = (path, value) => {
|
|
2066
|
+
const type = `json_type(${column2}, ${collector.add(path)})`;
|
|
2067
|
+
const guard = typeMatches(type, value);
|
|
2068
|
+
let base = guard;
|
|
2069
|
+
if (value !== null) {
|
|
2070
|
+
const target = `json_extract(${column2}, ${collector.add(path)})`;
|
|
2071
|
+
const bound = typeof value === "boolean" ? value ? 1 : 0 : value;
|
|
2072
|
+
const operand = typeof value === "object" ? `json(${collector.add(JSON.stringify(value))})` : collector.add(bound);
|
|
2073
|
+
base = `(${guard} AND ${target} = ${operand})`;
|
|
2004
2074
|
}
|
|
2005
|
-
return
|
|
2075
|
+
return expr.negate === true ? `NOT (${base})` : base;
|
|
2006
2076
|
};
|
|
2007
2077
|
switch (expr.op) {
|
|
2008
2078
|
case "equals":
|
|
2009
|
-
return compareExtracted(
|
|
2079
|
+
return compareExtracted(jsonPathString(expr.path), expr.value);
|
|
2010
2080
|
case "string_contains":
|
|
2011
2081
|
case "string_starts_with":
|
|
2012
2082
|
case "string_ends_with": {
|
|
@@ -2016,7 +2086,7 @@ function renderJsonFilter(params) {
|
|
|
2016
2086
|
case "array_starts_with":
|
|
2017
2087
|
case "array_ends_with": {
|
|
2018
2088
|
const edge = expr.op === "array_starts_with" ? "[0]" : "[#-1]";
|
|
2019
|
-
return compareExtracted(
|
|
2089
|
+
return compareExtracted(`${jsonPathString(expr.path)}${edge}`, expr.value);
|
|
2020
2090
|
}
|
|
2021
2091
|
case "array_contains": {
|
|
2022
2092
|
const guard = `json_type(${column2}, ${collector.add(jsonPathString(expr.path))}) = 'array'`;
|
|
@@ -2030,7 +2100,9 @@ function renderJsonFilter(params) {
|
|
|
2030
2100
|
});
|
|
2031
2101
|
}
|
|
2032
2102
|
const bound = typeof element === "boolean" ? element ? 1 : 0 : element;
|
|
2033
|
-
|
|
2103
|
+
const path = collector.add(jsonPathString(expr.path));
|
|
2104
|
+
const type = `${dialect.quoteIdent({ name: "json_each" })}.${dialect.quoteIdent({ name: "type" })}`;
|
|
2105
|
+
return `EXISTS (SELECT 1 FROM json_each(${column2}, ${path}) WHERE ${typeMatches(type, element)} AND ${dialect.quoteIdent({ name: "json_each" })}.${dialect.quoteIdent({ name: "value" })} = ${collector.add(bound)})`;
|
|
2034
2106
|
});
|
|
2035
2107
|
return tests.length === 0 ? guard : `(${[guard, ...tests].join(" AND ")})`;
|
|
2036
2108
|
}
|
|
@@ -2400,7 +2472,9 @@ function renderAssignments(params) {
|
|
|
2400
2472
|
return `${column} = ${collector.add(value.text)}${dialect.jsonParamCast}`;
|
|
2401
2473
|
}
|
|
2402
2474
|
if (isSetOperation(value)) {
|
|
2403
|
-
|
|
2475
|
+
const operand = collector.add(value.value);
|
|
2476
|
+
const numeric = dialect.name === "sqlite" && value.numericType === "Decimal" ? `CAST(${operand} AS REAL)` : operand;
|
|
2477
|
+
return `${column} = ${read} ${SET_OPERATION_SQL[value.__op]} ${numeric}`;
|
|
2404
2478
|
}
|
|
2405
2479
|
if (isDbNowMarker(value)) {
|
|
2406
2480
|
return `${column} = ${dialect.renderDbNow({ offsetSeconds: value.offsetSeconds, collector })}`;
|
|
@@ -2501,29 +2575,57 @@ function sqliteColumnClauses(params) {
|
|
|
2501
2575
|
}
|
|
2502
2576
|
return columns;
|
|
2503
2577
|
}
|
|
2504
|
-
// packages/sql/src/dialects/
|
|
2578
|
+
// packages/sql/src/dialects/postgres-default-identity.ts
|
|
2505
2579
|
import { unsupportedCapability as unsupportedCapability9 } from "@vibeorm/schema";
|
|
2580
|
+
function renderPostgresDefaultFunctionIdentity(params) {
|
|
2581
|
+
const { dialect, table, column } = params;
|
|
2582
|
+
if (dialect.name !== "postgres")
|
|
2583
|
+
throw unsupportedCapability9({ dialect: dialect.name, feature: "defaultFunctionIdentity" });
|
|
2584
|
+
const collector = new ParamCollector(dialect);
|
|
2585
|
+
const namespace = collector.add(table.namespace);
|
|
2586
|
+
const name = collector.add(table.name);
|
|
2587
|
+
const field = collector.add(column);
|
|
2588
|
+
return {
|
|
2589
|
+
text: `SELECT pg_catalog.pg_get_expr(ad.adbin, ad.adrelid, false) AS "expression",
|
|
2590
|
+
pn.nspname::text AS "functionNamespace", p.proname::text AS "functionName",
|
|
2591
|
+
(p.pronargs = 0 AND p.provariadic = 0 AND p.prokind = 'f' AND NOT p.proretset) AS "zeroArguments",
|
|
2592
|
+
(p.prorettype = a.atttypid AND a.atttypmod = -1) AS "exactResultType"
|
|
2593
|
+
FROM pg_catalog.pg_attrdef ad
|
|
2594
|
+
JOIN pg_catalog.pg_attribute a ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum
|
|
2595
|
+
JOIN pg_catalog.pg_class c ON c.oid = ad.adrelid
|
|
2596
|
+
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
|
2597
|
+
JOIN pg_catalog.pg_depend d ON d.classid = 'pg_catalog.pg_attrdef'::pg_catalog.regclass AND d.objid = ad.oid AND d.refclassid = 'pg_catalog.pg_proc'::pg_catalog.regclass AND d.deptype = 'n'
|
|
2598
|
+
JOIN pg_catalog.pg_proc p ON p.oid = d.refobjid
|
|
2599
|
+
JOIN pg_catalog.pg_namespace pn ON pn.oid = p.pronamespace
|
|
2600
|
+
WHERE n.nspname = ${namespace} AND c.relname = ${name} AND a.attname = ${field}
|
|
2601
|
+
AND a.attnum > 0 AND NOT a.attisdropped AND a.attgenerated = ''`,
|
|
2602
|
+
values: collector.values,
|
|
2603
|
+
returning: "none"
|
|
2604
|
+
};
|
|
2605
|
+
}
|
|
2606
|
+
// packages/sql/src/dialects/constraint-owned-index.ts
|
|
2607
|
+
import { unsupportedCapability as unsupportedCapability10 } from "@vibeorm/schema";
|
|
2506
2608
|
function renderConstraintOwnedIndexDrop(params) {
|
|
2507
2609
|
if (params.dialect.name !== "postgres")
|
|
2508
|
-
throw
|
|
2610
|
+
throw unsupportedCapability10({ dialect: params.dialect.name, feature: "constraintOwnedIndexDrop" });
|
|
2509
2611
|
const quote = (name) => params.dialect.quoteIdent({ name });
|
|
2510
2612
|
return { text: `ALTER TABLE ${quote(params.table)} DROP CONSTRAINT ${quote(params.constraint)};`, values: [], returning: "none" };
|
|
2511
2613
|
}
|
|
2512
2614
|
// packages/sql/src/dialects/mysql-check-probe.ts
|
|
2513
|
-
import { unsupportedCapability as
|
|
2615
|
+
import { unsupportedCapability as unsupportedCapability11 } from "@vibeorm/schema";
|
|
2514
2616
|
function renderMysqlCheckProbe(params) {
|
|
2515
2617
|
if (params.dialect.name !== "mysql")
|
|
2516
|
-
throw
|
|
2618
|
+
throw unsupportedCapability11({ dialect: params.dialect.name, feature: "temporaryCheckProbe" });
|
|
2517
2619
|
const q = (name) => params.dialect.quoteIdent({ name });
|
|
2518
2620
|
const probe = q(params.probe);
|
|
2519
2621
|
switch (params.operation) {
|
|
2520
2622
|
case "clone":
|
|
2521
2623
|
if (params.table === undefined)
|
|
2522
|
-
throw
|
|
2624
|
+
throw unsupportedCapability11({ dialect: "mysql", feature: "temporaryCheckProbe", hint: "A source table is required" });
|
|
2523
2625
|
return { text: `CREATE TEMPORARY TABLE ${probe} LIKE ${q(params.table.namespace)}.${q(params.table.name)}`, values: [], returning: "none" };
|
|
2524
2626
|
case "add": {
|
|
2525
2627
|
if (params.expression === undefined || params.definition === undefined)
|
|
2526
|
-
throw
|
|
2628
|
+
throw unsupportedCapability11({ dialect: "mysql", feature: "temporaryCheckProbe", hint: "An authored expression and temporary clone definition are required" });
|
|
2527
2629
|
const parts = tableDefinitionParts({ sql: params.definition });
|
|
2528
2630
|
return { text: `CREATE TEMPORARY TABLE ${probe} (
|
|
2529
2631
|
${[...parts.clauses, `CONSTRAINT ${probe} CHECK (${params.expression})`].join(`,
|
|
@@ -2569,31 +2671,31 @@ function sqliteTableConstraints(params) {
|
|
|
2569
2671
|
return result;
|
|
2570
2672
|
}
|
|
2571
2673
|
// packages/sql/src/dialects/migration-visibility.ts
|
|
2572
|
-
import { unsupportedCapability as
|
|
2674
|
+
import { unsupportedCapability as unsupportedCapability12 } from "@vibeorm/schema";
|
|
2573
2675
|
function renderMigrationVisibility(params) {
|
|
2574
2676
|
if (params.dialect.name !== "mysql")
|
|
2575
|
-
throw
|
|
2677
|
+
throw unsupportedCapability12({ dialect: params.dialect.name, feature: "mysqlCatalogVisibility" });
|
|
2576
2678
|
const collector = new ParamCollector(params.dialect);
|
|
2577
2679
|
const grantee = "CONCAT(QUOTE(SUBSTRING_INDEX(CURRENT_USER(), '@', 1)), '@', QUOTE(SUBSTRING_INDEX(CURRENT_USER(), '@', -1)))";
|
|
2578
2680
|
return { text: `SELECT PRIVILEGE_TYPE AS privilege FROM information_schema.USER_PRIVILEGES WHERE GRANTEE = ${grantee} UNION SELECT PRIVILEGE_TYPE AS privilege FROM information_schema.SCHEMA_PRIVILEGES WHERE GRANTEE = ${grantee} AND ${collector.add(params.namespace)} LIKE TABLE_SCHEMA`, values: collector.values, returning: "none" };
|
|
2579
2681
|
}
|
|
2580
2682
|
// packages/sql/src/dialects/migration-inventory.ts
|
|
2581
|
-
import { unsupportedCapability as
|
|
2683
|
+
import { unsupportedCapability as unsupportedCapability13 } from "@vibeorm/schema";
|
|
2582
2684
|
function renderSqliteColumnInventory(params) {
|
|
2583
2685
|
if (params.dialect.name !== "sqlite")
|
|
2584
|
-
throw
|
|
2686
|
+
throw unsupportedCapability13({ dialect: params.dialect.name, feature: "sqliteColumnInventory" });
|
|
2585
2687
|
const collector = new ParamCollector(params.dialect);
|
|
2586
2688
|
return { text: `SELECT name, hidden, pk, dflt_value AS definition FROM pragma_table_xinfo(${collector.add(params.table)}, ${collector.add(params.namespace)}) ORDER BY cid`, values: collector.values, returning: "none" };
|
|
2587
2689
|
}
|
|
2588
2690
|
function renderSqliteForeignKeyInventory(params) {
|
|
2589
2691
|
if (params.dialect.name !== "sqlite")
|
|
2590
|
-
throw
|
|
2692
|
+
throw unsupportedCapability13({ dialect: params.dialect.name, feature: "sqliteForeignKeyInventory" });
|
|
2591
2693
|
const collector = new ParamCollector(params.dialect);
|
|
2592
2694
|
return { text: `SELECT id, seq, "from", "to", "table", on_update, on_delete, match FROM pragma_foreign_key_list(${collector.add(params.table)}, ${collector.add(params.namespace)}) ORDER BY id, seq`, values: collector.values, returning: "none" };
|
|
2593
2695
|
}
|
|
2594
2696
|
function renderSqliteRebuildObjects(params) {
|
|
2595
2697
|
if (params.dialect.name !== "sqlite")
|
|
2596
|
-
throw
|
|
2698
|
+
throw unsupportedCapability13({ dialect: params.dialect.name, feature: "sqliteRebuildObjects" });
|
|
2597
2699
|
return { text: "SELECT name, tbl_name, type, sql FROM main.sqlite_schema WHERE type IN ('index', 'trigger') AND sql IS NOT NULL ORDER BY type, name", values: [], returning: "none" };
|
|
2598
2700
|
}
|
|
2599
2701
|
function renderMigrationInventory(params) {
|
|
@@ -2627,10 +2729,10 @@ UNION ALL SELECT 'function', ROUTINE_NAME, NULL, NULL, '[]', NULL FROM informati
|
|
|
2627
2729
|
ORDER BY kind, parent, name`, values: collector.values, returning: "none" };
|
|
2628
2730
|
}
|
|
2629
2731
|
const schema = params.dialect.quoteIdent({ name: params.namespace });
|
|
2630
|
-
return { text: `SELECT type AS kind, name, tbl_name AS parent, sql AS definition FROM ${schema}.sqlite_schema WHERE name NOT LIKE '
|
|
2732
|
+
return { text: `SELECT type AS kind, name, tbl_name AS parent, sql AS definition FROM ${schema}.sqlite_schema WHERE name NOT LIKE 'sqlite\\_%' ESCAPE '\\' AND name <> '_vibe_migrations' ORDER BY type, tbl_name, name`, values: [], returning: "none" };
|
|
2631
2733
|
}
|
|
2632
2734
|
// packages/sql/src/dialects/migration-objects.ts
|
|
2633
|
-
import { unsupportedCapability as
|
|
2735
|
+
import { unsupportedCapability as unsupportedCapability14 } from "@vibeorm/schema";
|
|
2634
2736
|
function renderMigrationObjectQuery(params) {
|
|
2635
2737
|
const { dialect, identity: object } = params;
|
|
2636
2738
|
const collector = new ParamCollector(dialect);
|
|
@@ -2668,7 +2770,10 @@ function renderMigrationObjectQuery(params) {
|
|
|
2668
2770
|
text = `SELECT pg_catalog.pg_get_indexdef(i.indexrelid, 0, false) AS "definition", i.indisunique AS "unique", i.indisvalid AS "valid", i.indisready AS "ready", con.conname::text AS "constraint", con.contype::text AS "constraintType" ${relation} JOIN pg_catalog.pg_index i ON i.indrelid = c.oid JOIN pg_catalog.pg_class ix ON ix.oid = i.indexrelid LEFT JOIN pg_catalog.pg_constraint con ON con.conindid = i.indexrelid AND con.contype IN ('p', 'u', 'x') WHERE ${where} AND ix.relname = ${collector.add(object.name)}`;
|
|
2669
2771
|
break;
|
|
2670
2772
|
case "table":
|
|
2671
|
-
text = `SELECT c.relkind::text AS "type", c.relrowsecurity AS "rls", c.relforcerowsecurity AS "forceRls" ${relation} WHERE ${where} AND c.relkind IN ('r', 'p')`;
|
|
2773
|
+
text = `SELECT c.relkind::text AS "type", c.relrowsecurity AS "rls", c.relforcerowsecurity AS "forceRls", c.relpersistence::text AS "persistence", ARRAY(SELECT option FROM unnest(c.reloptions) AS option ORDER BY option COLLATE "C") AS "options" ${relation} WHERE ${where} AND c.relkind IN ('r', 'p')`;
|
|
2774
|
+
break;
|
|
2775
|
+
case "enum":
|
|
2776
|
+
text = `SELECT ARRAY(SELECT e.enumlabel::text FROM pg_catalog.pg_enum e WHERE e.enumtypid = t.oid ORDER BY e.enumsortorder) AS "values" FROM pg_catalog.pg_type t JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = ${namespace} AND t.typname = ${name} AND t.typtype = 'e'`;
|
|
2672
2777
|
break;
|
|
2673
2778
|
case "postgresExtension":
|
|
2674
2779
|
text = `SELECT e.extversion::text AS "version", e.extrelocatable AS "relocatable" FROM pg_catalog.pg_extension e JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace WHERE n.nspname = ${namespace} AND e.extname = ${name}`;
|
|
@@ -2692,7 +2797,7 @@ function renderMigrationObjectQuery(params) {
|
|
|
2692
2797
|
break;
|
|
2693
2798
|
case "constraint":
|
|
2694
2799
|
if (object.constraintType === "exclusion")
|
|
2695
|
-
throw
|
|
2800
|
+
throw unsupportedCapability14({ dialect: "mysql", feature: "exclusionConstraints" });
|
|
2696
2801
|
text = `SELECT tc.CONSTRAINT_TYPE AS type, tc.ENFORCED AS enforced, cc.CHECK_CLAUSE AS definition, rc.UPDATE_RULE AS onUpdate, rc.DELETE_RULE AS onDelete, rc.MATCH_OPTION AS matchOption FROM information_schema.TABLE_CONSTRAINTS tc LEFT JOIN information_schema.CHECK_CONSTRAINTS cc ON cc.CONSTRAINT_SCHEMA = tc.CONSTRAINT_SCHEMA AND cc.CONSTRAINT_NAME = tc.CONSTRAINT_NAME LEFT JOIN information_schema.REFERENTIAL_CONSTRAINTS rc ON rc.CONSTRAINT_SCHEMA = tc.CONSTRAINT_SCHEMA AND rc.TABLE_NAME = tc.TABLE_NAME AND rc.CONSTRAINT_NAME = tc.CONSTRAINT_NAME WHERE tc.TABLE_SCHEMA = ${namespace} AND tc.TABLE_NAME = ${name} AND tc.CONSTRAINT_NAME = ${collector.add(object.name)}`;
|
|
2697
2802
|
break;
|
|
2698
2803
|
case "index":
|
|
@@ -2702,15 +2807,15 @@ function renderMigrationObjectQuery(params) {
|
|
|
2702
2807
|
text = `SELECT TABLE_TYPE AS type, ENGINE AS engine, TABLE_COLLATION AS collation FROM information_schema.TABLES WHERE TABLE_SCHEMA = ${namespace} AND TABLE_NAME = ${name}`;
|
|
2703
2808
|
break;
|
|
2704
2809
|
default:
|
|
2705
|
-
throw
|
|
2810
|
+
throw unsupportedCapability14({ dialect: "mysql", feature: `inspect:${object.kind}` });
|
|
2706
2811
|
}
|
|
2707
2812
|
} else {
|
|
2708
2813
|
if (physical.namespace !== "main" && physical.namespace !== "temp")
|
|
2709
|
-
throw
|
|
2814
|
+
throw unsupportedCapability14({ dialect: "sqlite", feature: "attachedSchemaInspection" });
|
|
2710
2815
|
const catalog = `${dialect.quoteIdent({ name: physical.namespace })}.sqlite_schema`;
|
|
2711
2816
|
const kind = object.kind === "table" || object.kind === "view" ? object.kind : object.kind === "trigger" ? "trigger" : object.kind === "index" ? "index" : "table";
|
|
2712
|
-
if (["function", "sequence", "postgresExtension"].includes(object.kind) || object.kind === "constraint" && object.constraintType === "exclusion")
|
|
2713
|
-
throw
|
|
2817
|
+
if (["function", "sequence", "postgresExtension", "enum"].includes(object.kind) || object.kind === "constraint" && object.constraintType === "exclusion")
|
|
2818
|
+
throw unsupportedCapability14({ dialect: "sqlite", feature: `inspect:${object.kind}` });
|
|
2714
2819
|
const sqliteParams = new ParamCollector(dialect);
|
|
2715
2820
|
if (object.kind === "column" || object.kind === "columnDefault" || object.kind === "generatedColumn") {
|
|
2716
2821
|
text = `SELECT x.type AS type, x."notnull" AS "notNull", x.pk AS primaryKeyPosition, x.hidden AS generated, x.dflt_value AS definition, (SELECT sql FROM ${catalog} WHERE name = ${sqliteParams.add(physical.name)} AND type = 'table') AS tableDefinition FROM pragma_table_xinfo(${sqliteParams.add(physical.name)}, ${sqliteParams.add(physical.namespace)}) x WHERE x.name = ${sqliteParams.add(object.column)}`;
|
|
@@ -2737,7 +2842,7 @@ function renderMysqlObjectMembers(params) {
|
|
|
2737
2842
|
}
|
|
2738
2843
|
function renderMigrationDependencies(params) {
|
|
2739
2844
|
if (params.dialect.name !== "postgres")
|
|
2740
|
-
throw
|
|
2845
|
+
throw unsupportedCapability14({ dialect: params.dialect.name, feature: "catalogDependencies" });
|
|
2741
2846
|
const object = params.identity;
|
|
2742
2847
|
const physical = "table" in object ? object.table : object.name;
|
|
2743
2848
|
const collector = new ParamCollector(params.dialect);
|
|
@@ -2768,6 +2873,9 @@ function renderMigrationDependencies(params) {
|
|
|
2768
2873
|
case "function":
|
|
2769
2874
|
source = `SELECT 'pg_proc'::regclass AS classid, p.oid AS objid, 0 AS objsubid FROM pg_catalog.pg_proc p JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace WHERE n.nspname = ${namespace} AND p.proname = ${name} AND ARRAY(SELECT tn.nspname || '.' || t.typname FROM unnest(p.proargtypes) WITH ORDINALITY a(oid, ord) JOIN pg_catalog.pg_type t ON t.oid = a.oid JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace ORDER BY a.ord) = ${collector.add(object.argumentTypes.map((type) => `${type.namespace}.${type.name}`))}::text[]`;
|
|
2770
2875
|
break;
|
|
2876
|
+
case "enum":
|
|
2877
|
+
source = `SELECT 'pg_type'::regclass AS classid, t.oid AS objid, 0 AS objsubid FROM pg_catalog.pg_type t JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = ${namespace} AND t.typname = ${name} AND t.typtype = 'e'`;
|
|
2878
|
+
break;
|
|
2771
2879
|
case "postgresExtension":
|
|
2772
2880
|
source = `SELECT 'pg_extension'::regclass AS classid, e.oid AS objid, 0 AS objsubid FROM pg_catalog.pg_extension e JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace WHERE n.nspname = ${namespace} AND e.extname = ${name}`;
|
|
2773
2881
|
break;
|
|
@@ -2785,16 +2893,16 @@ function renderMigrationNamespace(params) {
|
|
|
2785
2893
|
}
|
|
2786
2894
|
function renderCheckProbe(params) {
|
|
2787
2895
|
if (params.dialect.name !== "postgres")
|
|
2788
|
-
throw
|
|
2896
|
+
throw unsupportedCapability14({ dialect: params.dialect.name, feature: "rollbackCheckProbe" });
|
|
2789
2897
|
const q = (name) => params.dialect.quoteIdent({ name });
|
|
2790
2898
|
return { text: `ALTER TABLE ${q(params.table.namespace)}.${q(params.table.name)} ADD CONSTRAINT ${q(params.name)} CHECK (${params.expression}) NOT VALID`, values: [], returning: "none" };
|
|
2791
2899
|
}
|
|
2792
2900
|
// packages/sql/src/dialects/postgres-migration.ts
|
|
2793
|
-
import { VibeError as VibeError9, unsupportedCapability as
|
|
2901
|
+
import { VibeError as VibeError9, unsupportedCapability as unsupportedCapability15 } from "@vibeorm/schema";
|
|
2794
2902
|
var SETTING_VALUE = /^[0-9]+(?:\.[0-9]+)?\s*(?:us|ms|s|min|h|d)?$/;
|
|
2795
2903
|
function requirePostgres2(params) {
|
|
2796
2904
|
if (params.dialect.name !== "postgres") {
|
|
2797
|
-
throw
|
|
2905
|
+
throw unsupportedCapability15({ dialect: params.dialect.name, feature: params.feature });
|
|
2798
2906
|
}
|
|
2799
2907
|
}
|
|
2800
2908
|
function renderMigrationSessionRead(params) {
|
|
@@ -2928,8 +3036,10 @@ export {
|
|
|
2928
3036
|
renderPredicate,
|
|
2929
3037
|
renderPostgresWorkload,
|
|
2930
3038
|
renderPostgresExplain,
|
|
3039
|
+
renderPostgresDefaultFunctionIdentity,
|
|
2931
3040
|
renderMysqlObjectMembers,
|
|
2932
3041
|
renderMysqlCheckProbe,
|
|
3042
|
+
renderModuleJournal,
|
|
2933
3043
|
renderMigrationVisibility,
|
|
2934
3044
|
renderMigrationSessionSet,
|
|
2935
3045
|
renderMigrationSessionRestore,
|
|
@@ -2983,6 +3093,7 @@ export {
|
|
|
2983
3093
|
compileExclusion,
|
|
2984
3094
|
SQL_DIALECTS,
|
|
2985
3095
|
SQL_DEFAULT_CELL,
|
|
3096
|
+
SQLITE_SESSION_SQL,
|
|
2986
3097
|
SQLITE_CODECS,
|
|
2987
3098
|
SQLITE_CAPABILITIES,
|
|
2988
3099
|
RLS_READINESS_SQL,
|
|
@@ -2995,6 +3106,7 @@ export {
|
|
|
2995
3106
|
NATIVE_RLS,
|
|
2996
3107
|
MYSQL_CODECS,
|
|
2997
3108
|
MYSQL_CAPABILITIES,
|
|
3109
|
+
MODULE_JOURNAL_COLUMN,
|
|
2998
3110
|
JSON_TRANSPORT,
|
|
2999
3111
|
DIALECT_CODECS,
|
|
3000
3112
|
DIALECT_CAPABILITIES,
|
|
@@ -3002,4 +3114,4 @@ export {
|
|
|
3002
3114
|
ADVISORY_KEY_BOUNDS
|
|
3003
3115
|
};
|
|
3004
3116
|
|
|
3005
|
-
//# debugId=
|
|
3117
|
+
//# debugId=760F5D93FBC694E964756E2164756E21
|