flint-orm 0.4.4 → 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.
@@ -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(details: {
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(details: {
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(details: LibSQLWebConnectionDetails): {
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>;
@@ -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(details: LibSQLConnectionDetails): {
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 TursoSyncConnectionDetails {
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?: string;
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(details: TursoSyncConnectionDetails): Promise<{
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
+ };
@@ -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 = await flint({ url: './app.db' })
21
+ * const db = flint({ url: './app.db' })
19
22
  */
20
- export declare function flint(details: {
23
+ export declare function flint(options: {
21
24
  url: string;
22
- }): Promise<{
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 { LibSQLWebConnectionDetails } from '../drivers/libsql-web';
2
+ export type { Config as LibSQLWebConfig } from '@libsql/client/web';
@@ -1,2 +1,2 @@
1
1
  export { flint } from '../drivers/libsql';
2
- export type { LibSQLConnectionDetails } from '../drivers/libsql';
2
+ export type { Config as LibSQLConfig } from '@libsql/client';
@@ -1,2 +1,2 @@
1
1
  export { flint } from '../drivers/turso-sync';
2
- export type { TursoSyncConnectionDetails } from '../drivers/turso-sync';
2
+ export type { TursoSyncOptions } from '../drivers/turso-sync';
@@ -3,6 +3,7 @@ export interface SerializedColumn {
3
3
  name: string;
4
4
  sqlType: 'text' | 'integer' | 'real' | 'blob';
5
5
  isPrimaryKey: boolean;
6
+ isAutoIncrement?: boolean;
6
7
  isNotNull: boolean;
7
8
  isUnique: boolean;
8
9
  hasDefault: boolean;
package/dist/src/cli.js CHANGED
@@ -275,6 +275,9 @@ function diffColumns(tableName, prevCols, currCols) {
275
275
  if (prevCol.isPrimaryKey !== currCol.isPrimaryKey) {
276
276
  unsafe = true;
277
277
  }
278
+ if (prevCol.isAutoIncrement !== undefined && (prevCol.isAutoIncrement ?? false) !== (currCol.isAutoIncrement ?? false)) {
279
+ unsafe = true;
280
+ }
278
281
  if (prevCol.isNotNull !== currCol.isNotNull) {
279
282
  if (prevCol.isNotNull && !currCol.isNotNull) {
280
283
  unsafe = true;
@@ -529,11 +532,15 @@ function serializeColumn(col) {
529
532
  name: col.name,
530
533
  sqlType: internal.sqlType,
531
534
  isPrimaryKey: internal.isPrimaryKey,
535
+ isAutoIncrement: internal.isAutoIncrement ?? false,
532
536
  isNotNull: internal.isNotNull,
533
537
  isUnique: internal.isUnique,
534
538
  hasDefault: internal.hasDefault,
535
539
  defaultValue: internal.defaultValue
536
540
  };
541
+ if (result.isAutoIncrement && !result.isPrimaryKey) {
542
+ throw new Error(`Column "${col.name}": autoIncrement() requires primaryKey()`);
543
+ }
537
544
  if (internal.referencesTable && internal.referencesColumn) {
538
545
  result.referencesTable = internal.referencesTable;
539
546
  result.referencesColumn = internal.referencesColumn;
@@ -592,6 +599,8 @@ function columnToDDL(col) {
592
599
  const parts = [col.name, sqlType(col)];
593
600
  if (col.isPrimaryKey)
594
601
  parts.push("PRIMARY KEY");
602
+ if (col.isAutoIncrement === true)
603
+ parts.push("AUTOINCREMENT");
595
604
  if (col.isNotNull && !col.isPrimaryKey)
596
605
  parts.push("NOT NULL");
597
606
  if (col.isUnique && !col.isPrimaryKey)
@@ -775,24 +784,7 @@ function serializeOpArg(op) {
775
784
  }
776
785
  }
777
786
  function serializeColumnArg(col) {
778
- const obj = {
779
- name: col.name,
780
- sqlType: col.sqlType,
781
- isPrimaryKey: col.isPrimaryKey,
782
- isNotNull: col.isNotNull,
783
- isUnique: col.isUnique,
784
- hasDefault: col.hasDefault,
785
- defaultValue: col.defaultValue
786
- };
787
- if (col.referencesTable && col.referencesColumn) {
788
- obj.referencesTable = col.referencesTable;
789
- obj.referencesColumn = col.referencesColumn;
790
- if (col.onDelete)
791
- obj.onDelete = col.onDelete;
792
- if (col.onUpdate)
793
- obj.onUpdate = col.onUpdate;
794
- }
795
- return JSON.stringify(obj);
787
+ return JSON.stringify(col);
796
788
  }
797
789
  function serializeIndexArg(idx) {
798
790
  return `{ name: ${JSON.stringify(idx.name)}, columns: ${JSON.stringify(idx.columns)}, unique: ${idx.unique} }`;
@@ -832,7 +824,7 @@ async function generate(tables, migrationsDir, nameOrOptions) {
832
824
  const migrationDir = join(migrationsDir, folderName);
833
825
  mkdirSync(migrationDir, { recursive: true });
834
826
  const uniqueOps = [...new Set(operations.map((op) => op.type))];
835
- const imports = uniqueOps.map((op) => `import { ${op} } from "flint-orm/migration/operations";`).join(`
827
+ const imports = uniqueOps.map((op) => `import { ${op} } from "flint-orm/migration";`).join(`
836
828
  `);
837
829
  const operationLines = operations.map((op) => {
838
830
  const arg = serializeOpArg(op);
@@ -2381,8 +2373,9 @@ class BunSqliteExecutor {
2381
2373
  this.#client.close();
2382
2374
  }
2383
2375
  }
2384
- function flint(details) {
2385
- const client = new Database(details.url);
2376
+ function flint(options) {
2377
+ const { url, ...opts } = options;
2378
+ const client = new Database(url, Object.keys(opts).length ? opts : undefined);
2386
2379
  return createClient(new BunSqliteExecutor(client));
2387
2380
  }
2388
2381
  var init_bun_sqlite = __esm(() => {
@@ -3199,8 +3192,9 @@ class BetterSqlite3Executor {
3199
3192
  this.#client.close();
3200
3193
  }
3201
3194
  }
3202
- function flint2(details) {
3203
- const client = new import_better_sqlite3.default(details.url);
3195
+ function flint2(options) {
3196
+ const { url, ...opts } = options;
3197
+ const client = new import_better_sqlite3.default(url, Object.keys(opts).length ? opts : undefined);
3204
3198
  return createClient(new BetterSqlite3Executor(client));
3205
3199
  }
3206
3200
  var import_better_sqlite3;
@@ -9175,11 +9169,8 @@ class LibsqlExecutor {
9175
9169
  this.#client.close();
9176
9170
  }
9177
9171
  }
9178
- function flint3(details) {
9179
- const client = createClient2({
9180
- url: normalizeUrl(details.url),
9181
- authToken: details.authToken
9182
- });
9172
+ function flint3(options) {
9173
+ const client = createClient2({ ...options, url: normalizeUrl(options.url) });
9183
9174
  return createClient(new LibsqlExecutor(client));
9184
9175
  }
9185
9176
  var init_libsql = __esm(() => {
@@ -9256,8 +9247,8 @@ class LibsqlWebExecutor {
9256
9247
  this.#client.close();
9257
9248
  }
9258
9249
  }
9259
- function flint4(details) {
9260
- const client = createClient3({ url: details.url, authToken: details.authToken });
9250
+ function flint4(options) {
9251
+ const client = createClient3(options);
9261
9252
  return createClient(new LibsqlWebExecutor(client));
9262
9253
  }
9263
9254
  var init_libsql_web = __esm(() => {
@@ -11486,6 +11477,46 @@ var init_promise2 = __esm(() => {
11486
11477
  };
11487
11478
  });
11488
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
+
11489
11520
  // src/drivers/turso-sync.ts
11490
11521
  var exports_turso_sync = {};
11491
11522
  __export(exports_turso_sync, {
@@ -11525,14 +11556,19 @@ class TursoSyncExecutor {
11525
11556
  this.#db.close();
11526
11557
  }
11527
11558
  }
11528
- async function flint5(details) {
11529
- const localPath = details.url.includes("://") ? details.url : resolve2(details.url);
11530
- const db = await connect2({
11531
- path: localPath,
11532
- url: details.syncUrl,
11533
- authToken: details.authToken
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);
11534
11570
  });
11535
- return createClient(new TursoSyncExecutor(db));
11571
+ return createClient(executor);
11536
11572
  }
11537
11573
  var init_turso_sync = __esm(() => {
11538
11574
  init_promise2();
@@ -12110,9 +12146,13 @@ class TursoExecutor {
12110
12146
  this.#db.close();
12111
12147
  }
12112
12148
  }
12113
- async function flint6(details) {
12114
- const db = await connect3(details.url);
12115
- return createClient(new TursoExecutor(db));
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);
12116
12156
  }
12117
12157
  var init_turso = __esm(() => {
12118
12158
  init_promise3();
@@ -2033,8 +2033,9 @@ class BetterSqlite3Executor {
2033
2033
  this.#client.close();
2034
2034
  }
2035
2035
  }
2036
- function flint(details) {
2037
- const client = new import_better_sqlite3.default(details.url);
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(details) {
1273
- const client = new Database(details.url);
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(details) {
6053
- const client = createClient({ url: details.url, authToken: details.authToken });
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(details) {
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
- async function flint(details) {
3487
- const localPath = details.url.includes("://") ? details.url : resolve(details.url);
3488
- const db = await connect2({
3489
- path: localPath,
3490
- url: details.syncUrl,
3491
- authToken: details.authToken
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(new TursoSyncExecutor(db));
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
- async function flint(details) {
2367
- const db = await connect(details.url);
2368
- return createClient(new TursoExecutor(db));
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();
@@ -57,11 +57,15 @@ function serializeColumn(col) {
57
57
  name: col.name,
58
58
  sqlType: internal.sqlType,
59
59
  isPrimaryKey: internal.isPrimaryKey,
60
+ isAutoIncrement: internal.isAutoIncrement ?? false,
60
61
  isNotNull: internal.isNotNull,
61
62
  isUnique: internal.isUnique,
62
63
  hasDefault: internal.hasDefault,
63
64
  defaultValue: internal.defaultValue
64
65
  };
66
+ if (result.isAutoIncrement && !result.isPrimaryKey) {
67
+ throw new Error(`Column "${col.name}": autoIncrement() requires primaryKey()`);
68
+ }
65
69
  if (internal.referencesTable && internal.referencesColumn) {
66
70
  result.referencesTable = internal.referencesTable;
67
71
  result.referencesColumn = internal.referencesColumn;
@@ -207,6 +211,9 @@ function diffColumns(tableName, prevCols, currCols) {
207
211
  if (prevCol.isPrimaryKey !== currCol.isPrimaryKey) {
208
212
  unsafe = true;
209
213
  }
214
+ if (prevCol.isAutoIncrement !== undefined && (prevCol.isAutoIncrement ?? false) !== (currCol.isAutoIncrement ?? false)) {
215
+ unsafe = true;
216
+ }
210
217
  if (prevCol.isNotNull !== currCol.isNotNull) {
211
218
  if (prevCol.isNotNull && !currCol.isNotNull) {
212
219
  unsafe = true;
@@ -463,6 +470,8 @@ function columnToDDL(col) {
463
470
  const parts = [col.name, sqlType(col)];
464
471
  if (col.isPrimaryKey)
465
472
  parts.push("PRIMARY KEY");
473
+ if (col.isAutoIncrement === true)
474
+ parts.push("AUTOINCREMENT");
466
475
  if (col.isNotNull && !col.isPrimaryKey)
467
476
  parts.push("NOT NULL");
468
477
  if (col.isUnique && !col.isPrimaryKey)
@@ -646,24 +655,7 @@ function serializeOpArg(op) {
646
655
  }
647
656
  }
648
657
  function serializeColumnArg(col) {
649
- const obj = {
650
- name: col.name,
651
- sqlType: col.sqlType,
652
- isPrimaryKey: col.isPrimaryKey,
653
- isNotNull: col.isNotNull,
654
- isUnique: col.isUnique,
655
- hasDefault: col.hasDefault,
656
- defaultValue: col.defaultValue
657
- };
658
- if (col.referencesTable && col.referencesColumn) {
659
- obj.referencesTable = col.referencesTable;
660
- obj.referencesColumn = col.referencesColumn;
661
- if (col.onDelete)
662
- obj.onDelete = col.onDelete;
663
- if (col.onUpdate)
664
- obj.onUpdate = col.onUpdate;
665
- }
666
- return JSON.stringify(obj);
658
+ return JSON.stringify(col);
667
659
  }
668
660
  function serializeIndexArg(idx) {
669
661
  return `{ name: ${JSON.stringify(idx.name)}, columns: ${JSON.stringify(idx.columns)}, unique: ${idx.unique} }`;
@@ -703,7 +695,7 @@ async function generate(tables, migrationsDir, nameOrOptions) {
703
695
  const migrationDir = join(migrationsDir, folderName);
704
696
  mkdirSync(migrationDir, { recursive: true });
705
697
  const uniqueOps = [...new Set(operations.map((op) => op.type))];
706
- const imports = uniqueOps.map((op) => `import { ${op} } from "flint-orm/migration/operations";`).join(`
698
+ const imports = uniqueOps.map((op) => `import { ${op} } from "flint-orm/migration";`).join(`
707
699
  `);
708
700
  const operationLines = operations.map((op) => {
709
701
  const arg = serializeOpArg(op);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flint-orm",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "bin": {
5
5
  "flint": "./dist/src/cli.js"
6
6
  },