uql-orm 0.101.1 → 0.101.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +6 -6
- package/dist/d1/d1SqliteDialect.d.ts +1 -1
- package/dist/d1/d1SqliteDialect.js +1 -1
- package/dist/dialect/abstractDialect.js +2 -2
- package/dist/dialect/abstractSqlDialect.d.ts +10 -10
- package/dist/dialect/abstractSqlDialect.js +24 -24
- package/dist/dialect/operators.js +2 -2
- package/dist/dialect/pgLikeSqlDialect.d.ts +1 -1
- package/dist/dialect/pgLikeSqlDialect.js +5 -5
- package/dist/dialect/queryContext.d.ts +1 -1
- package/dist/dialect/queryContext.js +1 -1
- package/dist/dialect/vectorSqlDialect.js +1 -1
- package/dist/entity/decorator/entity.d.ts +2 -2
- package/dist/entity/decorator/entity.js +2 -2
- package/dist/http/query.d.ts +1 -1
- package/dist/http/query.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/migrate/builder/tableBuilder.js +1 -1
- package/dist/migrate/builder/types.d.ts +2 -2
- package/dist/migrate/codegen/entityCodeGenerator.js +1 -1
- package/dist/migrate/codegen/fieldOptionsSource.js +5 -5
- package/dist/migrate/codegen/indexDecoratorSource.d.ts +2 -2
- package/dist/migrate/codegen/indexDecoratorSource.js +5 -5
- package/dist/migrate/codegen/migrationFile.d.ts +1 -1
- package/dist/migrate/codegen/migrationFile.js +4 -4
- package/dist/migrate/codegen/sourceLiteral.d.ts +2 -2
- package/dist/migrate/codegen/sourceLiteral.js +3 -3
- package/dist/migrate/ddl/defaultSql.js +1 -1
- package/dist/migrate/generator/definitionToNode.d.ts +3 -3
- package/dist/migrate/indexPredicate.d.ts +1 -1
- package/dist/migrate/indexPredicate.js +5 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +8 -8
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +3 -3
- package/dist/migrate/introspection/mssqlIntrospector.d.ts +5 -5
- package/dist/migrate/introspection/mssqlIntrospector.js +10 -10
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +5 -5
- package/dist/migrate/introspection/mysqlIntrospector.js +13 -13
- package/dist/migrate/introspection/postgresIntrospector.d.ts +13 -13
- package/dist/migrate/introspection/postgresIntrospector.js +21 -21
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +4 -4
- package/dist/migrate/introspection/sqliteIntrospector.js +6 -6
- package/dist/migrate/migrationLock.d.ts +3 -3
- package/dist/migrate/migrationLock.js +7 -7
- package/dist/migrate/migrationTarget.js +2 -2
- package/dist/migrate/migrator.js +2 -2
- package/dist/migrate/schemaGenerator.d.ts +1 -1
- package/dist/migrate/schemaGenerator.js +1 -1
- package/dist/migrate/storage/databaseStorage.d.ts +3 -3
- package/dist/migrate/storage/databaseStorage.js +4 -4
- package/dist/migrate/triggerSql.js +7 -7
- package/dist/mongodb/mongoDialect.js +4 -4
- package/dist/mongodb/mongoSchemaGenerator.js +3 -3
- package/dist/mssql/mssqlDialect.js +3 -3
- package/dist/querier/abstractSqlQuerier.js +1 -1
- package/dist/schema/canonicalType.d.ts +1 -1
- package/dist/schema/canonicalType.js +6 -6
- package/dist/schema/sqlExpression.d.ts +4 -4
- package/dist/schema/sqlExpression.js +5 -5
- package/dist/sqlite/sqliteDialect.js +2 -2
- package/dist/type/dialect.d.ts +3 -3
- package/dist/type/entity.d.ts +39 -39
- package/dist/type/index.d.ts +1 -1
- package/dist/type/index.js +1 -1
- package/dist/type/migration.d.ts +1 -1
- package/dist/type/querier.d.ts +5 -5
- package/dist/type/query.d.ts +32 -32
- package/dist/type/queryAggregate.d.ts +2 -2
- package/dist/type/{queryRaw.d.ts → querySql.d.ts} +33 -33
- package/dist/type/{queryRaw.js → querySql.js} +17 -17
- package/dist/type/queryWhere.d.ts +22 -22
- package/dist/type/universalQuerier.d.ts +12 -12
- package/dist/type/wire.d.ts +4 -4
- package/dist/util/ddlExpression.util.d.ts +4 -4
- package/dist/util/ddlExpression.util.js +7 -7
- package/dist/util/dialect.util.d.ts +7 -7
- package/dist/util/dialect.util.js +4 -4
- package/dist/util/fieldOption.util.d.ts +3 -3
- package/dist/util/fieldOption.util.js +5 -5
- package/dist/util/index.d.ts +1 -1
- package/dist/util/index.js +1 -1
- package/dist/util/query.util.js +1 -1
- package/dist/util/{raw.d.ts → sql.d.ts} +22 -20
- package/dist/util/{raw.js → sql.js} +28 -26
- package/dist/util/triggerWrite.d.ts +7 -7
- package/dist/util/triggerWrite.js +2 -2
- package/package.json +1 -1
- package/skills/uql-orm/SKILL.md +7 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QuerySql } from '../type/querySql.js';
|
|
2
2
|
import { isOperatorObject } from '../util/object.util.js';
|
|
3
3
|
import { UqlUsageError } from '../util/uqlError.js';
|
|
4
4
|
/**
|
|
@@ -20,11 +20,11 @@ const PREDICATE_GRAMMARS = {
|
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
22
|
* Refuses a partial index's predicate reaching past what the engine takes, before it compiles to what
|
|
23
|
-
* only the server would reject, naming the operator as its author wrote it. A `
|
|
23
|
+
* only the server would reject, naming the operator as its author wrote it. A `sql` one is left to the server.
|
|
24
24
|
*/
|
|
25
25
|
export function assertIndexPredicate(where, dialectName, indexName) {
|
|
26
26
|
const grammar = PREDICATE_GRAMMARS[dialectName];
|
|
27
|
-
const refused = grammar && !(where instanceof
|
|
27
|
+
const refused = grammar && !(where instanceof QuerySql) ? refusedOperator(where, grammar) : undefined;
|
|
28
28
|
if (refused) {
|
|
29
29
|
throw refusedIndexPredicate(dialectName, refused, indexName);
|
|
30
30
|
}
|
|
@@ -33,7 +33,7 @@ export function assertIndexPredicate(where, dialectName, indexName) {
|
|
|
33
33
|
export function refusedIndexPredicate(dialectName, part, indexName) {
|
|
34
34
|
return new UqlUsageError(`${dialectName} does not support ${part} in a partial index predicate (index "${indexName}")`);
|
|
35
35
|
}
|
|
36
|
-
/** The first part of `where` outside `grammar`, depth-first; a `
|
|
36
|
+
/** The first part of `where` outside `grammar`, depth-first; a `sql` clause is left alone. */
|
|
37
37
|
function refusedOperator(where, grammar) {
|
|
38
38
|
return Object.entries(where)
|
|
39
39
|
.map(([key, value]) => {
|
|
@@ -46,7 +46,7 @@ function refusedOperator(where, grammar) {
|
|
|
46
46
|
if (!grammar.rootOps.has(key)) {
|
|
47
47
|
return key;
|
|
48
48
|
}
|
|
49
|
-
const clauses = Array.isArray(value) ? value.filter((clause) => !(clause instanceof
|
|
49
|
+
const clauses = Array.isArray(value) ? value.filter((clause) => !(clause instanceof QuerySql)) : [];
|
|
50
50
|
return clauses.map((clause) => refusedOperator(clause, grammar)).find(Boolean);
|
|
51
51
|
})
|
|
52
52
|
.find(Boolean);
|
|
@@ -4,12 +4,12 @@ import type { SchemaAST } from '../../schema/schemaAST.js';
|
|
|
4
4
|
import { SqlExpression } from '../../schema/sqlExpression.js';
|
|
5
5
|
import type { CheckSchema, TriggerSchema } from '../../schema/types.js';
|
|
6
6
|
import { type ForeignKeyAction } from '../../schema/types.js';
|
|
7
|
-
import type { ColumnRenames, ColumnSchema, Except, ForeignKeySchema, IndexSchema, PrimaryKeySchema, QuerierPool,
|
|
7
|
+
import type { ColumnRenames, ColumnSchema, Except, ForeignKeySchema, IndexSchema, PrimaryKeySchema, QuerierPool, QuerySql, RawRow, SchemaIntrospector, SqlQuerier, StoredDefinition, TableSchema } from '../../type/index.js';
|
|
8
8
|
/**
|
|
9
9
|
* Reads the rows of one statement while introspecting a table, an identical statement sent once: SQLite's
|
|
10
10
|
* `table_info` is both the column list and the key, and on D1 and Turso every PRAGMA is a round trip.
|
|
11
11
|
*/
|
|
12
|
-
export type TableRowReader = <T extends RawRow>(sql:
|
|
12
|
+
export type TableRowReader = <T extends RawRow>(sql: QuerySql) => Promise<T[]>;
|
|
13
13
|
/** A column as its engine's catalogue reads it; the key and the indexes say which it belongs to. */
|
|
14
14
|
export type ReadColumn = Except<ColumnSchema, 'isPrimaryKey' | 'isUnique'>;
|
|
15
15
|
/** A foreign key as MySQL and SQL Server list one: a row, its column lists comma-joined. */
|
|
@@ -35,12 +35,12 @@ export declare abstract class AbstractSqlSchemaIntrospector implements SchemaInt
|
|
|
35
35
|
*/
|
|
36
36
|
constructor(pool: QuerierPool, schema?: string | undefined);
|
|
37
37
|
/** The schema every catalogue query filters on: the one that was asked for, bound, or the connection's default. */
|
|
38
|
-
protected get schemaExpr():
|
|
38
|
+
protected get schemaExpr(): QuerySql;
|
|
39
39
|
/**
|
|
40
40
|
* How this engine names the connection's current schema (Postgres) or database (MySQL). Empty on
|
|
41
41
|
* an engine with no schemas, whose catalogue queries never reference one.
|
|
42
42
|
*/
|
|
43
|
-
protected readonly defaultSchemaExpr:
|
|
43
|
+
protected readonly defaultSchemaExpr: QuerySql;
|
|
44
44
|
/**
|
|
45
45
|
* The database as a {@link SchemaAST}, or just the tables named. A name nothing matches is left out
|
|
46
46
|
* rather than raised: the point of naming them is to read a database other things are still
|
|
@@ -55,9 +55,9 @@ export declare abstract class AbstractSqlSchemaIntrospector implements SchemaInt
|
|
|
55
55
|
/** Whether the base table exists: its query answers a row for it, none for a view or nothing. */
|
|
56
56
|
protected tableExistsInternal(read: TableRowReader, tableName: string): Promise<boolean>;
|
|
57
57
|
/** SQL listing the base tables' names, as `table_name`. */
|
|
58
|
-
protected abstract getTableNamesQuery():
|
|
58
|
+
protected abstract getTableNamesQuery(): QuerySql;
|
|
59
59
|
/** SQL answering a row where the base table named exists. */
|
|
60
|
-
protected abstract tableExistsQuery(tableName: string):
|
|
60
|
+
protected abstract tableExistsQuery(tableName: string): QuerySql;
|
|
61
61
|
/** The table's columns, in their order. */
|
|
62
62
|
protected abstract getColumns(read: TableRowReader, tableName: string): Promise<ReadColumn[]>;
|
|
63
63
|
/** The table's indexes, but its key's own. */
|
|
@@ -77,14 +77,14 @@ export declare abstract class AbstractSqlSchemaIntrospector implements SchemaInt
|
|
|
77
77
|
* as the engine reprints it, and what it `requires` to be recreated first. It reads what is installed, not
|
|
78
78
|
* what uql wrote, which is exactly what a rollback restores.
|
|
79
79
|
*/
|
|
80
|
-
protected abstract triggersQuery(tableName: string):
|
|
80
|
+
protected abstract triggersQuery(tableName: string): QuerySql;
|
|
81
81
|
/** See {@link TableSchema.definition}: none, but where the engine keeps the statements themselves. */
|
|
82
82
|
protected getDefinition(_read: TableRowReader, _tableName: string): Promise<StoredDefinition[] | undefined>;
|
|
83
83
|
/**
|
|
84
84
|
* The key `sql` lists a row of for each column, in key order: its `column_name`, and the `constraint_name`
|
|
85
85
|
* where the engine names the key's constraint. Only a `DROP` needs that name, and only the reported one will do.
|
|
86
86
|
*/
|
|
87
|
-
protected readPrimaryKey(read: TableRowReader, sql:
|
|
87
|
+
protected readPrimaryKey(read: TableRowReader, sql: QuerySql): Promise<PrimaryKeySchema | undefined>;
|
|
88
88
|
/** The {@link ForeignKeyAction} a catalogue names, whatever its case, and `SET_NULL` as SQL Server spells it. */
|
|
89
89
|
protected normalizeReferentialAction(action: string): ForeignKeyAction | undefined;
|
|
90
90
|
/** Foreign keys read one row each, as {@link JoinedForeignKeyRow} lists them. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SqlExpression } from '../../schema/sqlExpression.js';
|
|
2
2
|
import { FOREIGN_KEY_ACTIONS } from '../../schema/types.js';
|
|
3
|
-
import {
|
|
3
|
+
import { sql } from '../../util/sql.js';
|
|
4
4
|
import { isOwnedName } from '../../util/sql.util.js';
|
|
5
5
|
import { withSqlQuerierForMigrations } from '../acquireQuerierForMigrations.js';
|
|
6
6
|
import { knownDefault } from '../ddl/defaultSql.js';
|
|
@@ -24,13 +24,13 @@ export class AbstractSqlSchemaIntrospector {
|
|
|
24
24
|
}
|
|
25
25
|
/** The schema every catalogue query filters on: the one that was asked for, bound, or the connection's default. */
|
|
26
26
|
get schemaExpr() {
|
|
27
|
-
return this.schema === undefined ? this.defaultSchemaExpr :
|
|
27
|
+
return this.schema === undefined ? this.defaultSchemaExpr : sql `${this.schema}`;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* How this engine names the connection's current schema (Postgres) or database (MySQL). Empty on
|
|
31
31
|
* an engine with no schemas, whose catalogue queries never reference one.
|
|
32
32
|
*/
|
|
33
|
-
defaultSchemaExpr =
|
|
33
|
+
defaultSchemaExpr = sql ``;
|
|
34
34
|
/**
|
|
35
35
|
* The database as a {@link SchemaAST}, or just the tables named. A name nothing matches is left out
|
|
36
36
|
* rather than raised: the point of naming them is to read a database other things are still
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { CheckSchema } from '../../schema/types.js';
|
|
2
|
-
import type { ForeignKeySchema, IndexSchema, PrimaryKeySchema,
|
|
2
|
+
import type { ForeignKeySchema, IndexSchema, PrimaryKeySchema, QuerySql } from '../../type/index.js';
|
|
3
3
|
import { AbstractSqlSchemaIntrospector, type ReadColumn, type TableRowReader } from './abstractSqlSchemaIntrospector.js';
|
|
4
4
|
/** SQL Server schema introspector: `INFORMATION_SCHEMA` has no view of indexes, which come from `sys.indexes`. */
|
|
5
5
|
export declare class MsSqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
6
|
-
protected readonly defaultSchemaExpr:
|
|
7
|
-
protected triggersQuery(tableName: string):
|
|
6
|
+
protected readonly defaultSchemaExpr: QuerySql;
|
|
7
|
+
protected triggersQuery(tableName: string): QuerySql;
|
|
8
8
|
protected getChecks(read: TableRowReader, tableName: string): Promise<CheckSchema[]>;
|
|
9
|
-
protected getTableNamesQuery():
|
|
10
|
-
protected tableExistsQuery(tableName: string):
|
|
9
|
+
protected getTableNamesQuery(): QuerySql;
|
|
10
|
+
protected tableExistsQuery(tableName: string): QuerySql;
|
|
11
11
|
/** From `sys` rather than `INFORMATION_SCHEMA`, which has no identity flag. */
|
|
12
12
|
protected getColumns(read: TableRowReader, tableName: string): Promise<ReadColumn[]>;
|
|
13
13
|
/** `is_primary_key` is excluded: the key is read separately, the way every other engine reads it. */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sql } from '../../util/sql.js';
|
|
2
2
|
import { AbstractSqlSchemaIntrospector, } from './abstractSqlSchemaIntrospector.js';
|
|
3
3
|
/** SQL Server schema introspector: `INFORMATION_SCHEMA` has no view of indexes, which come from `sys.indexes`. */
|
|
4
4
|
export class MsSqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
5
|
-
defaultSchemaExpr =
|
|
5
|
+
defaultSchemaExpr = sql `SCHEMA_NAME()`;
|
|
6
6
|
triggersQuery(tableName) {
|
|
7
|
-
return
|
|
7
|
+
return sql `
|
|
8
8
|
SELECT t.name AS name, m.definition AS definition
|
|
9
9
|
FROM sys.triggers t
|
|
10
10
|
JOIN sys.sql_modules m ON m.object_id = t.object_id
|
|
@@ -13,14 +13,14 @@ export class MsSqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
13
13
|
`;
|
|
14
14
|
}
|
|
15
15
|
async getChecks(read, tableName) {
|
|
16
|
-
return read(
|
|
16
|
+
return read(sql `
|
|
17
17
|
SELECT k.name AS name, k.definition AS expression
|
|
18
18
|
FROM sys.check_constraints k
|
|
19
19
|
WHERE OBJECT_SCHEMA_NAME(k.parent_object_id) = ${this.schemaExpr} AND OBJECT_NAME(k.parent_object_id) = ${tableName}
|
|
20
20
|
`);
|
|
21
21
|
}
|
|
22
22
|
getTableNamesQuery() {
|
|
23
|
-
return
|
|
23
|
+
return sql `
|
|
24
24
|
SELECT TABLE_NAME as table_name
|
|
25
25
|
FROM INFORMATION_SCHEMA.TABLES
|
|
26
26
|
WHERE TABLE_SCHEMA = ${this.schemaExpr}
|
|
@@ -29,14 +29,14 @@ export class MsSqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
29
29
|
`;
|
|
30
30
|
}
|
|
31
31
|
tableExistsQuery(tableName) {
|
|
32
|
-
return
|
|
32
|
+
return sql `
|
|
33
33
|
SELECT 1 FROM INFORMATION_SCHEMA.TABLES
|
|
34
34
|
WHERE TABLE_SCHEMA = ${this.schemaExpr} AND TABLE_NAME = ${tableName} AND TABLE_TYPE = 'BASE TABLE'
|
|
35
35
|
`;
|
|
36
36
|
}
|
|
37
37
|
/** From `sys` rather than `INFORMATION_SCHEMA`, which has no identity flag. */
|
|
38
38
|
async getColumns(read, tableName) {
|
|
39
|
-
const rows = await read(
|
|
39
|
+
const rows = await read(sql `
|
|
40
40
|
SELECT
|
|
41
41
|
c.name as column_name,
|
|
42
42
|
t.name as data_type,
|
|
@@ -74,7 +74,7 @@ export class MsSqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
74
74
|
}
|
|
75
75
|
/** `is_primary_key` is excluded: the key is read separately, the way every other engine reads it. */
|
|
76
76
|
async getIndexes(read, tableName) {
|
|
77
|
-
const rows = await read(
|
|
77
|
+
const rows = await read(sql `
|
|
78
78
|
SELECT
|
|
79
79
|
i.name as index_name,
|
|
80
80
|
i.is_unique as is_unique,
|
|
@@ -98,7 +98,7 @@ export class MsSqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
98
98
|
}));
|
|
99
99
|
}
|
|
100
100
|
async getForeignKeys(read, tableName) {
|
|
101
|
-
const rows = await read(
|
|
101
|
+
const rows = await read(sql `
|
|
102
102
|
SELECT
|
|
103
103
|
fk.name as constraint_name,
|
|
104
104
|
STRING_AGG(pc.name, ',') WITHIN GROUP (ORDER BY fkc.constraint_column_id) as columns,
|
|
@@ -120,7 +120,7 @@ export class MsSqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
120
120
|
return this.joinedForeignKeys(rows);
|
|
121
121
|
}
|
|
122
122
|
getPrimaryKey(read, tableName) {
|
|
123
|
-
return this.readPrimaryKey(read,
|
|
123
|
+
return this.readPrimaryKey(read, sql `
|
|
124
124
|
SELECT c.name as column_name, i.name as constraint_name
|
|
125
125
|
FROM sys.indexes i
|
|
126
126
|
JOIN sys.objects o ON o.object_id = i.object_id
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { IndexFacet } from '../../schema/indexDifferences.js';
|
|
2
2
|
import type { CheckSchema } from '../../schema/types.js';
|
|
3
|
-
import type { ForeignKeySchema, IndexSchema, PrimaryKeySchema,
|
|
3
|
+
import type { ForeignKeySchema, IndexSchema, PrimaryKeySchema, QuerySql } from '../../type/index.js';
|
|
4
4
|
import { AbstractSqlSchemaIntrospector, type ReadColumn, type TableRowReader } from './abstractSqlSchemaIntrospector.js';
|
|
5
5
|
/**
|
|
6
6
|
* MySQL/MariaDB schema introspector.
|
|
7
7
|
* Works with both MySQL and MariaDB as they share the same information_schema structure.
|
|
8
8
|
*/
|
|
9
9
|
export declare class MysqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
10
|
-
protected readonly defaultSchemaExpr:
|
|
11
|
-
protected triggersQuery(tableName: string):
|
|
10
|
+
protected readonly defaultSchemaExpr: QuerySql;
|
|
11
|
+
protected triggersQuery(tableName: string): QuerySql;
|
|
12
12
|
/**
|
|
13
13
|
* `CHECK_CONSTRAINTS` names no table on MySQL, where a check's name is unique in its schema, so the
|
|
14
14
|
* table comes from `TABLE_CONSTRAINTS`. It reports the clause escaped as a literal's body (`\'a\'`).
|
|
15
15
|
*/
|
|
16
16
|
protected getChecks(read: TableRowReader, tableName: string): Promise<CheckSchema[]>;
|
|
17
|
-
protected getTableNamesQuery():
|
|
18
|
-
protected tableExistsQuery(tableName: string):
|
|
17
|
+
protected getTableNamesQuery(): QuerySql;
|
|
18
|
+
protected tableExistsQuery(tableName: string): QuerySql;
|
|
19
19
|
protected getColumns(read: TableRowReader, tableName: string): Promise<ReadColumn[]>;
|
|
20
20
|
protected getIndexes(read: TableRowReader, tableName: string): Promise<IndexSchema[]>;
|
|
21
21
|
protected getForeignKeys(read: TableRowReader, tableName: string): Promise<ForeignKeySchema[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SqlExpression } from '../../schema/sqlExpression.js';
|
|
2
|
-
import {
|
|
2
|
+
import { sql } from '../../util/sql.js';
|
|
3
3
|
import { unescapeMysqlString } from '../../util/sqlLiteral.js';
|
|
4
4
|
import { AbstractSqlSchemaIntrospector, } from './abstractSqlSchemaIntrospector.js';
|
|
5
5
|
/**
|
|
@@ -8,9 +8,9 @@ import { AbstractSqlSchemaIntrospector, } from './abstractSqlSchemaIntrospector.
|
|
|
8
8
|
*/
|
|
9
9
|
export class MysqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
10
10
|
// A MySQL "schema" is a database, so the connection's own is what `DATABASE()` reports.
|
|
11
|
-
defaultSchemaExpr =
|
|
11
|
+
defaultSchemaExpr = sql `DATABASE()`;
|
|
12
12
|
triggersQuery(tableName) {
|
|
13
|
-
return
|
|
13
|
+
return sql `
|
|
14
14
|
SELECT TRIGGER_NAME AS name,
|
|
15
15
|
CONCAT('CREATE TRIGGER \`', TRIGGER_SCHEMA, '\`.\`', TRIGGER_NAME, '\` ', ACTION_TIMING, ' ', EVENT_MANIPULATION,
|
|
16
16
|
' ON \`', EVENT_OBJECT_SCHEMA, '\`.\`', EVENT_OBJECT_TABLE, '\` FOR EACH ROW ', ACTION_STATEMENT) AS definition
|
|
@@ -23,7 +23,7 @@ export class MysqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
23
23
|
* table comes from `TABLE_CONSTRAINTS`. It reports the clause escaped as a literal's body (`\'a\'`).
|
|
24
24
|
*/
|
|
25
25
|
async getChecks(read, tableName) {
|
|
26
|
-
const rows = await read(
|
|
26
|
+
const rows = await read(sql `
|
|
27
27
|
SELECT k.CONSTRAINT_NAME AS name, c.CHECK_CLAUSE AS expression
|
|
28
28
|
FROM information_schema.TABLE_CONSTRAINTS k
|
|
29
29
|
JOIN information_schema.CHECK_CONSTRAINTS c
|
|
@@ -33,7 +33,7 @@ export class MysqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
33
33
|
return rows.map(({ name, expression }) => ({ name, expression: unescapeMysqlString(expression) }));
|
|
34
34
|
}
|
|
35
35
|
getTableNamesQuery() {
|
|
36
|
-
return
|
|
36
|
+
return sql `
|
|
37
37
|
SELECT TABLE_NAME as table_name
|
|
38
38
|
FROM information_schema.TABLES
|
|
39
39
|
WHERE TABLE_SCHEMA = ${this.schemaExpr}
|
|
@@ -42,13 +42,13 @@ export class MysqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
42
42
|
`;
|
|
43
43
|
}
|
|
44
44
|
tableExistsQuery(tableName) {
|
|
45
|
-
return
|
|
45
|
+
return sql `
|
|
46
46
|
SELECT 1 FROM information_schema.TABLES
|
|
47
47
|
WHERE TABLE_SCHEMA = ${this.schemaExpr} AND TABLE_NAME = ${tableName} AND TABLE_TYPE = 'BASE TABLE'
|
|
48
48
|
`;
|
|
49
49
|
}
|
|
50
50
|
async getColumns(read, tableName) {
|
|
51
|
-
const rows = await read(
|
|
51
|
+
const rows = await read(sql `
|
|
52
52
|
SELECT
|
|
53
53
|
COLUMN_NAME as column_name,
|
|
54
54
|
DATA_TYPE as data_type,
|
|
@@ -83,7 +83,7 @@ export class MysqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
83
83
|
}));
|
|
84
84
|
}
|
|
85
85
|
async getIndexes(read, tableName) {
|
|
86
|
-
const rows = await read(
|
|
86
|
+
const rows = await read(sql `
|
|
87
87
|
SELECT
|
|
88
88
|
INDEX_NAME as index_name,
|
|
89
89
|
GROUP_CONCAT(COALESCE(COLUMN_NAME, '') ORDER BY SEQ_IN_INDEX) as columns,
|
|
@@ -107,7 +107,7 @@ export class MysqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
107
107
|
}));
|
|
108
108
|
}
|
|
109
109
|
async getForeignKeys(read, tableName) {
|
|
110
|
-
const rows = await read(
|
|
110
|
+
const rows = await read(sql `
|
|
111
111
|
SELECT
|
|
112
112
|
kcu.CONSTRAINT_NAME as constraint_name,
|
|
113
113
|
GROUP_CONCAT(kcu.COLUMN_NAME ORDER BY kcu.ORDINAL_POSITION) as columns,
|
|
@@ -129,7 +129,7 @@ export class MysqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
129
129
|
}
|
|
130
130
|
/** Unnamed: MySQL calls every key `PRIMARY`, and drops one by no name. */
|
|
131
131
|
getPrimaryKey(read, tableName) {
|
|
132
|
-
return this.readPrimaryKey(read,
|
|
132
|
+
return this.readPrimaryKey(read, sql `
|
|
133
133
|
SELECT COLUMN_NAME as column_name
|
|
134
134
|
FROM information_schema.KEY_COLUMN_USAGE
|
|
135
135
|
WHERE TABLE_SCHEMA = ${this.schemaExpr}
|
|
@@ -190,7 +190,7 @@ export class MariadbSchemaIntrospector extends MysqlSchemaIntrospector {
|
|
|
190
190
|
* JSON column's `json_valid()` is its type, read by {@link getColumns}, so it is left out.
|
|
191
191
|
*/
|
|
192
192
|
async getChecks(read, tableName) {
|
|
193
|
-
return read(
|
|
193
|
+
return read(sql `
|
|
194
194
|
SELECT CONSTRAINT_NAME AS name, CHECK_CLAUSE AS expression
|
|
195
195
|
FROM information_schema.CHECK_CONSTRAINTS
|
|
196
196
|
WHERE CONSTRAINT_SCHEMA = ${this.schemaExpr} AND TABLE_NAME = ${tableName}
|
|
@@ -215,7 +215,7 @@ export class MariadbSchemaIntrospector extends MysqlSchemaIntrospector {
|
|
|
215
215
|
const qualified = [this.schema, tableName]
|
|
216
216
|
.filter((name) => name !== undefined)
|
|
217
217
|
.map((name) => this.dialect.escapeId(name));
|
|
218
|
-
const [row] = await read(
|
|
218
|
+
const [row] = await read(sql.text(`SHOW CREATE TABLE ${qualified.join('.')}`));
|
|
219
219
|
const lines = row['Create Table'].split('\n');
|
|
220
220
|
return indexes.map((index) => {
|
|
221
221
|
if (index.type !== 'vector') {
|
|
@@ -228,7 +228,7 @@ export class MariadbSchemaIntrospector extends MysqlSchemaIntrospector {
|
|
|
228
228
|
}
|
|
229
229
|
async getColumns(read, tableName) {
|
|
230
230
|
const columns = await super.getColumns(read, tableName);
|
|
231
|
-
const checks = await read(
|
|
231
|
+
const checks = await read(sql `
|
|
232
232
|
SELECT CONSTRAINT_NAME as column_name
|
|
233
233
|
FROM information_schema.CHECK_CONSTRAINTS
|
|
234
234
|
WHERE CONSTRAINT_SCHEMA = ${this.schemaExpr}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import type { IndexFacet } from '../../schema/indexDifferences.js';
|
|
2
2
|
import { type CheckSchema } from '../../schema/types.js';
|
|
3
|
-
import type { ForeignKeySchema, IndexSchema, PrimaryKeySchema,
|
|
3
|
+
import type { ForeignKeySchema, IndexSchema, PrimaryKeySchema, QuerySql } from '../../type/index.js';
|
|
4
4
|
import { AbstractSqlSchemaIntrospector, type ReadColumn, type TableRowReader } from './abstractSqlSchemaIntrospector.js';
|
|
5
5
|
/**
|
|
6
6
|
* PostgreSQL schema introspector
|
|
7
7
|
*/
|
|
8
8
|
export declare class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
9
|
-
protected readonly defaultSchemaExpr:
|
|
9
|
+
protected readonly defaultSchemaExpr: QuerySql;
|
|
10
10
|
/**
|
|
11
11
|
* Expressions and predicates are read back too, for `generate:from-db`, but they are text the
|
|
12
12
|
* database reprints in its own words, so they are not comparable and are not claimed here.
|
|
13
13
|
*/
|
|
14
14
|
protected readonly indexFacets: ReadonlySet<IndexFacet>;
|
|
15
|
-
protected triggersQuery(tableName: string):
|
|
15
|
+
protected triggersQuery(tableName: string): QuerySql;
|
|
16
16
|
/** `pg_get_expr` answers NULL for a table dropped mid-read, where `pg_get_constraintdef` raises. */
|
|
17
17
|
protected getChecks(read: TableRowReader, tableName: string): Promise<CheckSchema[]>;
|
|
18
|
-
protected getTableNamesQuery():
|
|
19
|
-
protected tableExistsQuery(tableName: string):
|
|
18
|
+
protected getTableNamesQuery(): QuerySql;
|
|
19
|
+
protected tableExistsQuery(tableName: string): QuerySql;
|
|
20
20
|
/**
|
|
21
21
|
* The comment reads through `to_regclass` rather than a `::regclass` cast: a name resolves against
|
|
22
22
|
* the live catalogue while `information_schema` answers from this statement's snapshot, so a table
|
|
@@ -30,7 +30,7 @@ export declare class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrosp
|
|
|
30
30
|
*/
|
|
31
31
|
protected getColumns(read: TableRowReader, tableName: string): Promise<ReadColumn[]>;
|
|
32
32
|
/** Whether `information_schema.columns c` lists a column the table shows: every one, on Postgres. */
|
|
33
|
-
protected readonly visibleColumnSql:
|
|
33
|
+
protected readonly visibleColumnSql: QuerySql;
|
|
34
34
|
/**
|
|
35
35
|
* `attname` where the entry is a column, `pg_get_indexdef` for that one position where it is an
|
|
36
36
|
* expression. Neither alone will do: an expression entry has `attnum = 0`, so joining `pg_attribute`
|
|
@@ -44,11 +44,11 @@ export declare class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrosp
|
|
|
44
44
|
*/
|
|
45
45
|
protected getIndexes(read: TableRowReader, tableName: string): Promise<IndexSchema[]>;
|
|
46
46
|
/** Whether an entry sorts nulls first, which Postgres states on every entry. */
|
|
47
|
-
protected readonly nullsFirstSql:
|
|
47
|
+
protected readonly nullsFirstSql: QuerySql;
|
|
48
48
|
/** An index's access method, which is the type it declares. */
|
|
49
|
-
protected readonly indexMethodSql:
|
|
49
|
+
protected readonly indexMethodSql: QuerySql;
|
|
50
50
|
/** An entry's operator class, where it is not the default for its type. */
|
|
51
|
-
protected readonly opsClassSql:
|
|
51
|
+
protected readonly opsClassSql: QuerySql;
|
|
52
52
|
/** From `pg_constraint`, whose key arrays keep each column paired with the one it references. */
|
|
53
53
|
protected getForeignKeys(read: TableRowReader, tableName: string): Promise<ForeignKeySchema[]>;
|
|
54
54
|
protected getPrimaryKey(read: TableRowReader, tableName: string): Promise<PrimaryKeySchema | undefined>;
|
|
@@ -76,13 +76,13 @@ export declare class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrosp
|
|
|
76
76
|
export declare class CockroachSchemaIntrospector extends PostgresSchemaIntrospector {
|
|
77
77
|
protected readonly indexFacets: ReadonlySet<IndexFacet>;
|
|
78
78
|
/** Not `rowid`, the `NOT VISIBLE` key it gives a table declared without one, which no entity can name. */
|
|
79
|
-
protected readonly visibleColumnSql:
|
|
79
|
+
protected readonly visibleColumnSql: QuerySql;
|
|
80
80
|
/** None: it rejects a stated nulls order, so reading one back gives an index it would refuse to rebuild. */
|
|
81
|
-
protected readonly nullsFirstSql:
|
|
81
|
+
protected readonly nullsFirstSql: QuerySql;
|
|
82
82
|
/**
|
|
83
83
|
* Every index reports the access method `prefix` and no operator class, so a vector index is read off
|
|
84
84
|
* its definition, `USING cspann (vec vector_cosine_ops)`: its type, and its last key's class.
|
|
85
85
|
*/
|
|
86
|
-
protected readonly indexMethodSql:
|
|
87
|
-
protected readonly opsClassSql:
|
|
86
|
+
protected readonly indexMethodSql: QuerySql;
|
|
87
|
+
protected readonly opsClassSql: QuerySql;
|
|
88
88
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { INDEX_TYPES } from '../../schema/types.js';
|
|
2
2
|
import { isVectorIndexType } from '../../type/vector.js';
|
|
3
|
-
import {
|
|
3
|
+
import { sql } from '../../util/sql.js';
|
|
4
4
|
import { AbstractSqlSchemaIntrospector, } from './abstractSqlSchemaIntrospector.js';
|
|
5
5
|
/**
|
|
6
6
|
* PostgreSQL schema introspector
|
|
7
7
|
*/
|
|
8
8
|
export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
9
|
-
defaultSchemaExpr =
|
|
9
|
+
defaultSchemaExpr = sql `current_schema()`;
|
|
10
10
|
/**
|
|
11
11
|
* Expressions and predicates are read back too, for `generate:from-db`, but they are text the
|
|
12
12
|
* database reprints in its own words, so they are not comparable and are not claimed here.
|
|
@@ -20,7 +20,7 @@ export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
20
20
|
'distance',
|
|
21
21
|
]);
|
|
22
22
|
triggersQuery(tableName) {
|
|
23
|
-
return
|
|
23
|
+
return sql `
|
|
24
24
|
SELECT t.tgname AS name, pg_get_triggerdef(t.oid) AS definition, pg_get_functiondef(t.tgfoid) AS requires
|
|
25
25
|
FROM pg_trigger t
|
|
26
26
|
JOIN pg_class c ON c.oid = t.tgrelid
|
|
@@ -30,7 +30,7 @@ export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
30
30
|
}
|
|
31
31
|
/** `pg_get_expr` answers NULL for a table dropped mid-read, where `pg_get_constraintdef` raises. */
|
|
32
32
|
async getChecks(read, tableName) {
|
|
33
|
-
const rows = await read(
|
|
33
|
+
const rows = await read(sql `
|
|
34
34
|
SELECT con.conname AS name, pg_get_expr(con.conbin, con.conrelid) AS expression
|
|
35
35
|
FROM pg_constraint con
|
|
36
36
|
JOIN pg_class t ON t.oid = con.conrelid
|
|
@@ -40,7 +40,7 @@ export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
40
40
|
return rows.flatMap(({ name, expression }) => (expression === null ? [] : [{ name, expression }]));
|
|
41
41
|
}
|
|
42
42
|
getTableNamesQuery() {
|
|
43
|
-
return
|
|
43
|
+
return sql `
|
|
44
44
|
SELECT table_name
|
|
45
45
|
FROM information_schema.tables
|
|
46
46
|
WHERE table_schema = ${this.schemaExpr}
|
|
@@ -49,7 +49,7 @@ export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
49
49
|
`;
|
|
50
50
|
}
|
|
51
51
|
tableExistsQuery(tableName) {
|
|
52
|
-
return
|
|
52
|
+
return sql `
|
|
53
53
|
SELECT 1 FROM information_schema.tables
|
|
54
54
|
WHERE table_schema = ${this.schemaExpr} AND table_name = ${tableName} AND table_type = 'BASE TABLE'
|
|
55
55
|
`;
|
|
@@ -66,7 +66,7 @@ export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
66
66
|
* CockroachDB names that type `vector` where Postgres says `USER-DEFINED`.
|
|
67
67
|
*/
|
|
68
68
|
async getColumns(read, tableName) {
|
|
69
|
-
const rows = await read(
|
|
69
|
+
const rows = await read(sql `
|
|
70
70
|
SELECT
|
|
71
71
|
c.column_name,
|
|
72
72
|
c.data_type,
|
|
@@ -108,7 +108,7 @@ export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
108
108
|
}));
|
|
109
109
|
}
|
|
110
110
|
/** Whether `information_schema.columns c` lists a column the table shows: every one, on Postgres. */
|
|
111
|
-
visibleColumnSql =
|
|
111
|
+
visibleColumnSql = sql `TRUE`;
|
|
112
112
|
/**
|
|
113
113
|
* `attname` where the entry is a column, `pg_get_indexdef` for that one position where it is an
|
|
114
114
|
* expression. Neither alone will do: an expression entry has `attnum = 0`, so joining `pg_attribute`
|
|
@@ -121,7 +121,7 @@ export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
121
121
|
* uniqueness, and one over several as the unique `@Index` it is.
|
|
122
122
|
*/
|
|
123
123
|
async getIndexes(read, tableName) {
|
|
124
|
-
const rows = await read(
|
|
124
|
+
const rows = await read(sql `
|
|
125
125
|
SELECT
|
|
126
126
|
i.relname AS index_name,
|
|
127
127
|
ix.indisunique AS is_unique,
|
|
@@ -165,24 +165,24 @@ export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
/** Whether an entry sorts nulls first, which Postgres states on every entry. */
|
|
168
|
-
nullsFirstSql =
|
|
168
|
+
nullsFirstSql = sql `(ix.indoption[k.n - 1] & 2) <> 0`;
|
|
169
169
|
/** An index's access method, which is the type it declares. */
|
|
170
|
-
indexMethodSql =
|
|
170
|
+
indexMethodSql = sql `am.amname`;
|
|
171
171
|
/** An entry's operator class, where it is not the default for its type. */
|
|
172
|
-
opsClassSql =
|
|
172
|
+
opsClassSql = sql `CASE WHEN op.opcdefault THEN NULL ELSE op.opcname END`;
|
|
173
173
|
/** From `pg_constraint`, whose key arrays keep each column paired with the one it references. */
|
|
174
174
|
async getForeignKeys(read, tableName) {
|
|
175
|
-
const columnsOf = (keys, table) =>
|
|
175
|
+
const columnsOf = (keys, table) => sql `ARRAY_TO_JSON(ARRAY(
|
|
176
176
|
SELECT a.attname FROM UNNEST(${keys}) WITH ORDINALITY AS k(attnum, n)
|
|
177
177
|
JOIN pg_attribute a ON a.attrelid = ${table} AND a.attnum = k.attnum
|
|
178
178
|
ORDER BY k.n
|
|
179
179
|
))`;
|
|
180
|
-
const rows = await read(
|
|
180
|
+
const rows = await read(sql `
|
|
181
181
|
SELECT
|
|
182
182
|
con.conname AS constraint_name,
|
|
183
|
-
${columnsOf(
|
|
183
|
+
${columnsOf(sql `con.conkey`, sql `con.conrelid`)} AS columns,
|
|
184
184
|
ref.relname AS referenced_table,
|
|
185
|
-
${columnsOf(
|
|
185
|
+
${columnsOf(sql `con.confkey`, sql `con.confrelid`)} AS referenced_columns,
|
|
186
186
|
con.confdeltype AS delete_rule,
|
|
187
187
|
con.confupdtype AS update_rule
|
|
188
188
|
FROM pg_constraint con
|
|
@@ -203,7 +203,7 @@ export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
203
203
|
}));
|
|
204
204
|
}
|
|
205
205
|
getPrimaryKey(read, tableName) {
|
|
206
|
-
return this.readPrimaryKey(read,
|
|
206
|
+
return this.readPrimaryKey(read, sql `
|
|
207
207
|
SELECT kcu.column_name, tc.constraint_name
|
|
208
208
|
FROM information_schema.table_constraints tc
|
|
209
209
|
JOIN information_schema.key_column_usage kcu
|
|
@@ -336,13 +336,13 @@ export class CockroachSchemaIntrospector extends PostgresSchemaIntrospector {
|
|
|
336
336
|
'distance',
|
|
337
337
|
]);
|
|
338
338
|
/** Not `rowid`, the `NOT VISIBLE` key it gives a table declared without one, which no entity can name. */
|
|
339
|
-
visibleColumnSql =
|
|
339
|
+
visibleColumnSql = sql `c.is_hidden = 'NO'`;
|
|
340
340
|
/** None: it rejects a stated nulls order, so reading one back gives an index it would refuse to rebuild. */
|
|
341
|
-
nullsFirstSql =
|
|
341
|
+
nullsFirstSql = sql `NULL::BOOL`;
|
|
342
342
|
/**
|
|
343
343
|
* Every index reports the access method `prefix` and no operator class, so a vector index is read off
|
|
344
344
|
* its definition, `USING cspann (vec vector_cosine_ops)`: its type, and its last key's class.
|
|
345
345
|
*/
|
|
346
|
-
indexMethodSql =
|
|
347
|
-
opsClassSql =
|
|
346
|
+
indexMethodSql = sql `CASE WHEN pg_get_indexdef(ix.indexrelid) LIKE '% USING cspann %' THEN 'vector' ELSE am.amname END`;
|
|
347
|
+
opsClassSql = sql `CASE WHEN k.n = ix.indnkeyatts THEN substring(pg_get_indexdef(ix.indexrelid) from '(\\w+_ops)\\)') END`;
|
|
348
348
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IndexFacet } from '../../schema/indexDifferences.js';
|
|
2
2
|
import type { CheckSchema } from '../../schema/types.js';
|
|
3
|
-
import type { ForeignKeySchema, IndexSchema, PrimaryKeySchema,
|
|
3
|
+
import type { ForeignKeySchema, IndexSchema, PrimaryKeySchema, QuerySql, StoredDefinition } from '../../type/index.js';
|
|
4
4
|
import { AbstractSqlSchemaIntrospector, type ReadColumn, type TableRowReader } from './abstractSqlSchemaIntrospector.js';
|
|
5
5
|
/**
|
|
6
6
|
* SQLite schema introspector
|
|
@@ -8,10 +8,10 @@ import { AbstractSqlSchemaIntrospector, type ReadColumn, type TableRowReader } f
|
|
|
8
8
|
export declare class SqliteSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
9
9
|
/** Whether an index is libSQL's vector index, where the engine has one; elsewhere a declared one is built plain. */
|
|
10
10
|
protected readonly indexFacets: ReadonlySet<IndexFacet>;
|
|
11
|
-
protected triggersQuery(tableName: string):
|
|
11
|
+
protected triggersQuery(tableName: string): QuerySql;
|
|
12
12
|
/** User tables only: skips SQLite's own and libSQL's vector index tables (its metadata and `<index>_shadow`). */
|
|
13
|
-
protected getTableNamesQuery():
|
|
14
|
-
protected tableExistsQuery(tableName: string):
|
|
13
|
+
protected getTableNamesQuery(): QuerySql;
|
|
14
|
+
protected tableExistsQuery(tableName: string): QuerySql;
|
|
15
15
|
/**
|
|
16
16
|
* `table_xinfo`, not `table_info`: the latter omits generated columns entirely, so a table carrying
|
|
17
17
|
* one read back without it and every sync offered to add a column that was already there - which
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sql } from '../../util/sql.js';
|
|
2
2
|
import { AbstractSqlSchemaIntrospector, } from './abstractSqlSchemaIntrospector.js';
|
|
3
3
|
/**
|
|
4
4
|
* SQLite schema introspector
|
|
@@ -7,11 +7,11 @@ export class SqliteSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
7
7
|
/** Whether an index is libSQL's vector index, where the engine has one; elsewhere a declared one is built plain. */
|
|
8
8
|
indexFacets = new Set(this.dialect.hasVectorIndex() ? ['vector', 'distance'] : []);
|
|
9
9
|
triggersQuery(tableName) {
|
|
10
|
-
return
|
|
10
|
+
return sql `SELECT name, sql AS definition FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ${tableName}`;
|
|
11
11
|
}
|
|
12
12
|
/** User tables only: skips SQLite's own and libSQL's vector index tables (its metadata and `<index>_shadow`). */
|
|
13
13
|
getTableNamesQuery() {
|
|
14
|
-
return
|
|
14
|
+
return sql `
|
|
15
15
|
SELECT name AS table_name
|
|
16
16
|
FROM sqlite_master
|
|
17
17
|
WHERE type = 'table'
|
|
@@ -22,7 +22,7 @@ export class SqliteSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
22
22
|
`;
|
|
23
23
|
}
|
|
24
24
|
tableExistsQuery(tableName) {
|
|
25
|
-
return
|
|
25
|
+
return sql `SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ${tableName}`;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* `table_xinfo`, not `table_info`: the latter omits generated columns entirely, so a table carrying
|
|
@@ -96,7 +96,7 @@ export class SqliteSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
96
96
|
}
|
|
97
97
|
/** Every statement `sqlite_master` keeps for the table, its `CREATE TABLE` first. An automatic index has none. */
|
|
98
98
|
getDefinition(read, tableName) {
|
|
99
|
-
return read(
|
|
99
|
+
return read(sql `SELECT type AS kind, name, sql FROM sqlite_master WHERE tbl_name = ${tableName} AND sql IS NOT NULL ORDER BY type <> 'table'`);
|
|
100
100
|
}
|
|
101
101
|
/** libSQL's `libsql_vector_idx(col, 'metric=...')`, read back from the statement that created it. */
|
|
102
102
|
vectorIndex(name, sql) {
|
|
@@ -118,7 +118,7 @@ export class SqliteSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
118
118
|
}
|
|
119
119
|
/** A PRAGMA takes no parameters, so the name it reads is written into the statement, escaped. */
|
|
120
120
|
pragma(name, of) {
|
|
121
|
-
return
|
|
121
|
+
return sql.text(`PRAGMA ${name}(${this.dialect.escapeId(of)})`);
|
|
122
122
|
}
|
|
123
123
|
normalizeType(type) {
|
|
124
124
|
// Extract base type without length/precision
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { AbstractSqlDialect } from '../dialect/abstractSqlDialect.js';
|
|
2
|
-
import type { QuerierPool,
|
|
2
|
+
import type { QuerierPool, QuerySql, SqlQuerier } from '../type/index.js';
|
|
3
3
|
/** How long `up` and `down` wait for the lock another run holds, unless told otherwise. */
|
|
4
4
|
export declare const DEFAULT_LOCK_TIMEOUT: number;
|
|
5
5
|
/** The statements taking and releasing a named lock: `acquire` takes it without waiting, answering a row only when it did. */
|
|
6
6
|
type NamedLockSql = {
|
|
7
|
-
readonly acquire:
|
|
8
|
-
readonly release:
|
|
7
|
+
readonly acquire: QuerySql;
|
|
8
|
+
readonly release: QuerySql;
|
|
9
9
|
};
|
|
10
10
|
/** The statements of the lock named `name` on `dialect`'s engine, where it has one its sessions can hold. */
|
|
11
11
|
export declare function namedLockSql(dialect: AbstractSqlDialect, name: string): NamedLockSql | undefined;
|