flint-orm 0.4.0 → 0.4.2

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.
Files changed (51) hide show
  1. package/API.md +7 -1
  2. package/README.md +3 -1
  3. package/dist/config.d.ts +30 -0
  4. package/dist/drivers/better-sqlite3.d.ts +38 -0
  5. package/dist/drivers/bun-sqlite.d.ts +38 -0
  6. package/dist/drivers/libsql-web.d.ts +44 -0
  7. package/dist/drivers/libsql.d.ts +40 -0
  8. package/dist/drivers/turso-sync.d.ts +44 -0
  9. package/dist/drivers/turso.d.ts +38 -0
  10. package/dist/entries/better-sqlite3.d.ts +1 -0
  11. package/dist/entries/bun-sqlite.d.ts +1 -0
  12. package/dist/entries/config.d.ts +1 -0
  13. package/dist/entries/expressions.d.ts +5 -0
  14. package/dist/entries/libsql-web.d.ts +2 -0
  15. package/dist/entries/libsql.d.ts +2 -0
  16. package/dist/entries/table.d.ts +4 -0
  17. package/dist/entries/turso-sync.d.ts +2 -0
  18. package/dist/entries/turso.d.ts +1 -0
  19. package/dist/errors.d.ts +13 -0
  20. package/dist/executor.d.ts +16 -0
  21. package/dist/flint.d.ts +120 -0
  22. package/dist/index.d.ts +11 -0
  23. package/dist/migration/diff.d.ts +15 -0
  24. package/dist/migration/generate.d.ts +18 -0
  25. package/dist/migration/index.d.ts +11 -0
  26. package/dist/migration/migrate.d.ts +52 -0
  27. package/dist/migration/migration.d.ts +5 -0
  28. package/dist/migration/operations.d.ts +14 -0
  29. package/dist/migration/serialize.d.ts +3 -0
  30. package/dist/migration/sql.d.ts +2 -0
  31. package/dist/migration/types.d.ts +98 -0
  32. package/dist/query/aggregates.d.ts +47 -0
  33. package/dist/query/builder.d.ts +257 -0
  34. package/dist/query/conditions.d.ts +176 -0
  35. package/dist/schema/columns.d.ts +146 -0
  36. package/dist/schema/table.d.ts +74 -0
  37. package/dist/sqlite/introspect.d.ts +19 -0
  38. package/dist/src/cli.js +13744 -0
  39. package/dist/src/entries/better-sqlite3.js +2050 -0
  40. package/dist/src/entries/bun-sqlite.js +1284 -0
  41. package/dist/src/entries/config.js +55 -0
  42. package/dist/src/entries/expressions.js +1252 -0
  43. package/dist/src/entries/libsql-web.js +6065 -0
  44. package/dist/src/entries/libsql.js +7208 -0
  45. package/dist/src/entries/table.js +403 -0
  46. package/dist/src/entries/turso-sync.js +3504 -0
  47. package/dist/src/entries/turso.js +2379 -0
  48. package/dist/{index.js → src/index.js} +86 -22
  49. package/dist/src/migration/index.js +1066 -0
  50. package/package.json +3 -3
  51. package/src/cli.ts +0 -361
package/API.md CHANGED
@@ -110,7 +110,9 @@ text()
110
110
  .unique() // UNIQUE
111
111
  .default('hello') // DEFAULT 'hello'
112
112
  .defaultFn(() => new Date()) // DEFAULT (computed at insert)
