flint-orm 0.4.5 → 0.5.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/drivers/better-sqlite3.d.ts +2 -2
- package/dist/drivers/bun-sqlite.d.ts +3 -2
- package/dist/drivers/lazy-executor.d.ts +14 -0
- package/dist/drivers/libsql-web.d.ts +2 -7
- package/dist/drivers/libsql.d.ts +2 -6
- package/dist/drivers/turso-sync.d.ts +7 -5
- package/dist/drivers/turso.d.ts +7 -4
- package/dist/entries/libsql-web.d.ts +1 -1
- package/dist/entries/libsql.d.ts +1 -1
- package/dist/entries/turso-sync.d.ts +1 -1
- package/dist/src/cli.js +73 -22
- package/dist/src/entries/better-sqlite3.js +3 -2
- package/dist/src/entries/bun-sqlite.js +3 -2
- package/dist/src/entries/libsql-web.js +2 -2
- package/dist/src/entries/libsql.js +2 -5
- package/dist/src/entries/turso-sync.js +52 -7
- package/dist/src/entries/turso.js +47 -3
- package/dist/src/migration/index.js +4 -1
- package/package.json +1 -1
|
@@ -17,9 +17,9 @@ export declare class BetterSqlite3Executor implements Executor {
|
|
|
17
17
|
* import { flint } from 'flint-orm/better-sqlite3'
|
|
18
18
|
* const db = flint({ url: './app.db' })
|
|
19
19
|
*/
|
|
20
|
-
export declare function flint(
|
|
20
|
+
export declare function flint(options: {
|
|
21
21
|
url: string;
|
|
22
|
-
}): {
|
|
22
|
+
} & Database.Options): {
|
|
23
23
|
select: () => import("..").SelectStage1;
|
|
24
24
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
25
25
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Database } from 'bun:sqlite';
|
|
2
|
+
import type { DatabaseOptions } from 'bun:sqlite';
|
|
2
3
|
import type { Executor } from '../executor';
|
|
3
4
|
/** Synchronous executor backed by bun:sqlite, wrapped in Promises for uniform API. */
|
|
4
5
|
export declare class BunSqliteExecutor implements Executor {
|
|
@@ -17,9 +18,9 @@ export declare class BunSqliteExecutor implements Executor {
|
|
|
17
18
|
* import { flint } from 'flint-orm/bun-sqlite'
|
|
18
19
|
* const db = flint({ url: './app.db' })
|
|
19
20
|
*/
|
|
20
|
-
export declare function flint(
|
|
21
|
+
export declare function flint(options: {
|
|
21
22
|
url: string;
|
|
22
|
-
}): {
|
|
23
|
+
} & DatabaseOptions): {
|
|
23
24
|
select: () => import("..").SelectStage1;
|
|
24
25
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
25
26
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Executor } from '../executor';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps an async executor factory, deferring connection until first use.
|
|
4
|
+
* This lets flint() be synchronous even for async drivers.
|
|
5
|
+
*/
|
|
6
|
+
export declare class LazyExecutor implements Executor {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(factory: () => Promise<Executor>);
|
|
9
|
+
all(sql: string, params: unknown[]): Promise<unknown[]>;
|
|
10
|
+
get(sql: string, params: unknown[]): Promise<unknown>;
|
|
11
|
+
run(sql: string, params: unknown[]): Promise<void>;
|
|
12
|
+
transaction(fn: () => void | Promise<void>): Promise<void>;
|
|
13
|
+
close(): void;
|
|
14
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Client } from '@libsql/client';
|
|
1
|
+
import type { Client, Config } from '@libsql/client';
|
|
2
2
|
import type { Executor } from '../executor';
|
|
3
3
|
/** Async executor backed by @libsql/client/web. */
|
|
4
4
|
export declare class LibsqlWebExecutor implements Executor {
|
|
@@ -10,11 +10,6 @@ export declare class LibsqlWebExecutor implements Executor {
|
|
|
10
10
|
transaction(fn: () => void | Promise<void>): Promise<void>;
|
|
11
11
|
close(): void;
|
|
12
12
|
}
|
|
13
|
-
export interface LibSQLWebConnectionDetails {
|
|
14
|
-
/** Database URL — must use ws:, wss:, http:, or https: scheme. */
|
|
15
|
-
url: string;
|
|
16
|
-
authToken?: string;
|
|
17
|
-
}
|
|
18
13
|
/**
|
|
19
14
|
* Create a flint database client using @libsql/client/web.
|
|
20
15
|
*
|
|
@@ -25,7 +20,7 @@ export interface LibSQLWebConnectionDetails {
|
|
|
25
20
|
* import { flint } from 'flint-orm/libsql-web'
|
|
26
21
|
* const db = flint({ url: 'libsql://your-db.turso.io', authToken: '...' })
|
|
27
22
|
*/
|
|
28
|
-
export declare function flint(
|
|
23
|
+
export declare function flint(options: Config): {
|
|
29
24
|
select: () => import("..").SelectStage1;
|
|
30
25
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
31
26
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
package/dist/drivers/libsql.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Client } from '@libsql/client';
|
|
1
|
+
import type { Client, Config } from '@libsql/client';
|
|
2
2
|
import type { Executor } from '../executor';
|
|
3
3
|
/** Async executor backed by `@libsql/client`. */
|
|
4
4
|
export declare class LibsqlExecutor implements Executor {
|
|
@@ -10,10 +10,6 @@ export declare class LibsqlExecutor implements Executor {
|
|
|
10
10
|
transaction(fn: () => void | Promise<void>): Promise<void>;
|
|
11
11
|
close(): void;
|
|
12
12
|
}
|
|
13
|
-
export interface LibSQLConnectionDetails {
|
|
14
|
-
url: string;
|
|
15
|
-
authToken?: string;
|
|
16
|
-
}
|
|
17
13
|
/**
|
|
18
14
|
* Create a flint database client using @libsql/client.
|
|
19
15
|
*
|
|
@@ -21,7 +17,7 @@ export interface LibSQLConnectionDetails {
|
|
|
21
17
|
* import { flint } from 'flint-orm/libsql'
|
|
22
18
|
* const db = flint({ url: 'libsql://your-db.turso.io', authToken: '...' })
|
|
23
19
|
*/
|
|
24
|
-
export declare function flint(
|
|
20
|
+
export declare function flint(options: Config): {
|
|
25
21
|
select: () => import("..").SelectStage1;
|
|
26
22
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
27
23
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Database } from '@tursodatabase/sync';
|
|
1
|
+
import type { Database, DatabaseOpts } from '@tursodatabase/sync';
|
|
2
2
|
import type { Executor } from '../executor';
|
|
3
3
|
/** Async executor backed by @tursodatabase/sync. */
|
|
4
4
|
export declare class TursoSyncExecutor implements Executor {
|
|
@@ -10,22 +10,24 @@ export declare class TursoSyncExecutor implements Executor {
|
|
|
10
10
|
transaction(fn: () => void | Promise<void>): Promise<void>;
|
|
11
11
|
close(): void;
|
|
12
12
|
}
|
|
13
|
-
export interface
|
|
13
|
+
export interface TursoSyncOptions extends Omit<DatabaseOpts, 'path' | 'url' | 'authToken'> {
|
|
14
14
|
/** Local path for the synced database files. */
|
|
15
15
|
url: string;
|
|
16
16
|
/** Remote Turso database URL (libsql://...). */
|
|
17
17
|
syncUrl?: string;
|
|
18
18
|
/** Auth token for the remote database. */
|
|
19
|
-
authToken?:
|
|
19
|
+
authToken?: DatabaseOpts['authToken'];
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Create a flint database client using @tursodatabase/sync.
|
|
23
23
|
*
|
|
24
|
+
* Connection is established lazily on first query.
|
|
25
|
+
*
|
|
24
26
|
* @example
|
|
25
27
|
* import { flint } from 'flint-orm/turso-sync'
|
|
26
28
|
* const db = flint({ url: './local.db', syncUrl: 'libsql://db.turso.io', authToken: '...' })
|
|
27
29
|
*/
|
|
28
|
-
export declare function flint(
|
|
30
|
+
export declare function flint(options: TursoSyncOptions): {
|
|
29
31
|
select: () => import("..").SelectStage1;
|
|
30
32
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
31
33
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
|
@@ -41,4 +43,4 @@ export declare function flint(details: TursoSyncConnectionDetails): Promise<{
|
|
|
41
43
|
max: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
|
|
42
44
|
$run(query: string, ...params: unknown[]): Promise<void>;
|
|
43
45
|
$executor: Executor;
|
|
44
|
-
}
|
|
46
|
+
};
|
package/dist/drivers/turso.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { connect } from '@tursodatabase/database';
|
|
1
2
|
import type { Database } from '@tursodatabase/database';
|
|
2
3
|
import type { Executor } from '../executor';
|
|
3
4
|
/** Async executor backed by @tursodatabase/database. */
|
|
@@ -13,13 +14,15 @@ export declare class TursoExecutor implements Executor {
|
|
|
13
14
|
/**
|
|
14
15
|
* Create a flint database client using @tursodatabase/database.
|
|
15
16
|
*
|
|
17
|
+
* Connection is established lazily on first query.
|
|
18
|
+
*
|
|
16
19
|
* @example
|
|
17
20
|
* import { flint } from 'flint-orm/turso'
|
|
18
|
-
* const db =
|
|
21
|
+
* const db = flint({ url: './app.db' })
|
|
19
22
|
*/
|
|
20
|
-
export declare function flint(
|
|
23
|
+
export declare function flint(options: {
|
|
21
24
|
url: string;
|
|
22
|
-
}):
|
|
25
|
+
} & Parameters<typeof connect>[1]): {
|
|
23
26
|
select: () => import("..").SelectStage1;
|
|
24
27
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
25
28
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
|
@@ -35,4 +38,4 @@ export declare function flint(details: {
|
|
|
35
38
|
max: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
|
|
36
39
|
$run(query: string, ...params: unknown[]): Promise<void>;
|
|
37
40
|
$executor: Executor;
|
|
38
|
-
}
|
|
41
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { flint } from '../drivers/libsql-web';
|
|
2
|
-
export type {
|
|
2
|
+
export type { Config as LibSQLWebConfig } from '@libsql/client/web';
|
package/dist/entries/libsql.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { flint } from '../drivers/libsql';
|
|
2
|
-
export type {
|
|
2
|
+
export type { Config as LibSQLConfig } from '@libsql/client';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { flint } from '../drivers/turso-sync';
|
|
2
|
-
export type {
|
|
2
|
+
export type { TursoSyncOptions } from '../drivers/turso-sync';
|
package/dist/src/cli.js
CHANGED
|
@@ -275,7 +275,7 @@ function diffColumns(tableName, prevCols, currCols) {
|
|
|
275
275
|
if (prevCol.isPrimaryKey !== currCol.isPrimaryKey) {
|
|
276
276
|
unsafe = true;
|
|
277
277
|
}
|
|
278
|
-
if ((prevCol.isAutoIncrement ?? false) !== (currCol.isAutoIncrement ?? false)) {
|
|
278
|
+
if (prevCol.isAutoIncrement !== undefined && (prevCol.isAutoIncrement ?? false) !== (currCol.isAutoIncrement ?? false)) {
|
|
279
279
|
unsafe = true;
|
|
280
280
|
}
|
|
281
281
|
if (prevCol.isNotNull !== currCol.isNotNull) {
|
|
@@ -538,6 +538,9 @@ function serializeColumn(col) {
|
|
|
538
538
|
hasDefault: internal.hasDefault,
|
|
539
539
|
defaultValue: internal.defaultValue
|
|
540
540
|
};
|
|
541
|
+
if (result.isAutoIncrement && !result.isPrimaryKey) {
|
|
542
|
+
throw new Error(`Column "${col.name}": autoIncrement() requires primaryKey()`);
|
|
543
|
+
}
|
|
541
544
|
if (internal.referencesTable && internal.referencesColumn) {
|
|
542
545
|
result.referencesTable = internal.referencesTable;
|
|
543
546
|
result.referencesColumn = internal.referencesColumn;
|
|
@@ -2370,8 +2373,9 @@ class BunSqliteExecutor {
|
|
|
2370
2373
|
this.#client.close();
|
|
2371
2374
|
}
|
|
2372
2375
|
}
|
|
2373
|
-
function flint(
|
|
2374
|
-
const
|
|
2376
|
+
function flint(options) {
|
|
2377
|
+
const { url, ...opts } = options;
|
|
2378
|
+
const client = new Database(url, Object.keys(opts).length ? opts : undefined);
|
|
2375
2379
|
return createClient(new BunSqliteExecutor(client));
|
|
2376
2380
|
}
|
|
2377
2381
|
var init_bun_sqlite = __esm(() => {
|
|
@@ -3188,8 +3192,9 @@ class BetterSqlite3Executor {
|
|
|
3188
3192
|
this.#client.close();
|
|
3189
3193
|
}
|
|
3190
3194
|
}
|
|
3191
|
-
function flint2(
|
|
3192
|
-
const
|
|
3195
|
+
function flint2(options) {
|
|
3196
|
+
const { url, ...opts } = options;
|
|
3197
|
+
const client = new import_better_sqlite3.default(url, Object.keys(opts).length ? opts : undefined);
|
|
3193
3198
|
return createClient(new BetterSqlite3Executor(client));
|
|
3194
3199
|
}
|
|
3195
3200
|
var import_better_sqlite3;
|
|
@@ -9164,11 +9169,8 @@ class LibsqlExecutor {
|
|
|
9164
9169
|
this.#client.close();
|
|
9165
9170
|
}
|
|
9166
9171
|
}
|
|
9167
|
-
function flint3(
|
|
9168
|
-
const client = createClient2({
|
|
9169
|
-
url: normalizeUrl(details.url),
|
|
9170
|
-
authToken: details.authToken
|
|
9171
|
-
});
|
|
9172
|
+
function flint3(options) {
|
|
9173
|
+
const client = createClient2({ ...options, url: normalizeUrl(options.url) });
|
|
9172
9174
|
return createClient(new LibsqlExecutor(client));
|
|
9173
9175
|
}
|
|
9174
9176
|
var init_libsql = __esm(() => {
|
|
@@ -9245,8 +9247,8 @@ class LibsqlWebExecutor {
|
|
|
9245
9247
|
this.#client.close();
|
|
9246
9248
|
}
|
|
9247
9249
|
}
|
|
9248
|
-
function flint4(
|
|
9249
|
-
const client = createClient3(
|
|
9250
|
+
function flint4(options) {
|
|
9251
|
+
const client = createClient3(options);
|
|
9250
9252
|
return createClient(new LibsqlWebExecutor(client));
|
|
9251
9253
|
}
|
|
9252
9254
|
var init_libsql_web = __esm(() => {
|
|
@@ -11475,6 +11477,46 @@ var init_promise2 = __esm(() => {
|
|
|
11475
11477
|
};
|
|
11476
11478
|
});
|
|
11477
11479
|
|
|
11480
|
+
// src/drivers/lazy-executor.ts
|
|
11481
|
+
class LazyExecutor {
|
|
11482
|
+
#factory;
|
|
11483
|
+
#executor;
|
|
11484
|
+
#promise;
|
|
11485
|
+
constructor(factory) {
|
|
11486
|
+
this.#factory = factory;
|
|
11487
|
+
}
|
|
11488
|
+
async#resolve() {
|
|
11489
|
+
if (this.#executor)
|
|
11490
|
+
return this.#executor;
|
|
11491
|
+
if (!this.#promise) {
|
|
11492
|
+
this.#promise = this.#factory().then((exec2) => {
|
|
11493
|
+
this.#executor = exec2;
|
|
11494
|
+
return exec2;
|
|
11495
|
+
});
|
|
11496
|
+
}
|
|
11497
|
+
return this.#promise;
|
|
11498
|
+
}
|
|
11499
|
+
async all(sql2, params) {
|
|
11500
|
+
const exec2 = await this.#resolve();
|
|
11501
|
+
return exec2.all(sql2, params);
|
|
11502
|
+
}
|
|
11503
|
+
async get(sql2, params) {
|
|
11504
|
+
const exec2 = await this.#resolve();
|
|
11505
|
+
return exec2.get(sql2, params);
|
|
11506
|
+
}
|
|
11507
|
+
async run(sql2, params) {
|
|
11508
|
+
const exec2 = await this.#resolve();
|
|
11509
|
+
return exec2.run(sql2, params);
|
|
11510
|
+
}
|
|
11511
|
+
async transaction(fn) {
|
|
11512
|
+
const exec2 = await this.#resolve();
|
|
11513
|
+
return exec2.transaction(fn);
|
|
11514
|
+
}
|
|
11515
|
+
close() {
|
|
11516
|
+
this.#executor?.close();
|
|
11517
|
+
}
|
|
11518
|
+
}
|
|
11519
|
+
|
|
11478
11520
|
// src/drivers/turso-sync.ts
|
|
11479
11521
|
var exports_turso_sync = {};
|
|
11480
11522
|
__export(exports_turso_sync, {
|
|
@@ -11514,14 +11556,19 @@ class TursoSyncExecutor {
|
|
|
11514
11556
|
this.#db.close();
|
|
11515
11557
|
}
|
|
11516
11558
|
}
|
|
11517
|
-
|
|
11518
|
-
const
|
|
11519
|
-
const
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
|
|
11559
|
+
function flint5(options) {
|
|
11560
|
+
const { url, syncUrl, authToken, ...rest } = options;
|
|
11561
|
+
const localPath = url.includes("://") ? url : resolve2(url);
|
|
11562
|
+
const executor = new LazyExecutor(async () => {
|
|
11563
|
+
const db = await connect2({
|
|
11564
|
+
path: localPath,
|
|
11565
|
+
url: syncUrl,
|
|
11566
|
+
authToken,
|
|
11567
|
+
...rest
|
|
11568
|
+
});
|
|
11569
|
+
return new TursoSyncExecutor(db);
|
|
11523
11570
|
});
|
|
11524
|
-
return createClient(
|
|
11571
|
+
return createClient(executor);
|
|
11525
11572
|
}
|
|
11526
11573
|
var init_turso_sync = __esm(() => {
|
|
11527
11574
|
init_promise2();
|
|
@@ -12099,9 +12146,13 @@ class TursoExecutor {
|
|
|
12099
12146
|
this.#db.close();
|
|
12100
12147
|
}
|
|
12101
12148
|
}
|
|
12102
|
-
|
|
12103
|
-
const
|
|
12104
|
-
|
|
12149
|
+
function flint6(options) {
|
|
12150
|
+
const { url, ...opts } = options;
|
|
12151
|
+
const executor = new LazyExecutor(async () => {
|
|
12152
|
+
const db = await connect3(url, Object.keys(opts).length ? opts : undefined);
|
|
12153
|
+
return new TursoExecutor(db);
|
|
12154
|
+
});
|
|
12155
|
+
return createClient(executor);
|
|
12105
12156
|
}
|
|
12106
12157
|
var init_turso = __esm(() => {
|
|
12107
12158
|
init_promise3();
|
|
@@ -2033,8 +2033,9 @@ class BetterSqlite3Executor {
|
|
|
2033
2033
|
this.#client.close();
|
|
2034
2034
|
}
|
|
2035
2035
|
}
|
|
2036
|
-
function flint(
|
|
2037
|
-
const
|
|
2036
|
+
function flint(options) {
|
|
2037
|
+
const { url, ...opts } = options;
|
|
2038
|
+
const client = new import_better_sqlite3.default(url, Object.keys(opts).length ? opts : undefined);
|
|
2038
2039
|
return createClient(new BetterSqlite3Executor(client));
|
|
2039
2040
|
}
|
|
2040
2041
|
var import_better_sqlite3;
|
|
@@ -1269,8 +1269,9 @@ class BunSqliteExecutor {
|
|
|
1269
1269
|
this.#client.close();
|
|
1270
1270
|
}
|
|
1271
1271
|
}
|
|
1272
|
-
function flint(
|
|
1273
|
-
const
|
|
1272
|
+
function flint(options) {
|
|
1273
|
+
const { url, ...opts } = options;
|
|
1274
|
+
const client = new Database(url, Object.keys(opts).length ? opts : undefined);
|
|
1274
1275
|
return createClient(new BunSqliteExecutor(client));
|
|
1275
1276
|
}
|
|
1276
1277
|
var init_bun_sqlite = __esm(() => {
|
|
@@ -6049,8 +6049,8 @@ class LibsqlWebExecutor {
|
|
|
6049
6049
|
this.#client.close();
|
|
6050
6050
|
}
|
|
6051
6051
|
}
|
|
6052
|
-
function flint(
|
|
6053
|
-
const client = createClient(
|
|
6052
|
+
function flint(options) {
|
|
6053
|
+
const client = createClient(options);
|
|
6054
6054
|
return createClient2(new LibsqlWebExecutor(client));
|
|
6055
6055
|
}
|
|
6056
6056
|
var init_libsql_web = __esm(() => {
|
|
@@ -7189,11 +7189,8 @@ class LibsqlExecutor {
|
|
|
7189
7189
|
this.#client.close();
|
|
7190
7190
|
}
|
|
7191
7191
|
}
|
|
7192
|
-
function flint(
|
|
7193
|
-
const client = createClient({
|
|
7194
|
-
url: normalizeUrl(details.url),
|
|
7195
|
-
authToken: details.authToken
|
|
7196
|
-
});
|
|
7192
|
+
function flint(options) {
|
|
7193
|
+
const client = createClient({ ...options, url: normalizeUrl(options.url) });
|
|
7197
7194
|
return createClient2(new LibsqlExecutor(client));
|
|
7198
7195
|
}
|
|
7199
7196
|
var init_libsql = __esm(() => {
|
|
@@ -3444,6 +3444,46 @@ var init_flint = __esm(() => {
|
|
|
3444
3444
|
init_aggregates();
|
|
3445
3445
|
});
|
|
3446
3446
|
|
|
3447
|
+
// src/drivers/lazy-executor.ts
|
|
3448
|
+
class LazyExecutor {
|
|
3449
|
+
#factory;
|
|
3450
|
+
#executor;
|
|
3451
|
+
#promise;
|
|
3452
|
+
constructor(factory) {
|
|
3453
|
+
this.#factory = factory;
|
|
3454
|
+
}
|
|
3455
|
+
async#resolve() {
|
|
3456
|
+
if (this.#executor)
|
|
3457
|
+
return this.#executor;
|
|
3458
|
+
if (!this.#promise) {
|
|
3459
|
+
this.#promise = this.#factory().then((exec) => {
|
|
3460
|
+
this.#executor = exec;
|
|
3461
|
+
return exec;
|
|
3462
|
+
});
|
|
3463
|
+
}
|
|
3464
|
+
return this.#promise;
|
|
3465
|
+
}
|
|
3466
|
+
async all(sql2, params) {
|
|
3467
|
+
const exec = await this.#resolve();
|
|
3468
|
+
return exec.all(sql2, params);
|
|
3469
|
+
}
|
|
3470
|
+
async get(sql2, params) {
|
|
3471
|
+
const exec = await this.#resolve();
|
|
3472
|
+
return exec.get(sql2, params);
|
|
3473
|
+
}
|
|
3474
|
+
async run(sql2, params) {
|
|
3475
|
+
const exec = await this.#resolve();
|
|
3476
|
+
return exec.run(sql2, params);
|
|
3477
|
+
}
|
|
3478
|
+
async transaction(fn) {
|
|
3479
|
+
const exec = await this.#resolve();
|
|
3480
|
+
return exec.transaction(fn);
|
|
3481
|
+
}
|
|
3482
|
+
close() {
|
|
3483
|
+
this.#executor?.close();
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
|
|
3447
3487
|
// src/drivers/turso-sync.ts
|
|
3448
3488
|
var exports_turso_sync = {};
|
|
3449
3489
|
__export(exports_turso_sync, {
|
|
@@ -3483,14 +3523,19 @@ class TursoSyncExecutor {
|
|
|
3483
3523
|
this.#db.close();
|
|
3484
3524
|
}
|
|
3485
3525
|
}
|
|
3486
|
-
|
|
3487
|
-
const
|
|
3488
|
-
const
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3526
|
+
function flint(options) {
|
|
3527
|
+
const { url, syncUrl, authToken, ...rest } = options;
|
|
3528
|
+
const localPath = url.includes("://") ? url : resolve(url);
|
|
3529
|
+
const executor = new LazyExecutor(async () => {
|
|
3530
|
+
const db = await connect2({
|
|
3531
|
+
path: localPath,
|
|
3532
|
+
url: syncUrl,
|
|
3533
|
+
authToken,
|
|
3534
|
+
...rest
|
|
3535
|
+
});
|
|
3536
|
+
return new TursoSyncExecutor(db);
|
|
3492
3537
|
});
|
|
3493
|
-
return createClient(
|
|
3538
|
+
return createClient(executor);
|
|
3494
3539
|
}
|
|
3495
3540
|
var init_turso_sync = __esm(() => {
|
|
3496
3541
|
init_promise2();
|
|
@@ -2325,6 +2325,46 @@ var init_flint = __esm(() => {
|
|
|
2325
2325
|
init_aggregates();
|
|
2326
2326
|
});
|
|
2327
2327
|
|
|
2328
|
+
// src/drivers/lazy-executor.ts
|
|
2329
|
+
class LazyExecutor {
|
|
2330
|
+
#factory;
|
|
2331
|
+
#executor;
|
|
2332
|
+
#promise;
|
|
2333
|
+
constructor(factory) {
|
|
2334
|
+
this.#factory = factory;
|
|
2335
|
+
}
|
|
2336
|
+
async#resolve() {
|
|
2337
|
+
if (this.#executor)
|
|
2338
|
+
return this.#executor;
|
|
2339
|
+
if (!this.#promise) {
|
|
2340
|
+
this.#promise = this.#factory().then((exec) => {
|
|
2341
|
+
this.#executor = exec;
|
|
2342
|
+
return exec;
|
|
2343
|
+
});
|
|
2344
|
+
}
|
|
2345
|
+
return this.#promise;
|
|
2346
|
+
}
|
|
2347
|
+
async all(sql2, params) {
|
|
2348
|
+
const exec = await this.#resolve();
|
|
2349
|
+
return exec.all(sql2, params);
|
|
2350
|
+
}
|
|
2351
|
+
async get(sql2, params) {
|
|
2352
|
+
const exec = await this.#resolve();
|
|
2353
|
+
return exec.get(sql2, params);
|
|
2354
|
+
}
|
|
2355
|
+
async run(sql2, params) {
|
|
2356
|
+
const exec = await this.#resolve();
|
|
2357
|
+
return exec.run(sql2, params);
|
|
2358
|
+
}
|
|
2359
|
+
async transaction(fn) {
|
|
2360
|
+
const exec = await this.#resolve();
|
|
2361
|
+
return exec.transaction(fn);
|
|
2362
|
+
}
|
|
2363
|
+
close() {
|
|
2364
|
+
this.#executor?.close();
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2328
2368
|
// src/drivers/turso.ts
|
|
2329
2369
|
var exports_turso = {};
|
|
2330
2370
|
__export(exports_turso, {
|
|
@@ -2363,9 +2403,13 @@ class TursoExecutor {
|
|
|
2363
2403
|
this.#db.close();
|
|
2364
2404
|
}
|
|
2365
2405
|
}
|
|
2366
|
-
|
|
2367
|
-
const
|
|
2368
|
-
|
|
2406
|
+
function flint(options) {
|
|
2407
|
+
const { url, ...opts } = options;
|
|
2408
|
+
const executor = new LazyExecutor(async () => {
|
|
2409
|
+
const db = await connect(url, Object.keys(opts).length ? opts : undefined);
|
|
2410
|
+
return new TursoExecutor(db);
|
|
2411
|
+
});
|
|
2412
|
+
return createClient(executor);
|
|
2369
2413
|
}
|
|
2370
2414
|
var init_turso = __esm(() => {
|
|
2371
2415
|
init_promise2();
|
|
@@ -63,6 +63,9 @@ function serializeColumn(col) {
|
|
|
63
63
|
hasDefault: internal.hasDefault,
|
|
64
64
|
defaultValue: internal.defaultValue
|
|
65
65
|
};
|
|
66
|
+
if (result.isAutoIncrement && !result.isPrimaryKey) {
|
|
67
|
+
throw new Error(`Column "${col.name}": autoIncrement() requires primaryKey()`);
|
|
68
|
+
}
|
|
66
69
|
if (internal.referencesTable && internal.referencesColumn) {
|
|
67
70
|
result.referencesTable = internal.referencesTable;
|
|
68
71
|
result.referencesColumn = internal.referencesColumn;
|
|
@@ -208,7 +211,7 @@ function diffColumns(tableName, prevCols, currCols) {
|
|
|
208
211
|
if (prevCol.isPrimaryKey !== currCol.isPrimaryKey) {
|
|
209
212
|
unsafe = true;
|
|
210
213
|
}
|
|
211
|
-
if ((prevCol.isAutoIncrement ?? false) !== (currCol.isAutoIncrement ?? false)) {
|
|
214
|
+
if (prevCol.isAutoIncrement !== undefined && (prevCol.isAutoIncrement ?? false) !== (currCol.isAutoIncrement ?? false)) {
|
|
212
215
|
unsafe = true;
|
|
213
216
|
}
|
|
214
217
|
if (prevCol.isNotNull !== currCol.isNotNull) {
|