uql-orm 0.21.0 → 0.23.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/README.md +5 -4
- package/dist/browser/uql-browser.min.js.map +3 -3
- package/dist/bunSql/bunSqlCockroachDialect.d.ts +2 -2
- package/dist/bunSql/bunSqlCockroachDialect.js +4 -10
- package/dist/bunSql/bunSqlPostgresDialect.d.ts +2 -2
- package/dist/bunSql/bunSqlPostgresDialect.js +4 -10
- package/dist/cockroachdb/cockroachDialect.d.ts +20 -4
- package/dist/cockroachdb/cockroachDialect.js +33 -18
- package/dist/d1/d1Querier.d.ts +4 -3
- package/dist/d1/d1Querier.js +0 -3
- package/dist/d1/d1SqliteDialect.d.ts +7 -0
- package/dist/d1/d1SqliteDialect.js +9 -0
- package/dist/dialect/abstractDialect.d.ts +8 -3
- package/dist/dialect/abstractDialect.js +9 -4
- package/dist/dialect/abstractSqlDialect.d.ts +49 -8
- package/dist/dialect/abstractSqlDialect.js +95 -47
- package/dist/dialect/index.d.ts +1 -0
- package/dist/dialect/index.js +1 -0
- package/dist/dialect/indexSqlDialect.d.ts +57 -0
- package/dist/dialect/indexSqlDialect.js +101 -0
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +26 -1
- package/dist/dialect/mysqlLikeSqlDialect.js +57 -1
- package/dist/dialect/pgLikeSqlDialect.d.ts +37 -22
- package/dist/dialect/pgLikeSqlDialect.js +97 -68
- package/dist/dialect/vectorCast.d.ts +21 -0
- package/dist/dialect/vectorCast.js +28 -0
- package/dist/dialect/vectorSqlDialect.d.ts +10 -3
- package/dist/dialect/vectorSqlDialect.js +19 -8
- package/dist/entity/decorator/bag.d.ts +35 -0
- package/dist/entity/decorator/bag.js +54 -0
- package/dist/entity/decorator/entity.d.ts +28 -2
- package/dist/entity/decorator/entity.js +40 -2
- package/dist/entity/decorator/members.d.ts +51 -0
- package/dist/entity/decorator/members.js +51 -0
- package/dist/entity/index.d.ts +3 -1
- package/dist/entity/index.js +3 -1
- package/dist/entity/metadata/definition.d.ts +23 -8
- package/dist/entity/metadata/definition.js +56 -100
- package/dist/http/contract.js +1 -2
- package/dist/http/handler.js +5 -26
- package/dist/http/query.js +1 -1
- package/dist/libsql/libsqlDialect.d.ts +12 -2
- package/dist/libsql/libsqlDialect.js +14 -2
- package/dist/libsql/libsqlQuerier.d.ts +9 -22
- package/dist/libsql/libsqlQuerier.js +9 -85
- package/dist/libsql/libsqlQuerierPool.d.ts +10 -8
- package/dist/libsql/libsqlQuerierPool.js +17 -15
- package/dist/maria/mariaDialect.d.ts +26 -4
- package/dist/maria/mariaDialect.js +54 -15
- package/dist/migrate/acquireQuerierForMigrations.d.ts +13 -1
- package/dist/migrate/acquireQuerierForMigrations.js +28 -0
- package/dist/migrate/builder/migrationBuilder.d.ts +9 -29
- package/dist/migrate/builder/migrationBuilder.js +58 -76
- package/dist/migrate/builder/splitSqlStatements.d.ts +0 -2
- package/dist/migrate/builder/splitSqlStatements.js +0 -2
- package/dist/migrate/builder/tableBuilder.d.ts +12 -2
- package/dist/migrate/builder/tableBuilder.js +71 -119
- package/dist/migrate/builder/types.d.ts +30 -41
- package/dist/migrate/cli-config.js +24 -8
- package/dist/migrate/cli.d.ts +3 -2
- package/dist/migrate/cli.js +26 -49
- package/dist/migrate/codegen/entityCodeGenerator.d.ts +0 -4
- package/dist/migrate/codegen/entityCodeGenerator.js +8 -67
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +10 -0
- package/dist/migrate/codegen/fieldOptionsSource.js +55 -0
- package/dist/migrate/codegen/index.d.ts +0 -3
- package/dist/migrate/codegen/index.js +0 -6
- package/dist/migrate/drift/driftDetector.d.ts +10 -1
- package/dist/migrate/drift/driftDetector.js +22 -5
- package/dist/migrate/generator/indexNodeToSchema.d.ts +9 -0
- package/dist/migrate/generator/indexNodeToSchema.js +14 -0
- package/dist/migrate/generator/mongoCommand.d.ts +57 -0
- package/dist/migrate/generator/mongoCommand.js +26 -0
- package/dist/migrate/generator/mongoSchemaGenerator.d.ts +9 -20
- package/dist/migrate/generator/mongoSchemaGenerator.js +40 -82
- package/dist/migrate/index.d.ts +0 -1
- package/dist/migrate/index.js +0 -1
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +30 -11
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +61 -57
- package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -1
- package/dist/migrate/introspection/baseSqlIntrospector.js +3 -12
- package/dist/migrate/introspection/mongoIntrospector.js +9 -15
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +5 -8
- package/dist/migrate/introspection/mysqlIntrospector.js +4 -10
- package/dist/migrate/introspection/postgresIntrospector.d.ts +5 -8
- package/dist/migrate/introspection/postgresIntrospector.js +4 -10
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +6 -5
- package/dist/migrate/introspection/sqliteIntrospector.js +26 -18
- package/dist/migrate/migrator.d.ts +23 -3
- package/dist/migrate/migrator.js +101 -150
- package/dist/migrate/schemaGenerator.d.ts +26 -37
- package/dist/migrate/schemaGenerator.js +69 -174
- package/dist/migrate/schemaGeneratorAsync.d.ts +2 -2
- package/dist/migrate/schemaGeneratorAsync.js +3 -3
- package/dist/migrate/storage/databaseStorage.d.ts +2 -0
- package/dist/migrate/storage/databaseStorage.js +12 -27
- package/dist/mongo/mongoDialect.d.ts +2 -0
- package/dist/mongo/mongoDialect.js +14 -3
- package/dist/mongo/mongodbQuerier.js +171 -229
- package/dist/mysql/mysqlDialect.d.ts +8 -0
- package/dist/mysql/mysqlDialect.js +13 -0
- package/dist/nestjs/uqlContextInterceptor.js +58 -22
- package/dist/nestjs/uqlModule.d.ts +2 -11
- package/dist/nestjs/uqlModule.js +93 -44
- package/dist/postgres/postgresDialect.js +2 -2
- package/dist/querier/abstractQuerier.d.ts +28 -0
- package/dist/querier/abstractQuerier.js +47 -22
- package/dist/querier/abstractQuerierPool.d.ts +3 -0
- package/dist/querier/abstractQuerierPool.js +5 -3
- package/dist/querier/abstractSqlQuerier.d.ts +1 -3
- package/dist/querier/abstractSqlQuerier.js +48 -96
- package/dist/querier/index.d.ts +3 -1
- package/dist/querier/index.js +3 -1
- package/dist/querier/querierContext.browser.d.ts +12 -0
- package/dist/querier/querierContext.browser.js +18 -0
- package/dist/querier/querierContext.d.ts +22 -0
- package/dist/querier/querierContext.js +42 -0
- package/dist/querier/queryError.d.ts +22 -0
- package/dist/querier/queryError.js +20 -0
- package/dist/querier/transactional.d.ts +26 -0
- package/dist/querier/transactional.js +43 -0
- package/dist/schema/canonicalType.d.ts +14 -2
- package/dist/schema/canonicalType.js +41 -31
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/schemaASTBuilder.d.ts +9 -2
- package/dist/schema/schemaASTBuilder.js +58 -49
- package/dist/schema/types.d.ts +10 -58
- package/dist/sqlite/abstractSqliteQuerier.d.ts +46 -0
- package/dist/sqlite/abstractSqliteQuerier.js +44 -0
- package/dist/sqlite/bunSqliteAdapter.bun.d.ts +26 -0
- package/dist/sqlite/bunSqliteAdapter.bun.js +25 -0
- package/dist/sqlite/hranaQuerier.d.ts +54 -0
- package/dist/sqlite/hranaQuerier.js +68 -0
- package/dist/sqlite/hranaQuerierPool.d.ts +21 -0
- package/dist/sqlite/hranaQuerierPool.js +25 -0
- package/dist/sqlite/index.d.ts +3 -1
- package/dist/sqlite/index.js +3 -1
- package/dist/sqlite/localSqliteQuerierPool.d.ts +31 -0
- package/dist/sqlite/localSqliteQuerierPool.js +34 -0
- package/dist/sqlite/nodeSqliteAdapter.d.ts +35 -0
- package/dist/sqlite/nodeSqliteAdapter.js +28 -0
- package/dist/sqlite/nodeSqliteQuerierPool.d.ts +28 -0
- package/dist/sqlite/nodeSqliteQuerierPool.js +29 -0
- package/dist/sqlite/sqliteDialect.d.ts +18 -5
- package/dist/sqlite/sqliteDialect.js +23 -36
- package/dist/sqlite/sqliteQuerier.d.ts +16 -9
- package/dist/sqlite/sqliteQuerier.js +4 -27
- package/dist/sqlite/sqliteQuerierPool.d.ts +11 -14
- package/dist/sqlite/sqliteQuerierPool.js +16 -24
- package/dist/turso/index.d.ts +3 -0
- package/dist/turso/index.js +3 -0
- package/dist/turso/local.d.ts +3 -0
- package/dist/turso/local.js +3 -0
- package/dist/turso/tursoDialect.d.ts +15 -0
- package/dist/turso/tursoDialect.js +18 -0
- package/dist/turso/tursoLocalQuerier.d.ts +25 -0
- package/dist/turso/tursoLocalQuerier.js +20 -0
- package/dist/turso/tursoLocalQuerierPool.d.ts +32 -0
- package/dist/turso/tursoLocalQuerierPool.js +39 -0
- package/dist/turso/tursoQuerier.d.ts +10 -0
- package/dist/turso/tursoQuerier.js +10 -0
- package/dist/turso/tursoQuerierPool.d.ts +39 -0
- package/dist/turso/tursoQuerierPool.js +38 -0
- package/dist/type/config.d.ts +0 -6
- package/dist/type/dialect.d.ts +12 -4
- package/dist/type/dialect.js +7 -1
- package/dist/type/entity.d.ts +154 -26
- package/dist/type/migration.d.ts +32 -23
- package/dist/type/querier.d.ts +6 -0
- package/dist/type/vector.d.ts +5 -2
- package/dist/util/hook.util.js +1 -1
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +1 -0
- package/dist/util/indexColumn.util.d.ts +6 -0
- package/dist/util/indexColumn.util.js +26 -0
- package/package.json +21 -16
- package/dist/entity/decorator/field.d.ts +0 -2
- package/dist/entity/decorator/field.js +0 -7
- package/dist/entity/decorator/filter.d.ts +0 -7
- package/dist/entity/decorator/filter.js +0 -11
- package/dist/entity/decorator/hook.d.ts +0 -7
- package/dist/entity/decorator/hook.js +0 -14
- package/dist/entity/decorator/id.d.ts +0 -2
- package/dist/entity/decorator/id.js +0 -7
- package/dist/entity/decorator/index-decorator.d.ts +0 -29
- package/dist/entity/decorator/index-decorator.js +0 -26
- package/dist/entity/decorator/index.d.ts +0 -8
- package/dist/entity/decorator/index.js +0 -8
- package/dist/entity/decorator/relation.d.ts +0 -8
- package/dist/entity/decorator/relation.js +0 -19
- package/dist/migrate/codegen/entityMerger.d.ts +0 -114
- package/dist/migrate/codegen/entityMerger.js +0 -293
- package/dist/migrate/codegen/migrationCodeGenerator.d.ts +0 -61
- package/dist/migrate/codegen/migrationCodeGenerator.js +0 -355
- package/dist/migrate/codegen/smartRelationDetector.d.ts +0 -47
- package/dist/migrate/codegen/smartRelationDetector.js +0 -134
- package/dist/migrate/generator/index.d.ts +0 -2
- package/dist/migrate/generator/index.js +0 -2
- package/dist/migrate/sync/index.d.ts +0 -6
- package/dist/migrate/sync/index.js +0 -6
- package/dist/migrate/sync/schemaSync.d.ts +0 -131
- package/dist/migrate/sync/schemaSync.js +0 -259
- package/dist/querier/decorator/index.d.ts +0 -4
- package/dist/querier/decorator/index.js +0 -4
- package/dist/querier/decorator/injectQuerier.d.ts +0 -3
- package/dist/querier/decorator/injectQuerier.js +0 -33
- package/dist/querier/decorator/log.d.ts +0 -32
- package/dist/querier/decorator/log.js +0 -52
- package/dist/querier/decorator/serialized.d.ts +0 -6
- package/dist/querier/decorator/serialized.js +0 -13
- package/dist/querier/decorator/transactional.d.ts +0 -6
- package/dist/querier/decorator/transactional.js +0 -48
- package/dist/sqlite/betterSqlite3Dialect.d.ts +0 -9
- package/dist/sqlite/betterSqlite3Dialect.js +0 -9
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import type { Database } from 'better-sqlite3';
|
|
2
1
|
import type { ExtraOptions } from '../type/index.js';
|
|
3
|
-
import {
|
|
2
|
+
import { PreparedSqliteQuerier, type SqlitePreparedStatement } from './abstractSqliteQuerier.js';
|
|
4
3
|
import type { SqliteDialect } from './sqliteDialect.js';
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Structural subset of a synchronous better-sqlite3-compatible driver, declared locally so this
|
|
6
|
+
* querier carries no vendor type. A real `better-sqlite3` `Database` satisfies it directly;
|
|
7
|
+
* `bun:sqlite` is adapted to it by {@link Sqlite3QuerierPool}.
|
|
8
|
+
*/
|
|
9
|
+
export type SqliteDatabase = {
|
|
10
|
+
prepare(sql: string): SqlitePreparedStatement;
|
|
11
|
+
/** Installs a loadable extension (`sqlite-vec`, ...) into this connection. */
|
|
12
|
+
loadExtension(path: string): void;
|
|
13
|
+
close(): unknown;
|
|
14
|
+
};
|
|
15
|
+
export declare class SqliteQuerier extends PreparedSqliteQuerier {
|
|
16
|
+
readonly db: SqliteDatabase;
|
|
7
17
|
readonly extra?: ExtraOptions | undefined;
|
|
8
|
-
constructor(db:
|
|
9
|
-
|
|
10
|
-
internalStream<T>(query: string, values?: unknown[]): AsyncGenerator<Awaited<T>, void, unknown>;
|
|
11
|
-
internalRun(query: string, values?: unknown[]): Promise<import("../type/query.js").QueryUpdateResult>;
|
|
12
|
-
internalRelease(): Promise<void>;
|
|
18
|
+
constructor(db: SqliteDatabase, dialect: SqliteDialect, extra?: ExtraOptions | undefined);
|
|
19
|
+
protected prepare(query: string): SqlitePreparedStatement;
|
|
13
20
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export class SqliteQuerier extends AbstractSqliteQuerier {
|
|
1
|
+
import { PreparedSqliteQuerier } from './abstractSqliteQuerier.js';
|
|
2
|
+
export class SqliteQuerier extends PreparedSqliteQuerier {
|
|
4
3
|
db;
|
|
5
4
|
extra;
|
|
6
5
|
constructor(db, dialect, extra) {
|
|
@@ -8,29 +7,7 @@ export class SqliteQuerier extends AbstractSqliteQuerier {
|
|
|
8
7
|
this.db = db;
|
|
9
8
|
this.extra = extra;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
return this.db.prepare(query)
|
|
13
|
-
}
|
|
14
|
-
async *internalStream(query, values) {
|
|
15
|
-
for (const row of this.db.prepare(query).iterate(values || [])) {
|
|
16
|
-
yield row;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
async internalRun(query, values) {
|
|
20
|
-
const stmt = this.db.prepare(query);
|
|
21
|
-
// `reader` is true for any statement with a RETURNING clause; `.run()` silently discards
|
|
22
|
-
// returned rows, so those statements must go through `.all()` instead.
|
|
23
|
-
if (stmt.reader) {
|
|
24
|
-
const rows = stmt.all(values || []);
|
|
25
|
-
return this.buildUpdateResult({ rows });
|
|
26
|
-
}
|
|
27
|
-
const { changes, lastInsertRowid } = stmt.run(values || []);
|
|
28
|
-
return this.buildUpdateResult({ changes, id: lastInsertRowid });
|
|
29
|
-
}
|
|
30
|
-
async internalRelease() {
|
|
31
|
-
if (this.hasOpenTransaction) {
|
|
32
|
-
throwPendingTransaction();
|
|
33
|
-
}
|
|
34
|
-
// no-op
|
|
10
|
+
prepare(query) {
|
|
11
|
+
return this.db.prepare(query);
|
|
35
12
|
}
|
|
36
13
|
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import type { Options } from 'better-sqlite3';
|
|
2
|
-
import { AbstractSqlQuerierPool } from '../querier/index.js';
|
|
3
2
|
import type { ExtraOptions } from '../type/index.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import { AbstractLocalSqliteQuerierPool, type LocalSqlitePoolOptions } from './localSqliteQuerierPool.js';
|
|
4
|
+
import type { SqliteDatabase } from './sqliteQuerier.js';
|
|
5
|
+
/** Driver options, plus the loadable extensions to install on the connection. */
|
|
6
|
+
export type Sqlite3PoolOptions = Options & LocalSqlitePoolOptions;
|
|
7
|
+
/**
|
|
8
|
+
* Pool for `better-sqlite3`, or `bun:sqlite` when running under Bun - the same file, through whichever
|
|
9
|
+
* driver the runtime provides.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Sqlite3QuerierPool extends AbstractLocalSqliteQuerierPool<Sqlite3PoolOptions> {
|
|
7
12
|
readonly filename: string | Buffer;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
constructor(filename?: string | Buffer, opts?: Options | undefined, extra?: ExtraOptions);
|
|
11
|
-
/**
|
|
12
|
-
* The database handle is shared (single connection), but each acquisition gets its own querier
|
|
13
|
-
* so transaction state stays per unit of work.
|
|
14
|
-
*/
|
|
15
|
-
getQuerier(): Promise<SqliteQuerier>;
|
|
16
|
-
private openDb;
|
|
17
|
-
end(): Promise<void>;
|
|
13
|
+
constructor(filename?: string | Buffer, opts?: Sqlite3PoolOptions, extra?: ExtraOptions);
|
|
14
|
+
protected createDb(): Promise<SqliteDatabase>;
|
|
18
15
|
}
|
|
@@ -1,37 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { AbstractLocalSqliteQuerierPool } from './localSqliteQuerierPool.js';
|
|
2
|
+
/**
|
|
3
|
+
* Pool for `better-sqlite3`, or `bun:sqlite` when running under Bun - the same file, through whichever
|
|
4
|
+
* driver the runtime provides.
|
|
5
|
+
*/
|
|
6
|
+
export class Sqlite3QuerierPool extends AbstractLocalSqliteQuerierPool {
|
|
5
7
|
filename;
|
|
6
|
-
opts;
|
|
7
|
-
db;
|
|
8
8
|
constructor(filename = ':memory:', opts, extra) {
|
|
9
|
-
super(
|
|
9
|
+
super(opts, extra);
|
|
10
10
|
this.filename = filename;
|
|
11
|
-
this.opts = opts;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.db ??= await this.openDb();
|
|
19
|
-
return new SqliteQuerier(this.db, this.dialect, this.extra);
|
|
20
|
-
}
|
|
21
|
-
async openDb() {
|
|
12
|
+
async createDb() {
|
|
13
|
+
// `bun:sqlite` rejects option keys it does not know, and rejects an options object carrying no
|
|
14
|
+
// open flags, so `extensions` is stripped out and what remains of it collapses back to nothing.
|
|
15
|
+
const { extensions, ...driverOpts } = this.opts ?? {};
|
|
16
|
+
const opts = Object.keys(driverOpts).length > 0 ? driverOpts : undefined;
|
|
22
17
|
if (typeof Bun !== 'undefined') {
|
|
23
18
|
const { Database: BunDatabase } = await import('bun:sqlite');
|
|
24
|
-
const
|
|
19
|
+
const { adaptBunSqlite } = await import('./bunSqliteAdapter.bun.js');
|
|
20
|
+
const bunDb = new BunDatabase(this.filename, opts);
|
|
25
21
|
bunDb.run('PRAGMA journal_mode = WAL');
|
|
26
|
-
return bunDb;
|
|
22
|
+
return adaptBunSqlite(bunDb);
|
|
27
23
|
}
|
|
28
24
|
const { default: BetterSqlite3 } = await import('better-sqlite3');
|
|
29
|
-
const db = new BetterSqlite3(this.filename,
|
|
25
|
+
const db = new BetterSqlite3(this.filename, opts);
|
|
30
26
|
db.pragma('journal_mode = WAL');
|
|
31
27
|
return db;
|
|
32
28
|
}
|
|
33
|
-
async end() {
|
|
34
|
-
await this.db?.close();
|
|
35
|
-
this.db = undefined;
|
|
36
|
-
}
|
|
37
29
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LibsqlDialect } from '../libsql/libsqlDialect.js';
|
|
2
|
+
import type { VectorDistance } from '../type/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* SQLite Dialect specialization for Turso Database.
|
|
5
|
+
*
|
|
6
|
+
* @remarks Shared by `TursoQuerierPool` (remote, `@tursodatabase/serverless`) and
|
|
7
|
+
* `TursoLocalQuerierPool` (embedded, `@tursodatabase/database`). Built on `LibsqlDialect` because
|
|
8
|
+
* Turso is that engine's successor and keeps its SQL surface, vector functions included. Imports
|
|
9
|
+
* nothing vendor-specific, so the embedded entry point cannot pull native code into an edge bundle
|
|
10
|
+
* through it.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TursoDialect extends LibsqlDialect {
|
|
13
|
+
/** The Rust engine adds a dot-product distance to libSQL's cosine and L2. */
|
|
14
|
+
protected readonly vectorDistanceFns: ReadonlyMap<VectorDistance, string>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LibsqlDialect } from '../libsql/libsqlDialect.js';
|
|
2
|
+
/**
|
|
3
|
+
* SQLite Dialect specialization for Turso Database.
|
|
4
|
+
*
|
|
5
|
+
* @remarks Shared by `TursoQuerierPool` (remote, `@tursodatabase/serverless`) and
|
|
6
|
+
* `TursoLocalQuerierPool` (embedded, `@tursodatabase/database`). Built on `LibsqlDialect` because
|
|
7
|
+
* Turso is that engine's successor and keeps its SQL surface, vector functions included. Imports
|
|
8
|
+
* nothing vendor-specific, so the embedded entry point cannot pull native code into an edge bundle
|
|
9
|
+
* through it.
|
|
10
|
+
*/
|
|
11
|
+
export class TursoDialect extends LibsqlDialect {
|
|
12
|
+
/** The Rust engine adds a dot-product distance to libSQL's cosine and L2. */
|
|
13
|
+
vectorDistanceFns = new Map([
|
|
14
|
+
['cosine', 'vector_distance_cos'],
|
|
15
|
+
['l2', 'vector_distance_l2'],
|
|
16
|
+
['inner', 'vector_distance_dot'],
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PreparedSqliteQuerier, type SqlitePreparedStatement } from '../sqlite/abstractSqliteQuerier.js';
|
|
2
|
+
import type { SqliteDialect } from '../sqlite/sqliteDialect.js';
|
|
3
|
+
import type { ExtraOptions } from '../type/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Structural subset of the `@tursodatabase/database` API actually used here, declared locally so
|
|
6
|
+
* this package does not couple its published types to a pre-1.0 dependency.
|
|
7
|
+
*/
|
|
8
|
+
export type TursoDatabase = {
|
|
9
|
+
prepare(sql: string): Promise<SqlitePreparedStatement>;
|
|
10
|
+
pragma(source: string, options?: unknown): Promise<unknown[]>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Querier for the embedded Turso engine.
|
|
15
|
+
*
|
|
16
|
+
* @remarks The engine exposes better-sqlite3 semantics (`reader`, `{changes, lastInsertRowid}`,
|
|
17
|
+
* array-bound values) over an async API, so all it supplies is the awaited `prepare`.
|
|
18
|
+
* `BEGIN`/`COMMIT` work as plain statements, leaving transactions to the base class.
|
|
19
|
+
*/
|
|
20
|
+
export declare class TursoLocalQuerier extends PreparedSqliteQuerier {
|
|
21
|
+
readonly db: TursoDatabase;
|
|
22
|
+
readonly extra?: ExtraOptions | undefined;
|
|
23
|
+
constructor(db: TursoDatabase, dialect: SqliteDialect, extra?: ExtraOptions | undefined);
|
|
24
|
+
protected prepare(query: string): Promise<SqlitePreparedStatement>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PreparedSqliteQuerier } from '../sqlite/abstractSqliteQuerier.js';
|
|
2
|
+
/**
|
|
3
|
+
* Querier for the embedded Turso engine.
|
|
4
|
+
*
|
|
5
|
+
* @remarks The engine exposes better-sqlite3 semantics (`reader`, `{changes, lastInsertRowid}`,
|
|
6
|
+
* array-bound values) over an async API, so all it supplies is the awaited `prepare`.
|
|
7
|
+
* `BEGIN`/`COMMIT` work as plain statements, leaving transactions to the base class.
|
|
8
|
+
*/
|
|
9
|
+
export class TursoLocalQuerier extends PreparedSqliteQuerier {
|
|
10
|
+
db;
|
|
11
|
+
extra;
|
|
12
|
+
constructor(db, dialect, extra) {
|
|
13
|
+
super(dialect, extra);
|
|
14
|
+
this.db = db;
|
|
15
|
+
this.extra = extra;
|
|
16
|
+
}
|
|
17
|
+
prepare(query) {
|
|
18
|
+
return this.db.prepare(query);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AbstractSqlQuerierPool } from '../querier/index.js';
|
|
2
|
+
import type { ExtraOptions } from '../type/index.js';
|
|
3
|
+
import { TursoDialect } from './tursoDialect.js';
|
|
4
|
+
import { TursoLocalQuerier } from './tursoLocalQuerier.js';
|
|
5
|
+
/** Subset of `DatabaseOpts` from `@tursodatabase/database`, declared locally to avoid the coupling. */
|
|
6
|
+
export type TursoLocalOptions = {
|
|
7
|
+
readonly?: boolean;
|
|
8
|
+
fileMustExist?: boolean;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
defaultQueryTimeout?: number;
|
|
11
|
+
tracing?: 'info' | 'debug' | 'trace';
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Pool for the embedded Turso engine (`@tursodatabase/database`), the Rust rewrite of SQLite.
|
|
15
|
+
*
|
|
16
|
+
* @remarks Kept on the `uql-orm/turso/local` entry point rather than `uql-orm/turso`, because this
|
|
17
|
+
* package ships native binaries that do not resolve on edge runtimes. Separating them guarantees a
|
|
18
|
+
* bundle targeting Workers never reaches the native import.
|
|
19
|
+
*/
|
|
20
|
+
export declare class TursoLocalQuerierPool extends AbstractSqlQuerierPool<TursoLocalQuerier, TursoDialect> {
|
|
21
|
+
readonly filename: string;
|
|
22
|
+
readonly opts?: TursoLocalOptions | undefined;
|
|
23
|
+
private db?;
|
|
24
|
+
constructor(filename?: string, opts?: TursoLocalOptions | undefined, extra?: ExtraOptions);
|
|
25
|
+
/**
|
|
26
|
+
* The database handle is shared (single connection), but each acquisition gets its own querier
|
|
27
|
+
* so transaction state stays per unit of work.
|
|
28
|
+
*/
|
|
29
|
+
getQuerier(): Promise<TursoLocalQuerier>;
|
|
30
|
+
private openDb;
|
|
31
|
+
end(): Promise<void>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AbstractSqlQuerierPool } from '../querier/index.js';
|
|
2
|
+
import { TursoDialect } from './tursoDialect.js';
|
|
3
|
+
import { TursoLocalQuerier } from './tursoLocalQuerier.js';
|
|
4
|
+
/**
|
|
5
|
+
* Pool for the embedded Turso engine (`@tursodatabase/database`), the Rust rewrite of SQLite.
|
|
6
|
+
*
|
|
7
|
+
* @remarks Kept on the `uql-orm/turso/local` entry point rather than `uql-orm/turso`, because this
|
|
8
|
+
* package ships native binaries that do not resolve on edge runtimes. Separating them guarantees a
|
|
9
|
+
* bundle targeting Workers never reaches the native import.
|
|
10
|
+
*/
|
|
11
|
+
export class TursoLocalQuerierPool extends AbstractSqlQuerierPool {
|
|
12
|
+
filename;
|
|
13
|
+
opts;
|
|
14
|
+
db;
|
|
15
|
+
constructor(filename = ':memory:', opts, extra) {
|
|
16
|
+
super(new TursoDialect({ namingStrategy: extra?.namingStrategy }), extra);
|
|
17
|
+
this.filename = filename;
|
|
18
|
+
this.opts = opts;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The database handle is shared (single connection), but each acquisition gets its own querier
|
|
22
|
+
* so transaction state stays per unit of work.
|
|
23
|
+
*/
|
|
24
|
+
async getQuerier() {
|
|
25
|
+
this.db ??= await this.openDb();
|
|
26
|
+
return new TursoLocalQuerier(this.db, this.dialect, this.extra);
|
|
27
|
+
}
|
|
28
|
+
async openDb() {
|
|
29
|
+
const { connect } = await import('@tursodatabase/database');
|
|
30
|
+
// Annotated rather than cast, so the structural contract is checked against the real driver.
|
|
31
|
+
const db = await connect(this.filename, this.opts);
|
|
32
|
+
await db.pragma('journal_mode = WAL');
|
|
33
|
+
return db;
|
|
34
|
+
}
|
|
35
|
+
async end() {
|
|
36
|
+
await this.db?.close();
|
|
37
|
+
this.db = undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HranaQuerier } from '../sqlite/hranaQuerier.js';
|
|
2
|
+
/**
|
|
3
|
+
* Querier for remote Turso Cloud databases over `@tursodatabase/serverless/compat`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks Empty subclass by design: that compat client speaks the Hrana protocol, so the whole
|
|
6
|
+
* implementation is inherited. Kept as a distinct type so `TursoQuerierPool` does not expose a
|
|
7
|
+
* libsql-named class.
|
|
8
|
+
*/
|
|
9
|
+
export declare class TursoQuerier extends HranaQuerier {
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HranaQuerier } from '../sqlite/hranaQuerier.js';
|
|
2
|
+
/**
|
|
3
|
+
* Querier for remote Turso Cloud databases over `@tursodatabase/serverless/compat`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks Empty subclass by design: that compat client speaks the Hrana protocol, so the whole
|
|
6
|
+
* implementation is inherited. Kept as a distinct type so `TursoQuerierPool` does not expose a
|
|
7
|
+
* libsql-named class.
|
|
8
|
+
*/
|
|
9
|
+
export class TursoQuerier extends HranaQuerier {
|
|
10
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { HranaClient } from '../sqlite/hranaQuerier.js';
|
|
2
|
+
import { AbstractHranaQuerierPool } from '../sqlite/hranaQuerierPool.js';
|
|
3
|
+
import type { ExtraOptions } from '../type/index.js';
|
|
4
|
+
import { TursoDialect } from './tursoDialect.js';
|
|
5
|
+
import { TursoQuerier } from './tursoQuerier.js';
|
|
6
|
+
/**
|
|
7
|
+
* Connection settings for Turso Cloud, mirroring `@tursodatabase/serverless`.
|
|
8
|
+
*
|
|
9
|
+
* @remarks Declared here rather than imported so this package does not couple its published types
|
|
10
|
+
* to a pre-1.0 dependency.
|
|
11
|
+
*/
|
|
12
|
+
export type TursoConfig = {
|
|
13
|
+
/** `libsql://<db>.turso.io` or `https://<db>.turso.io`. */
|
|
14
|
+
url: string;
|
|
15
|
+
authToken?: string;
|
|
16
|
+
remoteEncryptionKey?: string;
|
|
17
|
+
/** Extra HTTP headers attached to every request, e.g. for routing through a gateway. */
|
|
18
|
+
requestHeaders?: Record<string, string>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Pool for remote Turso Cloud databases, driven by `@tursodatabase/serverless/compat`.
|
|
22
|
+
*
|
|
23
|
+
* @remarks The compat entry point is required rather than the native one: the native
|
|
24
|
+
* `conn.transaction()` takes a callback, which cannot satisfy the explicit
|
|
25
|
+
* `beginTransaction`/`commitTransaction` contract, and issuing a bare `BEGIN` is not an option
|
|
26
|
+
* because over plain HTTP consecutive requests need not share a connection. Compat's session-backed
|
|
27
|
+
* transaction handle is the piece that makes it work.
|
|
28
|
+
*/
|
|
29
|
+
export declare class TursoQuerierPool extends AbstractHranaQuerierPool<TursoQuerier, TursoDialect> {
|
|
30
|
+
protected readonly ownsClient: boolean;
|
|
31
|
+
private readonly conf;
|
|
32
|
+
/**
|
|
33
|
+
* Accepts either connection settings or an already-built client. The latter covers any driver
|
|
34
|
+
* with the same shape: `@libsql/client/web`, `@libsql/client-wasm`, or a test double.
|
|
35
|
+
*/
|
|
36
|
+
constructor(conf: TursoConfig | HranaClient, extra?: ExtraOptions);
|
|
37
|
+
protected openClient(): Promise<HranaClient>;
|
|
38
|
+
protected buildQuerier(client: HranaClient): TursoQuerier;
|
|
39
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AbstractHranaQuerierPool } from '../sqlite/hranaQuerierPool.js';
|
|
2
|
+
import { TursoDialect } from './tursoDialect.js';
|
|
3
|
+
import { TursoQuerier } from './tursoQuerier.js';
|
|
4
|
+
function isClient(conf) {
|
|
5
|
+
return typeof conf.execute === 'function';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Pool for remote Turso Cloud databases, driven by `@tursodatabase/serverless/compat`.
|
|
9
|
+
*
|
|
10
|
+
* @remarks The compat entry point is required rather than the native one: the native
|
|
11
|
+
* `conn.transaction()` takes a callback, which cannot satisfy the explicit
|
|
12
|
+
* `beginTransaction`/`commitTransaction` contract, and issuing a bare `BEGIN` is not an option
|
|
13
|
+
* because over plain HTTP consecutive requests need not share a connection. Compat's session-backed
|
|
14
|
+
* transaction handle is the piece that makes it work.
|
|
15
|
+
*/
|
|
16
|
+
export class TursoQuerierPool extends AbstractHranaQuerierPool {
|
|
17
|
+
ownsClient;
|
|
18
|
+
conf;
|
|
19
|
+
/**
|
|
20
|
+
* Accepts either connection settings or an already-built client. The latter covers any driver
|
|
21
|
+
* with the same shape: `@libsql/client/web`, `@libsql/client-wasm`, or a test double.
|
|
22
|
+
*/
|
|
23
|
+
constructor(conf, extra) {
|
|
24
|
+
super(new TursoDialect({ namingStrategy: extra?.namingStrategy }), extra);
|
|
25
|
+
this.conf = conf;
|
|
26
|
+
this.ownsClient = !isClient(conf);
|
|
27
|
+
}
|
|
28
|
+
async openClient() {
|
|
29
|
+
if (isClient(this.conf)) {
|
|
30
|
+
return this.conf;
|
|
31
|
+
}
|
|
32
|
+
const { createClient } = await import('@tursodatabase/serverless/compat');
|
|
33
|
+
return createClient(this.conf);
|
|
34
|
+
}
|
|
35
|
+
buildQuerier(client) {
|
|
36
|
+
return new TursoQuerier(client, this.dialect, this.extra);
|
|
37
|
+
}
|
|
38
|
+
}
|
package/dist/type/config.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AbstractDialect } from '../dialect/abstractDialect.js';
|
|
2
2
|
import type { ForeignKeyAction } from '../schema/types.js';
|
|
3
|
-
import type { NamingStrategy } from './namingStrategy.js';
|
|
4
3
|
import type { Querier } from './querier.js';
|
|
5
4
|
import type { QuerierPool } from './querierPool.js';
|
|
6
5
|
import type { Type } from './utility.js';
|
|
@@ -29,11 +28,6 @@ export interface Config {
|
|
|
29
28
|
* @default 'uql_migrations'
|
|
30
29
|
*/
|
|
31
30
|
tableName?: string;
|
|
32
|
-
/**
|
|
33
|
-
* The naming strategy for mapping class/property names to database table/column names.
|
|
34
|
-
* @default DefaultNamingStrategy (camelCase -> camelCase)
|
|
35
|
-
*/
|
|
36
|
-
namingStrategy?: NamingStrategy;
|
|
37
31
|
/**
|
|
38
32
|
* Default action for foreign key ON DELETE and ON UPDATE clauses.
|
|
39
33
|
* @default 'NO ACTION'
|
package/dist/type/dialect.d.ts
CHANGED
|
@@ -74,11 +74,11 @@ export interface EngineFeatures {
|
|
|
74
74
|
/** Whether the dialect supports inline COMMENT on columns (MySQL/MariaDB). */
|
|
75
75
|
readonly columnComment: boolean;
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
78
|
-
* `CREATE INDEX
|
|
79
|
-
* `
|
|
77
|
+
* Whether a vector index is declared inline in `CREATE TABLE` (MySQL/MariaDB) rather than as its own
|
|
78
|
+
* `CREATE INDEX` statement. The statement's shape itself is the dialect's business, see
|
|
79
|
+
* `AbstractSqlDialect.getCreateIndexStatement`.
|
|
80
80
|
*/
|
|
81
|
-
readonly
|
|
81
|
+
readonly inlineVectorIndex: boolean;
|
|
82
82
|
/** Whether the dialect requires/allows (n) length constraints on vector types. */
|
|
83
83
|
readonly vectorSupportsLength: boolean;
|
|
84
84
|
/** Whether the dialect natively supports the TIMESTAMPTZ alias/type. */
|
|
@@ -196,3 +196,11 @@ export interface SqlQueryDialect extends QueryDialect {
|
|
|
196
196
|
*/
|
|
197
197
|
placeholder(index: number): string;
|
|
198
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* An index capability that some engines have and others reject outright. Verified live: expression
|
|
201
|
+
* indexes exist everywhere but MariaDB 12.3 (which needs a generated column); prefix lengths are
|
|
202
|
+
* MySQL-family only and *required* there to index `TEXT`; `NULLS FIRST/LAST` and operator classes are
|
|
203
|
+
* Postgres-only (CockroachDB 26.2 answers "unimplemented"); `INCLUDE` is Postgres-wire only.
|
|
204
|
+
*/
|
|
205
|
+
export type IndexFeature = 'expression' | 'prefixLength' | 'nullsOrder' | 'opsClass' | 'include';
|
|
206
|
+
export declare const INDEX_FEATURE_LABELS: Record<IndexFeature, string>;
|
package/dist/type/dialect.js
CHANGED