113
- .references(otherColumn); // REFERENCES
113
+ .references(otherColumn) // REFERENCES otherColumn
114
+ .onDelete('cascade') // ON DELETE CASCADE
115
+ .onUpdate('set null'); // ON UPDATE SET NULL
114
116
  ```
115
117
 
116
118
  **Integer-only:**
@@ -591,6 +593,9 @@ import { addTable, dropTable, renameTable, addColumn, dropColumn, renameColumn,
591
593
  | `renameColumn` | `ALTER TABLE ... RENAME COLUMN ... TO` |
592
594
  | `createIndex` | `CREATE [UNIQUE] INDEX ...` |
593
595
  | `dropIndex` | `DROP INDEX ...` |
596
+ | `modifyColumn` | `ALTER TABLE ... ALTER COLUMN ...` |
597
+ | `modifyIndex` | `DROP INDEX IF EXISTS ...; CREATE ...` |
598
+ | `rebuildTable` | Temp table → copy → drop → rename |
594
599
 
595
600
  ---
596
601
 
@@ -606,6 +611,7 @@ import { addTable, dropTable, renameTable, addColumn, dropColumn, renameColumn,
606
611
  | `SQLExpression` | `{ sql: string; params: unknown[] }` |
607
612
  | `Executable` | Anything with a `.toSQL()` method (for `batch()`) |
608
613
  | `Driver` | `'bun-sqlite' \| 'better-sqlite3' \| 'libsql' \| 'libsql-web' \| 'turso' \| 'turso-sync'` |
614
+ | `RebuildTableOp` | Migration op that recreates a table with a new schema |
609
615
 
610
616
  ---
611
617
 
package/README.md CHANGED
@@ -78,6 +78,8 @@ const posts = table('posts', {
78
78
  - `.default(value)` — static default value
79
79
  - `.defaultFn(fn)` — dynamic default (called on insert when value is omitted)
80
80
  - `.references(target)` — foreign key reference
81
+ - `.onDelete(action)` — foreign key ON DELETE action (`cascade`, `set null`, `set default`, `restrict`, `no action`)
82
+ - `.onUpdate(action)` — foreign key ON UPDATE action (`cascade`, `set null`, `set default`, `restrict`, `no action`)
81
83
  - `.autoIncrement()` — integer auto-increment (integer columns only)
82
84
  - `.defaultNow()` — use `Date.now()` as default (date columns only)
83
85
  - `.onUpdateTimestamp()` — always set to `Date.now()` on update (date columns only)
@@ -323,7 +325,7 @@ flint migrate --dry-run # show what would run
323
325
  5. Writes a migration folder with `migration.ts` (operations) + `state.json` (snapshot)
324
326
  6. `flint migrate` reads pending migrations and executes them in order
325
327
 
326
- Unsafe changes (type changes, primary key changes) throw an error and must be handled manually.
328
+ Unsafe changes (type changes, primary key changes, FK modifications, UNIQUE changes, DEFAULT removal) automatically emit a `rebuildTable` operation that recreates the table with the new schema and copies data safely within a transaction.
327
329
 
328
330
  ## Subpath Imports
329
331
 
@@ -0,0 +1,30 @@
1
+ export type Driver = 'bun-sqlite' | 'better-sqlite3' | 'libsql' | 'libsql-web' | 'turso-sync' | 'turso';
2
+ export interface DatabaseConfig {
3
+ /** Path or URL to the SQLite database. */
4
+ url: string;
5
+ /** Auth token (required for libsql, libsql-web, turso-sync drivers). */
6
+ authToken?: string;
7
+ }
8
+ export interface FlintConfig {
9
+ /** Which SQLite driver to use. */
10
+ driver: Driver;
11
+ /** Database connection details. */
12
+ database: DatabaseConfig;
13
+ /** Path to schema folder or file containing table() exports. */
14
+ schema: string;
15
+ /** Path to the migrations directory. Defaults to "./flint". */
16
+ migrations?: string;
17
+ }
18
+ /**
19
+ * Define a flint-orm config.
20
+ *
21
+ * @example
22
+ * import { defineConfig } from "flint-orm/config";
23
+ *
24
+ * export default defineConfig({
25
+ * driver: "bun-sqlite",
26
+ * database: { url: "./app.db" },
27
+ * schema: "./src/schema",
28
+ * });
29
+ */
30
+ export declare function defineConfig(config: FlintConfig): FlintConfig;
@@ -0,0 +1,38 @@
1
+ import Database from 'better-sqlite3';
2
+ import type { Executor } from '../executor';
3
+ /** Synchronous executor backed by better-sqlite3, wrapped in Promises for uniform API. */
4
+ export declare class BetterSqlite3Executor implements Executor {
5
+ #private;
6
+ constructor(client: Database.Database);
7
+ all(sql: string, params: unknown[]): Promise<unknown[]>;
8
+ get(sql: string, params: unknown[]): Promise<unknown>;
9
+ run(sql: string, params: unknown[]): Promise<void>;
10
+ transaction(fn: () => void | Promise<void>): Promise<void>;
11
+ close(): void;
12
+ }
13
+ /**
14
+ * Create a flint database client using better-sqlite3.
15
+ *
16
+ * @example
17
+ * import { flint } from 'flint-orm/better-sqlite3'
18
+ * const db = flint({ url: './app.db' })
19
+ */
20
+ export declare function flint(details: {
21
+ url: string;
22
+ }): {
23
+ select: () => import("..").SelectStage1;
24
+ insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
25
+ update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
26
+ delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<T>>;
27
+ leftJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
28
+ innerJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
29
+ batch: (queries: import("..").Executable[]) => Promise<void>;
30
+ count: <T extends import("..").AnyTable>(table: T, condition?: import("..").Condition) => Promise<number>;
31
+ countColumn: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number>;
32
+ sum: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
33
+ avg: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
34
+ min: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
35
+ max: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
36
+ $run(query: string, ...params: unknown[]): Promise<void>;
37
+ $executor: Executor;
38
+ };
@@ -0,0 +1,38 @@
1
+ import { Database } from 'bun:sqlite';
2
+ import type { Executor } from '../executor';
3
+ /** Synchronous executor backed by bun:sqlite, wrapped in Promises for uniform API. */
4
+ export declare class BunSqliteExecutor implements Executor {
5
+ #private;
6
+ constructor(client: Database);
7
+ all(sql: string, params: unknown[]): Promise<unknown[]>;
8
+ get(sql: string, params: unknown[]): Promise<unknown>;
9
+ run(sql: string, params: unknown[]): Promise<void>;
10
+ transaction(fn: () => void | Promise<void>): Promise<void>;
11
+ close(): void;
12
+ }
13
+ /**
14
+ * Create a flint database client using bun:sqlite.
15
+ *
16
+ * @example
17
+ * import { flint } from 'flint-orm/bun-sqlite'
18
+ * const db = flint({ url: './app.db' })
19
+ */
20
+ export declare function flint(details: {
21
+ url: string;
22
+ }): {
23
+ select: () => import("..").SelectStage1;
24
+ insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
25
+ update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
26
+ delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<T>>;
27
+ leftJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
28
+ innerJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
29
+ batch: (queries: import("..").Executable[]) => Promise<void>;
30
+ count: <T extends import("..").AnyTable>(table: T, condition?: import("..").Condition) => Promise<number>;
31
+ countColumn: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number>;
32
+ sum: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
33
+ avg: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
34
+ min: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
35
+ max: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
36
+ $run(query: string, ...params: unknown[]): Promise<void>;
37
+ $executor: Executor;
38
+ };
@@ -0,0 +1,44 @@
1
+ import type { Client } from '@libsql/client';
2
+ import type { Executor } from '../executor';
3
+ /** Async executor backed by @libsql/client/web. */
4
+ export declare class LibsqlWebExecutor implements Executor {
5
+ #private;
6
+ constructor(client: Client);
7
+ all(sql: string, params: unknown[]): Promise<unknown[]>;
8
+ get(sql: string, params: unknown[]): Promise<unknown>;
9
+ run(sql: string, params: unknown[]): Promise<void>;
10
+ transaction(fn: () => void | Promise<void>): Promise<void>;
11
+ close(): void;
12
+ }
13
+ export interface LibSQLWebConnectionDetails {
14
+ /** Database URL — must use ws:, wss:, http:, or https: scheme. */
15
+ url: string;
16
+ authToken?: string;
17
+ }
18
+ /**
19
+ * Create a flint database client using @libsql/client/web.
20
+ *
21
+ * **Note:** The web client only supports `ws:`, `wss:`, `http:`, and `https:` URLs.
22
+ * `file:` URLs are not supported — use the `flint-orm/libsql` entry point for local SQLite files.
23
+ *
24
+ * @example
25
+ * import { flint } from 'flint-orm/libsql-web'
26
+ * const db = flint({ url: 'libsql://your-db.turso.io', authToken: '...' })
27
+ */
28
+ export declare function flint(details: LibSQLWebConnectionDetails): {
29
+ select: () => import("..").SelectStage1;
30
+ insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
31
+ update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
32
+ delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<T>>;
33
+ leftJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
34
+ innerJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
35
+ batch: (queries: import("..").Executable[]) => Promise<void>;
36
+ count: <T extends import("..").AnyTable>(table: T, condition?: import("..").Condition) => Promise<number>;
37
+ countColumn: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number>;
38
+ sum: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
39
+ avg: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
40
+ min: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
41
+ max: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
42
+ $run(query: string, ...params: unknown[]): Promise<void>;
43
+ $executor: Executor;
44
+ };
@@ -0,0 +1,40 @@
1
+ import type { Client } from '@libsql/client';
2
+ import type { Executor } from '../executor';
3
+ /** Async executor backed by `@libsql/client`. */
4
+ export declare class LibsqlExecutor implements Executor {
5
+ #private;
6
+ constructor(client: Client);
7
+ all(sql: string, params: unknown[]): Promise<unknown[]>;
8
+ get(sql: string, params: unknown[]): Promise<unknown>;
9
+ run(sql: string, params: unknown[]): Promise<void>;
10
+ transaction(fn: () => void | Promise<void>): Promise<void>;
11
+ close(): void;
12
+ }
13
+ export interface LibSQLConnectionDetails {
14
+ url: string;
15
+ authToken?: string;
16
+ }
17
+ /**
18
+ * Create a flint database client using @libsql/client.
19
+ *
20
+ * @example
21
+ * import { flint } from 'flint-orm/libsql'
22
+ * const db = flint({ url: 'libsql://your-db.turso.io', authToken: '...' })
23
+ */
24
+ export declare function flint(details: LibSQLConnectionDetails): {
25
+ select: () => import("..").SelectStage1;
26
+ insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
27
+ update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
28
+ delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<T>>;
29
+ leftJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
30
+ innerJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
31
+ batch: (queries: import("..").Executable[]) => Promise<void>;
32
+ count: <T extends import("..").AnyTable>(table: T, condition?: import("..").Condition) => Promise<number>;
33
+ countColumn: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number>;
34
+ sum: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
35
+ avg: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
36
+ min: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
37
+ max: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
38
+ $run(query: string, ...params: unknown[]): Promise<void>;
39
+ $executor: Executor;
40
+ };
@@ -0,0 +1,44 @@
1
+ import type { Database } from '@tursodatabase/sync';
2
+ import type { Executor } from '../executor';
3
+ /** Async executor backed by @tursodatabase/sync. */
4
+ export declare class TursoSyncExecutor implements Executor {
5
+ #private;
6
+ constructor(db: Database);
7
+ all(sql: string, params: unknown[]): Promise<unknown[]>;
8
+ get(sql: string, params: unknown[]): Promise<unknown>;
9
+ run(sql: string, params: unknown[]): Promise<void>;
10
+ transaction(fn: () => void | Promise<void>): Promise<void>;
11
+ close(): void;
12
+ }
13
+ export interface TursoSyncConnectionDetails {
14
+ /** Local path for the synced database files. */
15
+ url: string;
16
+ /** Remote Turso database URL (libsql://...). */
17
+ syncUrl?: string;
18
+ /** Auth token for the remote database. */
19
+ authToken?: string;
20
+ }
21
+ /**
22
+ * Create a flint database client using @tursodatabase/sync.
23
+ *
24
+ * @example
25
+ * import { flint } from 'flint-orm/turso-sync'
26
+ * const db = flint({ url: './local.db', syncUrl: 'libsql://db.turso.io', authToken: '...' })
27
+ */
28
+ export declare function flint(details: TursoSyncConnectionDetails): Promise<{
29
+ select: () => import("..").SelectStage1;
30
+ insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
31
+ update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
32
+ delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<T>>;
33
+ leftJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
34
+ innerJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
35
+ batch: (queries: import("..").Executable[]) => Promise<void>;
36
+ count: <T extends import("..").AnyTable>(table: T, condition?: import("..").Condition) => Promise<number>;
37
+ countColumn: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number>;
38
+ sum: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
39
+ avg: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
40
+ min: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
41
+ max: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
42
+ $run(query: string, ...params: unknown[]): Promise<void>;
43
+ $executor: Executor;
44
+ }>;
@@ -0,0 +1,38 @@
1
+ import type { Database } from '@tursodatabase/database';
2
+ import type { Executor } from '../executor';
3
+ /** Async executor backed by @tursodatabase/database. */
4
+ export declare class TursoExecutor implements Executor {
5
+ #private;
6
+ constructor(db: Database);
7
+ all(sql: string, params: unknown[]): Promise<unknown[]>;
8
+ get(sql: string, params: unknown[]): Promise<unknown>;
9
+ run(sql: string, params: unknown[]): Promise<void>;
10
+ transaction(fn: () => void | Promise<void>): Promise<void>;
11
+ close(): void;
12
+ }
13
+ /**
14
+ * Create a flint database client using @tursodatabase/database.
15
+ *
16
+ * @example
17
+ * import { flint } from 'flint-orm/turso'
18
+ * const db = await flint({ url: './app.db' })
19
+ */
20
+ export declare function flint(details: {
21
+ url: string;
22
+ }): Promise<{
23
+ select: () => import("..").SelectStage1;
24
+ insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
25
+ update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
26
+ delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<T>>;
27
+ leftJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
28
+ innerJoin: <Parent extends import("..").AnyTable>(parent: Parent) => import("../flint").JoinSelectStage1<Parent>;
29
+ batch: (queries: import("..").Executable[]) => Promise<void>;
30
+ count: <T extends import("..").AnyTable>(table: T, condition?: import("..").Condition) => Promise<number>;
31
+ countColumn: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number>;
32
+ sum: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
33
+ avg: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
34
+ min: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
35
+ max: <T extends import("..").AnyTable, C extends import("..").ColumnDef<any, any>>(table: T, column: C, condition?: import("..").Condition) => Promise<number | null>;
36
+ $run(query: string, ...params: unknown[]): Promise<void>;
37
+ $executor: Executor;
38
+ }>;
@@ -0,0 +1 @@
1
+ export { flint } from '../drivers/better-sqlite3';
@@ -0,0 +1 @@
1
+ export { flint } from '../drivers/bun-sqlite';
@@ -0,0 +1 @@
1
+ export { defineConfig, type FlintConfig, type Driver, type DatabaseConfig } from '../config.js';
@@ -0,0 +1,5 @@
1
+ export { eq, and, or, gt, gte, lt, lte, neq, isIn, isNotIn, isNull, isNotNull, like, glob, between } from '../query/conditions';
2
+ export type { Condition } from '../query/conditions';
3
+ export { sql } from '../flint';
4
+ export type { SQLExpression } from '../flint';
5
+ export { count, countColumn, sum, avg, min, max } from '../query/aggregates';
@@ -0,0 +1,2 @@
1
+ export { flint } from '../drivers/libsql-web';
2
+ export type { LibSQLWebConnectionDetails } from '../drivers/libsql-web';
@@ -0,0 +1,2 @@
1
+ export { flint } from '../drivers/libsql';
2
+ export type { LibSQLConnectionDetails } from '../drivers/libsql';
@@ -0,0 +1,4 @@
1
+ export { text, integer, boolean, json, date, real } from '../schema/columns';
2
+ export type { ColumnDef, IntegerColumnDef, DateColumnDef, DateColumnDefWithDefault, ForeignKeyAction } from '../schema/columns';
3
+ export { table, index, snakeCase } from '../schema/table';
4
+ export type { InferRow, InsertRow, TableDef, AnyTable, IndexDef, IndexBuilder } from '../schema/table';
@@ -0,0 +1,2 @@
1
+ export { flint } from '../drivers/turso-sync';
2
+ export type { TursoSyncConnectionDetails } from '../drivers/turso-sync';
@@ -0,0 +1 @@
1
+ export { flint } from '../drivers/turso';
@@ -0,0 +1,13 @@
1
+ /** Base error class for all flint-orm errors. */
2
+ export declare class FlintError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ /** Thrown when a value violates a column constraint or a validation rule fails. */
6
+ export declare class FlintValidationError extends FlintError {
7
+ constructor(message: string);
8
+ }
9
+ /** Thrown when a SQL query fails to execute. */
10
+ export declare class FlintQueryError extends FlintError {
11
+ readonly originalError?: Error;
12
+ constructor(message: string, originalError?: Error);
13
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A database executor that runs SQL and returns results.
3
+ * All methods return Promises for a uniform async API.
4
+ */
5
+ export interface Executor {
6
+ /** Execute a query and return all matching rows. */
7
+ all(sql: string, params: unknown[]): Promise<unknown[]>;
8
+ /** Execute a query and return a single row or null. */
9
+ get(sql: string, params: unknown[]): Promise<unknown>;
10
+ /** Execute a statement (INSERT, UPDATE, DELETE, DDL). */
11
+ run(sql: string, params: unknown[]): Promise<void>;
12
+ /** Run a callback inside a transaction. */
13
+ transaction(fn: () => void | Promise<void>): Promise<void>;
14
+ /** Close the underlying database connection. No-op if already closed. */
15
+ close(): void;
16
+ }
@@ -0,0 +1,120 @@
1
+ import type { Executor } from './executor';
2
+ import { DeleteBuilder } from './query/builder';
3
+ import type { Executable, SelectStage1, InsertStage1, UpdateStage1, JoinSelectStage1 } from './query/builder';
4
+ import type { AnyTable } from './schema/table';
5
+ import type { Condition } from './query/conditions';
6
+ import type { ColumnDef } from './schema/columns';
7
+ export type { Executable, SelectStage1, InsertStage1, UpdateStage1, JoinSelectStage1, JoinBuilder, SingleJoinBuilder } from './query/builder';
8
+ export type { JoinResult } from './query/builder';
9
+ /**
10
+ * A raw SQL expression with parameters.
11
+ */
12
+ export interface SQLExpression {
13
+ sql: string;
14
+ params: unknown[];
15
+ }
16
+ /**
17
+ * Create a flint database client from an executor.
18
+ *
19
+ * This is the shared core — driver-specific entry points call this
20
+ * with their executor implementation.
21
+ *
22
+ * @example
23
+ * // Used internally by driver entry points:
24
+ * import { createClient } from '../flint'
25
+ * export function flint(details) {
26
+ * const executor = new BunSqliteExecutor(new Database(details.url))
27
+ * return createClient(executor)
28
+ * }
29
+ */
30
+ export declare function createClient(executor: Executor): {
31
+ /**
32
+ * Start a SELECT query — call `.from(table)` next.
33
+ *
34
+ * @example
35
+ * const rows = db.select().from(users).execute()
36
+ */
37
+ select: () => SelectStage1;
38
+ /**
39
+ * Start an INSERT — call `.values(row)` next.
40
+ *
41
+ * @example
42
+ * db.insert(users).values({ id: "u1", name: "Alice" }).execute()
43
+ */
44
+ insert: <T extends AnyTable>(table: T) => InsertStage1<T>;
45
+ /**
46
+ * Start an UPDATE — call `.set(partial)` next.
47
+ *
48
+ * @example
49
+ * db.update(users).set({ name: "Bob" }).where(eq(users.id, "u1")).execute()
50
+ */
51
+ update: <T extends AnyTable>(table: T) => UpdateStage1<T>;
52
+ /**
53
+ * Start a DELETE — call `.where(condition)` next.
54
+ *
55
+ * @example
56
+ * db.delete(users).where(eq(users.id, "u1")).execute()
57
+ */
58
+ delete: <T extends AnyTable>(table: T) => DeleteBuilder<T, false, keyof import(".").InferRow<T>>;
59
+ /**
60
+ * Start a LEFT JOIN — call `.on(child)` next.
61
+ *
62
+ * @example
63
+ * db.leftJoin(users).on(posts).execute()
64
+ */
65
+ leftJoin: <Parent extends AnyTable>(parent: Parent) => JoinSelectStage1<Parent>;
66
+ /**
67
+ * Start an INNER JOIN — call `.on(child)` next.
68
+ *
69
+ * @example
70
+ * db.innerJoin(users).on(posts).execute()
71
+ */
72
+ innerJoin: <Parent extends AnyTable>(parent: Parent) => JoinSelectStage1<Parent>;
73
+ /**
74
+ * Run multiple queries atomically in a single transaction.
75
+ *
76
+ * @example
77
+ * db.batch([
78
+ * db.insert(users).values({ id: "u1", name: "Alice" }),
79
+ * db.insert(posts).values({ id: "p1", userId: "u1", title: "Hello" }),
80
+ * ])
81
+ */
82
+ batch: (queries: Executable[]) => Promise<void>;
83
+ /**
84
+ * Count all rows in a table, optionally filtered by a condition.
85
+ */
86
+ count: <T extends AnyTable>(table: T, condition?: Condition) => Promise<number>;
87
+ /**
88
+ * Count non-null values of a column, optionally filtered by a condition.
89
+ */
90
+ countColumn: <T extends AnyTable, C extends ColumnDef<any, any>>(table: T, column: C, condition?: Condition) => Promise<number>;
91
+ /**
92
+ * Sum non-null values of a column, optionally filtered by a condition.
93
+ */
94
+ sum: <T extends AnyTable, C extends ColumnDef<any, any>>(table: T, column: C, condition?: Condition) => Promise<number | null>;
95
+ /**
96
+ * Average non-null values of a column, optionally filtered by a condition.
97
+ */
98
+ avg: <T extends AnyTable, C extends ColumnDef<any, any>>(table: T, column: C, condition?: Condition) => Promise<number | null>;
99
+ /**
100
+ * Find the minimum non-null value of a column, optionally filtered by a condition.
101
+ */
102
+ min: <T extends AnyTable, C extends ColumnDef<any, any>>(table: T, column: C, condition?: Condition) => Promise<number | null>;
103
+ /**
104
+ * Find the maximum non-null value of a column, optionally filtered by a condition.
105
+ */
106
+ max: <T extends AnyTable, C extends ColumnDef<any, any>>(table: T, column: C, condition?: Condition) => Promise<number | null>;
107
+ /**
108
+ * Execute raw SQL directly against the database.
109
+ */
110
+ $run(query: string, ...params: unknown[]): Promise<void>;
111
+ /** Direct access to the underlying executor. */
112
+ $executor: Executor;
113
+ };
114
+ /**
115
+ * Tagged template for building parameterized SQL expressions.
116
+ *
117
+ * @example
118
+ * const expr = sql`name = ${"Alice"} AND age > ${18}`
119
+ */
120
+ export declare function sql(strings: TemplateStringsArray, ...values: unknown[]): SQLExpression;
@@ -0,0 +1,11 @@
1
+ export { sql, createClient } from './flint';
2
+ export type { SQLExpression, Executable, SelectStage1, InsertStage1, UpdateStage1 } from './flint';
3
+ export type { Executor } from './executor';
4
+ export { text, integer, boolean, json, date, real } from './schema/columns';
5
+ export type { ColumnDef, IntegerColumnDef, DateColumnDef, DateColumnDefWithDefault } from './schema/columns';
6
+ export { table, index, snakeCase } from './schema/table';
7
+ export type { InferRow, InsertRow, TableDef, AnyTable, IndexDef, IndexBuilder } from './schema/table';
8
+ export { eq, and, or, gt, gte, lt, lte, neq, isIn, isNotIn, isNull, isNotNull, like, glob, between } from './query/conditions';
9
+ export type { Condition } from './query/conditions';
10
+ export { count, countColumn, sum, avg, min, max } from './query/aggregates';
11
+ export { introspect } from './sqlite/introspect';
@@ -0,0 +1,15 @@
1
+ import type { SchemaState, MigrationOperation } from './types.js';
2
+ export declare class CancellationError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ export declare function diffSchemas(previous: SchemaState, current: SchemaState): MigrationOperation[];
6
+ export declare function emptyState(): SchemaState;
7
+ export type RenamePrompt = (message: string, options: {
8
+ value: string;
9
+ label: string;
10
+ hint: string;
11
+ }[]) => Promise<string | symbol>;
12
+ export declare function resolveRenames(operations: MigrationOperation[], options?: {
13
+ interactive?: boolean;
14
+ prompt?: RenamePrompt;
15
+ }): Promise<MigrationOperation[]>;
@@ -0,0 +1,18 @@
1
+ import type { TableDef } from '../schema/table.js';
2
+ import type { SchemaState, MigrationOperation } from './types.js';
3
+ import type { RenamePrompt } from './diff.js';
4
+ export interface GenerateResult {
5
+ folderName: string;
6
+ operations: MigrationOperation[];
7
+ sql: string;
8
+ state: SchemaState;
9
+ }
10
+ export interface GenerateOptions {
11
+ /** Migration folder name override. */
12
+ name?: string;
13
+ /** Whether to run interactive rename prompts. Defaults to true. */
14
+ interactive?: boolean;
15
+ /** Custom prompt function for rename resolution. Required when interactive is true. */
16
+ prompt?: RenamePrompt;
17
+ }
18
+ export declare function generate(tables: TableDef<any>[], migrationsDir: string, nameOrOptions?: string | GenerateOptions): Promise<GenerateResult>;
@@ -0,0 +1,11 @@
1
+ export { defineMigration } from './migration.js';
2
+ export { serializeSchema } from './serialize.js';
3
+ export { diffSchemas, emptyState, resolveRenames, CancellationError } from './diff.js';
4
+ export type { RenamePrompt } from './diff.js';
5
+ export { generateSQL } from './sql.js';
6
+ export { generate } from './generate.js';
7
+ export type { GenerateOptions } from './generate.js';
8
+ export { migrate, getMigrationStatus } from './migrate.js';
9
+ export type { MigrateOptions, MigrateResult, MigrationStatus } from './migrate.js';
10
+ export { addTable, dropTable, renameTable, addColumn, dropColumn, renameColumn, createIndex, dropIndex, modifyColumn, modifyIndex, rebuildTable, } from './operations.js';
11
+ export type { SchemaState, SerializedColumn, SerializedTable, SerializedIndex, MigrationOperation, MigrationFile, ModifyColumnOp, ModifyIndexOp, RebuildTableOp, } from './types.js';
@@ -0,0 +1,52 @@
1
+ import type { Executor } from '../executor.js';
2
+ export interface MigrateOptions {
3
+ /** Path to the migrations directory. */
4
+ migrationsDir: string;
5
+ /** Dry run — show what would be applied without executing. */
6
+ dryRun?: boolean;
7
+ }
8
+ export interface MigrateResult {
9
+ /** Names of migrations that were applied. */
10
+ applied: string[];
11
+ /** Names of migrations that were skipped (already applied). */
12
+ skipped: string[];
13
+ }
14
+ /**
15
+ * Apply pending migrations to a database.
16
+ *
17
+ * Reads the migrations directory, filters out already-applied migrations,
18
+ * and applies the remaining ones in order within transactions.
19
+ *
20
+ * @param executor - The database executor (works with any driver)
21
+ * @param options - Migration options
22
+ * @returns Result with applied and skipped migration names
23
+ *
24
+ * @example
25
+ * import { flint } from 'flint-orm/bun-sqlite';
26
+ * import { migrate } from 'flint-orm/migration';
27
+ *
28
+ * const db = flint({ url: 'app.db' });
29
+ * const result = await migrate(db.$executor, { migrationsDir: './flint' });
30
+ * console.log(`Applied: ${result.applied.join(', ')}`);
31
+ */
32
+ export declare function migrate(executor: Executor, options: MigrateOptions): Promise<MigrateResult>;
33
+ export interface MigrationStatus {
34
+ /** Applied migration names with their timestamps. */
35
+ applied: {
36
+ name: string;
37
+ folderName: string;
38
+ }[];
39
+ /** Pending migration names. */
40
+ pending: {
41
+ name: string;
42
+ folderName: string;
43
+ }[];
44
+ }
45
+ /**
46
+ * Get the status of migrations — which are applied and which are pending.
47
+ *
48
+ * @param executor - The database executor (works with any driver)
49
+ * @param migrationsDir - Path to the migrations directory
50
+ * @returns Status object with applied and pending migrations
51
+ */
52
+ export declare function getMigrationStatus(executor: Executor, migrationsDir: string): Promise<MigrationStatus>;