uql-orm 0.91.1 → 0.93.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/browser/http/bus.js +3 -4
- package/dist/browser/http/http.d.ts +1 -2
- package/dist/browser/http/http.js +8 -7
- package/dist/browser/index.d.ts +0 -1
- package/dist/browser/index.js +0 -1
- package/dist/browser/querier/httpQuerier.d.ts +18 -20
- package/dist/browser/querier/httpQuerier.js +20 -56
- package/dist/browser/type/index.d.ts +0 -1
- package/dist/browser/type/index.js +0 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +11 -12
- package/dist/cockroachdb/cockroachDialect.d.ts +4 -1
- package/dist/cockroachdb/cockroachDialect.js +6 -2
- package/dist/dialect/abstractDialect.d.ts +1 -1
- package/dist/dialect/abstractDialect.js +4 -1
- package/dist/dialect/abstractSqlDialect.d.ts +68 -37
- package/dist/dialect/abstractSqlDialect.js +185 -107
- package/dist/dialect/aliases.d.ts +4 -1
- package/dist/dialect/aliases.js +5 -2
- package/dist/dialect/hydrateColumn.js +3 -10
- package/dist/dialect/jsonSql.d.ts +4 -1
- package/dist/dialect/jsonSql.js +4 -1
- package/dist/dialect/mergeSqlDialect.d.ts +14 -4
- package/dist/dialect/mergeSqlDialect.js +32 -15
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +16 -24
- package/dist/dialect/mysqlLikeSqlDialect.js +38 -52
- package/dist/dialect/pgLikeSqlDialect.d.ts +8 -8
- package/dist/dialect/pgLikeSqlDialect.js +19 -22
- package/dist/http/contract.d.ts +4 -0
- package/dist/http/contract.js +1 -0
- package/dist/http/handler.d.ts +2 -2
- package/dist/http/handler.js +17 -19
- package/dist/http/query.d.ts +5 -3
- package/dist/http/query.js +42 -42
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/maria/mariaDialect.d.ts +4 -3
- package/dist/maria/mariaDialect.js +4 -6
- package/dist/migrate/builder/columnBuilder.d.ts +5 -15
- package/dist/migrate/builder/columnBuilder.js +50 -86
- package/dist/migrate/builder/index.d.ts +0 -1
- package/dist/migrate/builder/index.js +0 -1
- package/dist/migrate/builder/migrationBuilder.d.ts +3 -11
- package/dist/migrate/builder/migrationBuilder.js +41 -81
- package/dist/migrate/builder/tableBuilder.d.ts +0 -7
- package/dist/migrate/builder/tableBuilder.js +19 -30
- package/dist/migrate/builder/types.d.ts +2 -2
- package/dist/migrate/codegen/entityCodeGenerator.js +3 -3
- package/dist/migrate/codegen/entityTypes.js +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.js +22 -14
- package/dist/migrate/codegen/indexDecoratorSource.js +64 -41
- package/dist/migrate/ddl/defaultSql.d.ts +31 -0
- package/dist/migrate/ddl/defaultSql.js +109 -0
- package/dist/migrate/ddl/index.d.ts +2 -4
- package/dist/migrate/ddl/index.js +14 -5
- package/dist/migrate/ddl/mssqlTableDdl.d.ts +1 -0
- package/dist/migrate/ddl/mssqlTableDdl.js +4 -1
- package/dist/migrate/ddl/mysqlTableDdl.d.ts +17 -0
- package/dist/migrate/ddl/mysqlTableDdl.js +33 -0
- package/dist/migrate/ddl/pgTableDdl.d.ts +7 -0
- package/dist/migrate/ddl/pgTableDdl.js +17 -0
- package/dist/migrate/ddl/tableDdl.d.ts +15 -10
- package/dist/migrate/ddl/tableDdl.js +31 -32
- package/dist/migrate/drift/driftDetector.js +46 -59
- package/dist/migrate/generator/definitionToNode.d.ts +11 -7
- package/dist/migrate/generator/definitionToNode.js +27 -34
- package/dist/migrate/generator/indexNodeToSchema.d.ts +3 -3
- package/dist/migrate/generator/indexNodeToSchema.js +5 -4
- package/dist/migrate/index.js +1 -1
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +10 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +9 -0
- package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -1
- package/dist/migrate/introspection/baseSqlIntrospector.js +6 -8
- package/dist/migrate/introspection/mssqlIntrospector.js +3 -8
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +11 -4
- package/dist/migrate/introspection/mysqlIntrospector.js +27 -11
- package/dist/migrate/introspection/postgresIntrospector.d.ts +2 -2
- package/dist/migrate/introspection/postgresIntrospector.js +3 -3
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +1 -1
- package/dist/migrate/introspection/sqliteIntrospector.js +7 -10
- package/dist/migrate/migrationTarget.js +3 -3
- package/dist/migrate/schemaGenerator.d.ts +8 -12
- package/dist/migrate/schemaGenerator.js +36 -62
- package/dist/migrate/storage/databaseStorage.js +2 -2
- package/dist/migrate/triggerSql.d.ts +1 -1
- package/dist/migrate/triggerSql.js +17 -8
- package/dist/mongo/mongoDialect.d.ts +4 -3
- package/dist/mongo/mongoDialect.js +52 -38
- package/dist/mongo/mongoIntrospector.js +1 -1
- package/dist/mongo/mongoSchemaGenerator.d.ts +7 -4
- package/dist/mongo/mongoSchemaGenerator.js +18 -21
- package/dist/mongo/mongodbQuerier.d.ts +15 -8
- package/dist/mongo/mongodbQuerier.js +48 -33
- package/dist/mssql/mssqlDialect.d.ts +9 -5
- package/dist/mssql/mssqlDialect.js +23 -8
- package/dist/postgres/postgresDialect.d.ts +5 -2
- package/dist/postgres/postgresDialect.js +6 -6
- package/dist/querier/abstractQuerier.d.ts +20 -15
- package/dist/querier/abstractQuerier.js +93 -41
- package/dist/querier/abstractQuerierPool.d.ts +26 -24
- package/dist/querier/abstractQuerierPool.js +26 -64
- package/dist/querier/abstractSqlQuerier.d.ts +5 -6
- package/dist/querier/abstractSqlQuerier.js +15 -33
- package/dist/querier/cursor.d.ts +10 -0
- package/dist/querier/cursor.js +81 -0
- package/dist/querier/keyset.d.ts +19 -0
- package/dist/querier/keyset.js +198 -0
- package/dist/schema/canonicalType.d.ts +3 -3
- package/dist/schema/canonicalType.js +13 -12
- package/dist/schema/indexDifferences.d.ts +14 -7
- package/dist/schema/indexDifferences.js +7 -5
- package/dist/schema/schemaAST.d.ts +0 -1
- package/dist/schema/schemaAST.js +0 -2
- package/dist/schema/schemaASTBuilder.js +14 -20
- package/dist/schema/schemaASTDiffer.d.ts +7 -9
- package/dist/schema/schemaASTDiffer.js +54 -107
- package/dist/schema/sqlExpression.d.ts +28 -0
- package/dist/schema/sqlExpression.js +42 -0
- package/dist/schema/types.d.ts +48 -105
- package/dist/sqlite/sqliteDialect.d.ts +10 -13
- package/dist/sqlite/sqliteDialect.js +19 -30
- package/dist/type/dialect.d.ts +46 -11
- package/dist/type/dialect.js +2 -0
- package/dist/type/entity.d.ts +18 -3
- package/dist/type/migration.d.ts +7 -7
- package/dist/type/querier.d.ts +19 -26
- package/dist/type/query.d.ts +116 -25
- package/dist/type/query.js +21 -28
- package/dist/type/universalQuerier.d.ts +33 -7
- package/dist/type/utility.d.ts +10 -0
- package/dist/util/bytes.d.ts +7 -0
- package/dist/util/bytes.js +22 -0
- package/dist/util/date.d.ts +5 -0
- package/dist/util/date.js +5 -0
- package/dist/util/dialect.util.d.ts +1 -25
- package/dist/util/dialect.util.js +4 -50
- package/dist/util/field.util.d.ts +9 -0
- package/dist/util/field.util.js +15 -0
- package/dist/util/fieldOption.util.js +2 -2
- package/dist/util/index.d.ts +2 -1
- package/dist/util/index.js +2 -1
- package/dist/util/object.util.d.ts +0 -2
- package/dist/util/object.util.js +0 -7
- package/dist/util/query.util.d.ts +40 -0
- package/dist/util/query.util.js +76 -0
- package/dist/util/raw.d.ts +16 -1
- package/dist/util/raw.js +31 -0
- package/dist/util/relationQuery.util.js +18 -16
- package/dist/util/rowKey.util.js +2 -3
- package/dist/util/sql.util.d.ts +8 -2
- package/dist/util/sql.util.js +16 -17
- package/dist/util/sqlLiteral.js +2 -12
- package/dist/util/string.util.d.ts +5 -0
- package/dist/util/string.util.js +12 -0
- package/dist/util/triggerWrite.d.ts +11 -1
- package/dist/util/triggerWrite.js +14 -0
- package/package.json +1 -1
- package/skills/uql-orm/SKILL.md +22 -10
- package/dist/browser/options.d.ts +0 -4
- package/dist/browser/options.js +0 -13
- package/dist/browser/type/clientQuerierPool.d.ts +0 -4
- package/dist/browser/type/clientQuerierPool.js +0 -1
- package/dist/migrate/builder/expressions.d.ts +0 -69
- package/dist/migrate/builder/expressions.js +0 -145
package/dist/http/handler.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { withContext } from '../context/context.js';
|
|
2
2
|
import { getMeta, soleIdOf } from '../entity/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import { whereWith } from '../util/query.util.js';
|
|
4
4
|
import { UqlUsageError } from '../util/uqlError.js';
|
|
5
5
|
import { CRUD_ROUTES, entityPath, matchRoute, } from './contract.js';
|
|
6
6
|
import { parseQueryParams } from './query.js';
|
|
@@ -77,12 +77,20 @@ export function createRequestHandler(opts) {
|
|
|
77
77
|
return { data: count, count };
|
|
78
78
|
}
|
|
79
79
|
case 'findMany': {
|
|
80
|
-
|
|
81
|
-
querier.findMany(entity, query)
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
if (!counts) {
|
|
81
|
+
return { data: await querier.findMany(entity, query) };
|
|
82
|
+
}
|
|
83
|
+
// `findManyAndCount` counts every matching row, whereas `count` would count only the page `$limit` takes.
|
|
84
|
+
const [data, count] = await querier.findManyAndCount(entity, query);
|
|
84
85
|
return { data, count };
|
|
85
86
|
}
|
|
87
|
+
case 'findManyPage': {
|
|
88
|
+
const { $limit } = query;
|
|
89
|
+
if ($limit === undefined) {
|
|
90
|
+
throw new UqlUsageError('a page names how many rows it holds in $limit');
|
|
91
|
+
}
|
|
92
|
+
return { data: await querier.findManyPage(entity, { ...query, $limit }) };
|
|
93
|
+
}
|
|
86
94
|
case 'insertOne':
|
|
87
95
|
return { data: await querier.insertOne(entity, body), count: 1 };
|
|
88
96
|
case 'saveOne':
|
|
@@ -95,26 +103,16 @@ export function createRequestHandler(opts) {
|
|
|
95
103
|
const data = await querier.saveMany(entity, body);
|
|
96
104
|
return { data, count: data.length };
|
|
97
105
|
}
|
|
106
|
+
// A write returns how many rows it changed, and the querier still refuses a delete that names no rows.
|
|
98
107
|
case 'updateMany':
|
|
99
108
|
case 'updateOneById': {
|
|
100
109
|
const count = await querier.updateMany(entity, scoped, body);
|
|
101
|
-
return { data:
|
|
110
|
+
return { data: count, count };
|
|
102
111
|
}
|
|
112
|
+
case 'deleteMany':
|
|
103
113
|
case 'deleteOneById': {
|
|
104
114
|
const count = await querier.deleteMany(entity, scoped, { hardDelete });
|
|
105
|
-
return { data:
|
|
106
|
-
}
|
|
107
|
-
case 'deleteMany': {
|
|
108
|
-
const founds = await querier.findMany(entity, query);
|
|
109
|
-
if (!founds.length) {
|
|
110
|
-
return { data: [], count: 0 };
|
|
111
|
-
}
|
|
112
|
-
const idKey = soleIdOf(meta, 'the HTTP handler');
|
|
113
|
-
const ids = founds.map((found) => found[idKey]);
|
|
114
|
-
return {
|
|
115
|
-
data: ids,
|
|
116
|
-
count: await querier.deleteMany(entity, { $where: whereIds(meta, ids) }, { hardDelete }),
|
|
117
|
-
};
|
|
115
|
+
return { data: count, count };
|
|
118
116
|
}
|
|
119
117
|
}
|
|
120
118
|
}
|
package/dist/http/query.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import type { WireQuery } from '../type/index.js';
|
|
1
|
+
import type { QueryKeyset, WireQuery } from '../type/index.js';
|
|
2
2
|
/** The flags a request carries beside its query: `hardDelete` on a delete, `count` on a `findMany`. */
|
|
3
3
|
declare const WIRE_FLAGS: ["hardDelete", "count"];
|
|
4
4
|
/** {@link WIRE_FLAGS} as the booleans {@link parseQueryParams} decodes them to, where a hook may also set them. */
|
|
5
5
|
export type WireFlags = {
|
|
6
6
|
readonly [K in (typeof WIRE_FLAGS)[number]]?: boolean;
|
|
7
7
|
};
|
|
8
|
+
/** The cursors a page request carries; only `findManyPage` reads them. */
|
|
9
|
+
export type WireCursors = Pick<QueryKeyset<unknown>, '$after' | '$before'>;
|
|
8
10
|
/**
|
|
9
11
|
* Parse raw query-string entries (with JSON-stringified values), or a `QUERY` body, into a UQL query
|
|
10
|
-
* object. Symmetric counterpart of {@link stringifyQuery}. Only {@link
|
|
12
|
+
* object. Symmetric counterpart of {@link stringifyQuery}. Only the keys in {@link WIRE_VALUES} are honored.
|
|
11
13
|
*/
|
|
12
|
-
export declare function parseQueryParams<E = unknown>(params?: unknown): WireQuery<E> & WireFlags;
|
|
14
|
+
export declare function parseQueryParams<E = unknown>(params?: unknown): WireQuery<E> & WireFlags & WireCursors;
|
|
13
15
|
/**
|
|
14
16
|
* Serialize a UQL query object into a percent-encoded query string where object values
|
|
15
17
|
* are JSON-stringified. Symmetric counterpart of {@link parseQueryParams}.
|
package/dist/http/query.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// the clause
|
|
2
|
-
import {
|
|
1
|
+
// the clause table itself, not the barrel: this module is in the browser bundle's graph
|
|
2
|
+
import { QUERY_CLAUSES } from '../type/query.js';
|
|
3
3
|
// the brand alone, not the class: importing `QueryRaw` for an `instanceof` kept it, and `ColumnRef`
|
|
4
4
|
// with it, in the browser bundle, which is on a size budget
|
|
5
5
|
import { RAW_VALUE } from '../type/queryRaw.js';
|
|
@@ -9,20 +9,6 @@ import { getKeys, isRecord, isWhereMap } from '../util/object.util.js';
|
|
|
9
9
|
import { UqlUsageError } from '../util/uqlError.js';
|
|
10
10
|
/** The flags a request carries beside its query: `hardDelete` on a delete, `count` on a `findMany`. */
|
|
11
11
|
const WIRE_FLAGS = ['hardDelete', 'count'];
|
|
12
|
-
/**
|
|
13
|
-
* Keys accepted from the wire - query structure ({@link Query}) plus the {@link WIRE_FLAGS}. Anything else
|
|
14
|
-
* (e.g. `filters`, `context`, `$entity`) is dropped so a remote client can't bypass a security filter or
|
|
15
|
-
* inject ambient context - those are server-only. The `satisfies` ties
|
|
16
|
-
* every entry to a real query/option key, so a typo or a renamed option fails to compile.
|
|
17
|
-
*/
|
|
18
|
-
const ALLOWED_QUERY_KEYS = new Set([
|
|
19
|
-
...QUERY_OBJECT_CLAUSES,
|
|
20
|
-
...QUERY_ROOT_OBJECT_CLAUSES,
|
|
21
|
-
...QUERY_NUMBER_CLAUSES,
|
|
22
|
-
...QUERY_ROOT_NUMBER_CLAUSES,
|
|
23
|
-
...QUERY_BOOLEAN_CLAUSES,
|
|
24
|
-
...WIRE_FLAGS,
|
|
25
|
-
]);
|
|
26
12
|
/**
|
|
27
13
|
* Keys that mean something locally but that this transport can never honor, so they are rejected
|
|
28
14
|
* rather than dropped like the rest. Each request runs on its own auto-committing connection, so a
|
|
@@ -30,9 +16,18 @@ const ALLOWED_QUERY_KEYS = new Set([
|
|
|
30
16
|
* and ignoring it would hand the caller a read they believe is serialized and is not.
|
|
31
17
|
*/
|
|
32
18
|
const REJECTED_QUERY_KEYS = new Set(['$lock']);
|
|
19
|
+
/**
|
|
20
|
+
* The keys accepted from the wire, mapped to how each value is decoded: every query clause ({@link QUERY_CLAUSES})
|
|
21
|
+
* plus the {@link WIRE_FLAGS}. Anything else (e.g. `filters`, `context`, `$entity`) is dropped, so a remote
|
|
22
|
+
* client can't bypass a security filter or inject ambient context.
|
|
23
|
+
*/
|
|
24
|
+
const WIRE_VALUES = new Map([
|
|
25
|
+
...getKeys(QUERY_CLAUSES).map((key) => [key, QUERY_CLAUSES[key].value]),
|
|
26
|
+
...WIRE_FLAGS.map((flag) => [flag, 'boolean']),
|
|
27
|
+
]);
|
|
33
28
|
/**
|
|
34
29
|
* Parse raw query-string entries (with JSON-stringified values), or a `QUERY` body, into a UQL query
|
|
35
|
-
* object. Symmetric counterpart of {@link stringifyQuery}. Only {@link
|
|
30
|
+
* object. Symmetric counterpart of {@link stringifyQuery}. Only the keys in {@link WIRE_VALUES} are honored.
|
|
36
31
|
*/
|
|
37
32
|
export function parseQueryParams(params = {}) {
|
|
38
33
|
if (!isRecord(params)) {
|
|
@@ -43,39 +38,44 @@ export function parseQueryParams(params = {}) {
|
|
|
43
38
|
if (REJECTED_QUERY_KEYS.has(key)) {
|
|
44
39
|
throw new UqlUsageError(`'${key}' is not supported over HTTP`);
|
|
45
40
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
for (const key of [...QUERY_OBJECT_CLAUSES, ...QUERY_ROOT_OBJECT_CLAUSES]) {
|
|
51
|
-
const value = query[key];
|
|
52
|
-
if (typeof value === 'string') {
|
|
53
|
-
try {
|
|
54
|
-
query[key] = JSON.parse(value);
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
throw new UqlUsageError(`invalid JSON in '${key}'`);
|
|
58
|
-
}
|
|
41
|
+
const shape = WIRE_VALUES.get(key);
|
|
42
|
+
if (shape && params[key] !== undefined) {
|
|
43
|
+
query[key] = decodeWireValue(key, shape, params[key]);
|
|
59
44
|
}
|
|
60
45
|
}
|
|
61
46
|
query['$where'] ??= {};
|
|
62
47
|
if (!isWhereMap(query['$where'])) {
|
|
63
48
|
throw new UqlUsageError("'$where' must be a JSON object");
|
|
64
49
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
return query;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Decodes a value to the type its clause declares. A query string carries every value as text, so a boolean
|
|
54
|
+
* must be decoded: `'false'` is a non-empty string, and taken as is, `$distinct=false` would turn it on.
|
|
55
|
+
*/
|
|
56
|
+
function decodeWireValue(key, shape, value) {
|
|
57
|
+
switch (shape) {
|
|
58
|
+
case 'object':
|
|
59
|
+
return typeof value === 'string' ? parseJson(key, value) : value;
|
|
60
|
+
case 'number':
|
|
61
|
+
return Number(value);
|
|
62
|
+
case 'boolean':
|
|
63
|
+
return value === true || value === 'true';
|
|
64
|
+
case 'string':
|
|
65
|
+
// A cursor arrives as the exact text a page handed out, never as JSON, so any other value is not a cursor.
|
|
66
|
+
if (typeof value !== 'string') {
|
|
67
|
+
throw new UqlUsageError(`'${key}' must be a cursor a page handed out`);
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
72
70
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
}
|
|
72
|
+
function parseJson(key, text) {
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(text);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
throw new UqlUsageError(`invalid JSON in '${key}'`);
|
|
77
78
|
}
|
|
78
|
-
return query;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Serialize a UQL query object into a percent-encoded query string where object values
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,6 @@ export * from './type/index.js';
|
|
|
7
7
|
export { withDeleted } from './util/filters.util.js';
|
|
8
8
|
export type { HookContext } from './util/hook.util.js';
|
|
9
9
|
export { DefaultLogger } from './util/logger.js';
|
|
10
|
-
export { raw, refs } from './util/raw.js';
|
|
11
|
-
export { deleteFrom, insertInto, updateTable } from './util/triggerWrite.js';
|
|
10
|
+
export { currentDate, currentTime, currentTimestamp, raw, refs, uuid, uuidv7 } from './util/raw.js';
|
|
11
|
+
export { deleteFrom, insertInto, refuse, updateTable, upsertInto } from './util/triggerWrite.js';
|
|
12
12
|
export * from './util/uqlError.js';
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,6 @@ export * from './querier/index.js';
|
|
|
6
6
|
export * from './type/index.js';
|
|
7
7
|
export { withDeleted } from './util/filters.util.js';
|
|
8
8
|
export { DefaultLogger } from './util/logger.js';
|
|
9
|
-
export { raw, refs } from './util/raw.js';
|
|
10
|
-
export { deleteFrom, insertInto, updateTable } from './util/triggerWrite.js';
|
|
9
|
+
export { currentDate, currentTime, currentTimestamp, raw, refs, uuid, uuidv7 } from './util/raw.js';
|
|
10
|
+
export { deleteFrom, insertInto, refuse, updateTable, upsertInto } from './util/triggerWrite.js';
|
|
11
11
|
export * from './util/uqlError.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type RelationRows } from '../dialect/abstractSqlDialect.js';
|
|
2
2
|
import { type JsonAccessMode } from '../dialect/jsonSql.js';
|
|
3
3
|
import { MysqlLikeSqlDialect } from '../dialect/mysqlLikeSqlDialect.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { FieldOptions, Query, QueryContext, SqlDialectFeatures, SqlValues, Type, VectorDistance, VectorMetric } from '../type/index.js';
|
|
5
5
|
export declare class MariaDialect extends MysqlLikeSqlDialect {
|
|
6
6
|
readonly dialectName = "mariadb";
|
|
7
7
|
readonly insertIdSource = "returning";
|
|
@@ -11,12 +11,13 @@ export declare class MariaDialect extends MysqlLikeSqlDialect {
|
|
|
11
11
|
* to one table of a join.
|
|
12
12
|
*/
|
|
13
13
|
readonly features: SqlDialectFeatures;
|
|
14
|
+
/** `UUID_v7()` is MariaDB 11.7+; an older server refuses it itself. */
|
|
15
|
+
readonly sqlValues: SqlValues;
|
|
14
16
|
/**
|
|
15
17
|
* A derived table here reads no column of the statement around it, so the aggregate reads the
|
|
16
18
|
* related table itself, and orders and pages inside `JSON_ARRAYAGG`, which takes both.
|
|
17
19
|
*/
|
|
18
20
|
protected appendRelationArray(ctx: QueryContext, { entity, query, alias, joins }: RelationRows): void;
|
|
19
|
-
protected upsertReturning<E>(meta: EntityMeta<E>): string;
|
|
20
21
|
/**
|
|
21
22
|
* `JSON_EXTRACT` for the value and `JSON_VALUE` for its text, which every version has: MySQL's `->`/`->>`
|
|
22
23
|
* arrive only in 13.1.
|
|
@@ -44,7 +45,7 @@ export declare class MariaDialect extends MysqlLikeSqlDialect {
|
|
|
44
45
|
/** `SET STATEMENT ... FOR`, which scopes a variable to the statement it prefixes. */
|
|
45
46
|
protected applySettings(sql: string, settings: readonly string[]): string;
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
+
* Reads a `VECTOR` column back as its packed bytes in hex, which every driver hands over
|
|
48
49
|
* alike, and never through `VEC_ToText`, which keeps six of the nine digits a float32 needs.
|
|
49
50
|
*/
|
|
50
51
|
protected selectFieldExpr(escapedColumn: string, field: FieldOptions): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { relationTermKey } from '../dialect/abstractSqlDialect.js';
|
|
2
2
|
import { jsonPath } from '../dialect/jsonSql.js';
|
|
3
|
-
import { MYSQL_FEATURES, MYSQL_ROW_LOCKS, MysqlLikeSqlDialect } from '../dialect/mysqlLikeSqlDialect.js';
|
|
3
|
+
import { MYSQL_FEATURES, MYSQL_ROW_LOCKS, MYSQL_SQL_VALUES, MysqlLikeSqlDialect, } from '../dialect/mysqlLikeSqlDialect.js';
|
|
4
4
|
import { getMeta } from '../entity/index.js';
|
|
5
5
|
import { columnFamily } from '../util/field.util.js';
|
|
6
6
|
export class MariaDialect extends MysqlLikeSqlDialect {
|
|
@@ -20,6 +20,8 @@ export class MariaDialect extends MysqlLikeSqlDialect {
|
|
|
20
20
|
indexIfNotExists: true,
|
|
21
21
|
rowLocks: { ...MYSQL_ROW_LOCKS, of: false },
|
|
22
22
|
};
|
|
23
|
+
/** `UUID_v7()` is MariaDB 11.7+; an older server refuses it itself. */
|
|
24
|
+
sqlValues = { ...MYSQL_SQL_VALUES, uuidv7: 'UUID_v7()' };
|
|
23
25
|
/**
|
|
24
26
|
* A derived table here reads no column of the statement around it, so the aggregate reads the
|
|
25
27
|
* related table itself, and orders and pages inside `JSON_ARRAYAGG`, which takes both.
|
|
@@ -37,10 +39,6 @@ export class MariaDialect extends MysqlLikeSqlDialect {
|
|
|
37
39
|
const rows = `${query.$distinct ? 'DISTINCT ' : ''}${object}${order}${page}`;
|
|
38
40
|
ctx.append(`COALESCE((SELECT JSON_ARRAYAGG(${rows}) FROM ${this.tableRef(meta, alias).ref}${from}), JSON_ARRAY())`);
|
|
39
41
|
}
|
|
40
|
-
upsertReturning(meta) {
|
|
41
|
-
const returning = this.returningId(meta);
|
|
42
|
-
return returning ? ` ${returning}` : '';
|
|
43
|
-
}
|
|
44
42
|
/**
|
|
45
43
|
* `JSON_EXTRACT` for the value and `JSON_VALUE` for its text, which every version has: MySQL's `->`/`->>`
|
|
46
44
|
* arrive only in 13.1.
|
|
@@ -86,7 +84,7 @@ export class MariaDialect extends MysqlLikeSqlDialect {
|
|
|
86
84
|
return `SET STATEMENT ${settings.join(', ')} FOR ${sql}`;
|
|
87
85
|
}
|
|
88
86
|
/**
|
|
89
|
-
*
|
|
87
|
+
* Reads a `VECTOR` column back as its packed bytes in hex, which every driver hands over
|
|
90
88
|
* alike, and never through `VEC_ToText`, which keeps six of the nine digits a float32 needs.
|
|
91
89
|
*/
|
|
92
90
|
selectFieldExpr(escapedColumn, field) {
|
|
@@ -4,26 +4,16 @@
|
|
|
4
4
|
* Fluent API for defining columns in migrations.
|
|
5
5
|
*/
|
|
6
6
|
import type { EnumValues } from '../../schema/types.js';
|
|
7
|
-
import type
|
|
7
|
+
import { type CanonicalType, type ForeignKeyAction } from '../../schema/types.js';
|
|
8
8
|
import type { BaseColumnOptions, FullColumnDefinition, IColumnBuilder, IForeignKeyBuilder } from './types.js';
|
|
9
9
|
/**
|
|
10
|
-
* Builder for column definitions with a fluent API.
|
|
11
|
-
* Columns are NOT NULL by default (safer).
|
|
10
|
+
* Builder for column definitions with a fluent API. Each call replaces the definition it holds, and `build`
|
|
11
|
+
* returns it. Columns are NOT NULL by default (safer).
|
|
12
12
|
*/
|
|
13
13
|
export declare class ColumnBuilder implements IColumnBuilder, IForeignKeyBuilder {
|
|
14
|
-
private
|
|
15
|
-
private _type;
|
|
16
|
-
private _nullable;
|
|
17
|
-
private _defaultValue?;
|
|
18
|
-
private _primaryKey;
|
|
19
|
-
private _autoIncrement;
|
|
20
|
-
private _unique;
|
|
21
|
-
private _enum?;
|
|
22
|
-
private _generatedAs?;
|
|
23
|
-
private _comment?;
|
|
24
|
-
private _index?;
|
|
25
|
-
private _foreignKey?;
|
|
14
|
+
private column;
|
|
26
15
|
constructor(name: string, type: CanonicalType, options?: BaseColumnOptions);
|
|
16
|
+
private set;
|
|
27
17
|
/**
|
|
28
18
|
* Make the column nullable or not nullable.
|
|
29
19
|
*/
|
|
@@ -3,88 +3,73 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Fluent API for defining columns in migrations.
|
|
5
5
|
*/
|
|
6
|
+
import { DEFAULT_FOREIGN_KEY_ACTION } from '../../schema/types.js';
|
|
6
7
|
/**
|
|
7
|
-
* Builder for column definitions with a fluent API.
|
|
8
|
-
* Columns are NOT NULL by default (safer).
|
|
8
|
+
* Builder for column definitions with a fluent API. Each call replaces the definition it holds, and `build`
|
|
9
|
+
* returns it. Columns are NOT NULL by default (safer).
|
|
9
10
|
*/
|
|
10
11
|
export class ColumnBuilder {
|
|
11
|
-
|
|
12
|
-
_type;
|
|
13
|
-
_nullable;
|
|
14
|
-
_defaultValue;
|
|
15
|
-
_primaryKey;
|
|
16
|
-
_autoIncrement;
|
|
17
|
-
_unique;
|
|
18
|
-
_enum;
|
|
19
|
-
_generatedAs;
|
|
20
|
-
_comment;
|
|
21
|
-
_index;
|
|
22
|
-
_foreignKey;
|
|
12
|
+
column;
|
|
23
13
|
constructor(name, type, options = {}) {
|
|
24
|
-
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
14
|
+
const { references } = options;
|
|
15
|
+
this.column = {
|
|
16
|
+
name,
|
|
17
|
+
type: options.unsigned === undefined ? type : { ...type, unsigned: options.unsigned },
|
|
18
|
+
nullable: options.nullable ?? false,
|
|
19
|
+
defaultValue: options.defaultValue,
|
|
20
|
+
isPrimaryKey: options.primaryKey ?? false,
|
|
21
|
+
isAutoIncrement: options.autoIncrement ?? false,
|
|
22
|
+
isUnique: options.unique ?? false,
|
|
23
|
+
enum: undefined,
|
|
24
|
+
generatedAs: undefined,
|
|
25
|
+
comment: options.comment,
|
|
26
|
+
index: options.index,
|
|
27
|
+
foreignKey: references && {
|
|
28
|
+
references: { table: references.table, columns: [references.column ?? 'id'] },
|
|
29
|
+
onDelete: references.onDelete ?? DEFAULT_FOREIGN_KEY_ACTION,
|
|
30
|
+
onUpdate: references.onUpdate ?? DEFAULT_FOREIGN_KEY_ACTION,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
set(change) {
|
|
35
|
+
this.column = { ...this.column, ...change };
|
|
36
|
+
return this;
|
|
45
37
|
}
|
|
46
38
|
/**
|
|
47
39
|
* Make the column nullable or not nullable.
|
|
48
40
|
*/
|
|
49
41
|
nullable(value = true) {
|
|
50
|
-
this.
|
|
51
|
-
return this;
|
|
42
|
+
return this.set({ nullable: value });
|
|
52
43
|
}
|
|
53
44
|
/**
|
|
54
45
|
* Make the column NOT NULL.
|
|
55
46
|
*/
|
|
56
47
|
notNullable() {
|
|
57
|
-
this.
|
|
58
|
-
return this;
|
|
48
|
+
return this.set({ nullable: false });
|
|
59
49
|
}
|
|
60
50
|
/**
|
|
61
51
|
* Set a default value for the column.
|
|
62
52
|
*/
|
|
63
53
|
defaultValue(value) {
|
|
64
|
-
this.
|
|
65
|
-
return this;
|
|
54
|
+
return this.set({ defaultValue: value });
|
|
66
55
|
}
|
|
67
56
|
/**
|
|
68
57
|
* Mark as primary key.
|
|
69
58
|
*/
|
|
70
59
|
primaryKey() {
|
|
71
|
-
this.
|
|
72
|
-
this._nullable = false;
|
|
73
|
-
return this;
|
|
60
|
+
return this.set({ isPrimaryKey: true, nullable: false });
|
|
74
61
|
}
|
|
75
62
|
/**
|
|
76
63
|
* Enable auto-increment (for integer types).
|
|
77
64
|
*/
|
|
78
65
|
autoIncrement() {
|
|
79
|
-
this.
|
|
80
|
-
return this;
|
|
66
|
+
return this.set({ isAutoIncrement: true });
|
|
81
67
|
}
|
|
82
68
|
/**
|
|
83
69
|
* Add a unique constraint.
|
|
84
70
|
*/
|
|
85
71
|
unique() {
|
|
86
|
-
this.
|
|
87
|
-
return this;
|
|
72
|
+
return this.set({ isUnique: true });
|
|
88
73
|
}
|
|
89
74
|
/**
|
|
90
75
|
* Make the column one the database computes: `GENERATED ALWAYS AS (<sql>) STORED`.
|
|
@@ -93,85 +78,64 @@ export class ColumnBuilder {
|
|
|
93
78
|
* a check expression and a partial-index predicate do.
|
|
94
79
|
*/
|
|
95
80
|
computed(sql) {
|
|
96
|
-
this.
|
|
97
|
-
return this;
|
|
81
|
+
return this.set({ generatedAs: sql });
|
|
98
82
|
}
|
|
99
83
|
/**
|
|
100
84
|
* Constrain the column to these values, as a `CHECK (col IN (...))` - what `@Field({ enum })` emits.
|
|
101
85
|
*/
|
|
102
86
|
enum(values) {
|
|
103
|
-
this.
|
|
104
|
-
return this;
|
|
87
|
+
return this.set({ enum: values });
|
|
105
88
|
}
|
|
106
89
|
/**
|
|
107
90
|
* Add a comment to the column.
|
|
108
91
|
*/
|
|
109
92
|
comment(text) {
|
|
110
|
-
this.
|
|
111
|
-
return this;
|
|
93
|
+
return this.set({ comment: text });
|
|
112
94
|
}
|
|
113
95
|
/**
|
|
114
96
|
* Add an index on this column.
|
|
115
97
|
* @param name - Optional index name. If true, auto-generates name.
|
|
116
98
|
*/
|
|
117
99
|
index(name) {
|
|
118
|
-
this.
|
|
119
|
-
return this;
|
|
100
|
+
return this.set({ index: name ?? true });
|
|
120
101
|
}
|
|
121
102
|
/**
|
|
122
103
|
* Set as unsigned (MySQL/MariaDB).
|
|
123
104
|
*/
|
|
124
105
|
unsigned() {
|
|
125
|
-
this.
|
|
126
|
-
return this;
|
|
106
|
+
return this.set({ type: { ...this.column.type, unsigned: true } });
|
|
127
107
|
}
|
|
128
108
|
/**
|
|
129
109
|
* Add a foreign key reference.
|
|
130
110
|
* Returns a ForeignKeyBuilder for additional options.
|
|
131
111
|
*/
|
|
132
112
|
references(table, column = 'id') {
|
|
133
|
-
this.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
113
|
+
return this.set({
|
|
114
|
+
foreignKey: {
|
|
115
|
+
references: { table, columns: [column] },
|
|
116
|
+
onDelete: DEFAULT_FOREIGN_KEY_ACTION,
|
|
117
|
+
onUpdate: DEFAULT_FOREIGN_KEY_ACTION,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
139
120
|
}
|
|
140
121
|
/**
|
|
141
122
|
* Set ON DELETE action for foreign key.
|
|
142
123
|
*/
|
|
143
124
|
onDelete(action) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
return this;
|
|
125
|
+
const { foreignKey } = this.column;
|
|
126
|
+
return foreignKey ? this.set({ foreignKey: { ...foreignKey, onDelete: action } }) : this;
|
|
148
127
|
}
|
|
149
128
|
/**
|
|
150
129
|
* Set ON UPDATE action for foreign key.
|
|
151
130
|
*/
|
|
152
131
|
onUpdate(action) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
return this;
|
|
132
|
+
const { foreignKey } = this.column;
|
|
133
|
+
return foreignKey ? this.set({ foreignKey: { ...foreignKey, onUpdate: action } }) : this;
|
|
157
134
|
}
|
|
158
135
|
/**
|
|
159
136
|
* Build and return the column definition.
|
|
160
137
|
*/
|
|
161
138
|
build() {
|
|
162
|
-
return
|
|
163
|
-
name: this._name,
|
|
164
|
-
type: this._type,
|
|
165
|
-
nullable: this._nullable,
|
|
166
|
-
defaultValue: this._defaultValue,
|
|
167
|
-
isPrimaryKey: this._primaryKey,
|
|
168
|
-
isAutoIncrement: this._autoIncrement,
|
|
169
|
-
isUnique: this._unique,
|
|
170
|
-
enum: this._enum,
|
|
171
|
-
generatedAs: this._generatedAs,
|
|
172
|
-
comment: this._comment,
|
|
173
|
-
index: this._index,
|
|
174
|
-
foreignKey: this._foreignKey,
|
|
175
|
-
};
|
|
139
|
+
return this.column;
|
|
176
140
|
}
|
|
177
141
|
}
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import type { ForeignKeyAction } from '../../schema/types.js';
|
|
2
1
|
import type { IndexColumnInput, IndexOptions } from '../../type/index.js';
|
|
3
|
-
import type { SchemaGenerator } from '../../type/migration.js';
|
|
2
|
+
import type { ForeignKeySchema, SchemaGenerator } from '../../type/migration.js';
|
|
4
3
|
import type { AnyMigrationOperation, IAlterTableBuilder, IColumnBuilder, IColumnFactory, IMigrationBuilder, ITableBuilder } from './types.js';
|
|
5
|
-
type ForeignKeyTarget =
|
|
6
|
-
|
|
7
|
-
columns: string[];
|
|
8
|
-
};
|
|
9
|
-
type ForeignKeyOptions = {
|
|
10
|
-
name?: string;
|
|
11
|
-
onDelete?: ForeignKeyAction;
|
|
12
|
-
onUpdate?: ForeignKeyAction;
|
|
13
|
-
};
|
|
4
|
+
type ForeignKeyTarget = ForeignKeySchema['references'];
|
|
5
|
+
type ForeignKeyOptions = Pick<ForeignKeySchema, 'name' | 'onDelete' | 'onUpdate'>;
|
|
14
6
|
/**
|
|
15
7
|
* Records migration operations without executing them.
|
|
16
8
|
* Use for migration code generation and dry-run scenarios.
|