flint-orm 0.4.5 → 0.6.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/API.md +13 -13
- package/README.md +9 -9
- package/dist/drivers/better-sqlite3.d.ts +3 -3
- package/dist/drivers/bun-sqlite.d.ts +4 -3
- package/dist/drivers/lazy-executor.d.ts +14 -0
- package/dist/drivers/libsql-web.d.ts +3 -8
- package/dist/drivers/libsql.d.ts +3 -7
- package/dist/drivers/turso-sync.d.ts +10 -8
- package/dist/drivers/turso.d.ts +8 -5
- 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/flint.d.ts +6 -6
- package/dist/index.d.ts +1 -1
- package/dist/query/builder.d.ts +3 -6
- package/dist/src/cli.js +74 -35
- package/dist/src/entries/better-sqlite3.js +4 -15
- package/dist/src/entries/bun-sqlite.js +4 -15
- package/dist/src/entries/expressions.js +1 -13
- package/dist/src/entries/libsql-web.js +3 -15
- package/dist/src/entries/libsql.js +3 -18
- package/dist/src/entries/turso-sync.js +53 -20
- package/dist/src/entries/turso.js +48 -16
- package/dist/src/index.js +1 -13
- package/dist/src/migration/index.js +4 -1
- package/package.json +13 -5
package/API.md
CHANGED
|
@@ -30,7 +30,7 @@ const users = table('users', {
|
|
|
30
30
|
const db = flint({ url: './app.db' });
|
|
31
31
|
|
|
32
32
|
// Query
|
|
33
|
-
const user = await db.
|
|
33
|
+
const user = await db.selectFrom(users).where(eq(users.id, 'u1')).single().execute();
|
|
34
34
|
// { id: "u1", name: "Alice", email: "alice@example.com", age: 30, createdAt: Date }
|
|
35
35
|
```
|
|
36
36
|
|
|
@@ -177,12 +177,12 @@ const users = table(
|
|
|
177
177
|
|
|
178
178
|
All `execute()` methods return `Promise<T>` — always `await` regardless of driver.
|
|
179
179
|
|
|
180
|
-
### `db.
|
|
180
|
+
### `db.selectFrom(table)`
|
|
181
181
|
|
|
182
|
-
Start a SELECT query.
|
|
182
|
+
Start a SELECT query. Call `.columns()` to narrow, `.where()` to filter, `.execute()` to run.
|
|
183
183
|
|
|
184
184
|
```ts
|
|
185
|
-
await db.
|
|
185
|
+
await db.selectFrom(users).execute();
|
|
186
186
|
// SELECT * FROM users
|
|
187
187
|
```
|
|
188
188
|
|
|
@@ -191,7 +191,7 @@ await db.select().from(users).execute();
|
|
|
191
191
|
Narrow which columns appear in the result.
|
|
192
192
|
|
|
193
193
|
```ts
|
|
194
|
-
await db.
|
|
194
|
+
await db.selectFrom(users).columns(['id', 'name']).execute();
|
|
195
195
|
// SELECT id, name FROM users
|
|
196
196
|
// Returns: { id: string; name: string }[]
|
|
197
197
|
```
|
|
@@ -201,7 +201,7 @@ await db.select().from(users).columns(['id', 'name']).execute();
|
|
|
201
201
|
Filter rows.
|
|
202
202
|
|
|
203
203
|
```ts
|
|
204
|
-
await db.
|
|
204
|
+
await db.selectFrom(users).where(eq(users.active, true)).execute();
|
|
205
205
|
// SELECT * FROM users WHERE active = 1
|
|
206
206
|
```
|
|
207
207
|
|
|
@@ -210,7 +210,7 @@ await db.select().from(users).where(eq(users.active, true)).execute();
|
|
|
210
210
|
Return one row or null instead of an array. Adds `LIMIT 1`.
|
|
211
211
|
|
|
212
212
|
```ts
|
|
213
|
-
await db.
|
|
213
|
+
await db.selectFrom(users).where(eq(users.id, 'u1')).single().execute();
|
|
214
214
|
// SELECT * FROM users WHERE id = ? LIMIT 1
|
|
215
215
|
// Returns: UserRow | null
|
|
216
216
|
```
|
|
@@ -220,7 +220,7 @@ await db.select().from(users).where(eq(users.id, 'u1')).single().execute();
|
|
|
220
220
|
Sort results. Default direction is `"asc"`.
|
|
221
221
|
|
|
222
222
|
```ts
|
|
223
|
-
await db.
|
|
223
|
+
await db.selectFrom(users).orderBy('name', 'desc').execute();
|
|
224
224
|
// SELECT * FROM users ORDER BY name DESC
|
|
225
225
|
```
|
|
226
226
|
|
|
@@ -229,7 +229,7 @@ await db.select().from(users).orderBy('name', 'desc').execute();
|
|
|
229
229
|
Limit the number of results.
|
|
230
230
|
|
|
231
231
|
```ts
|
|
232
|
-
await db.
|
|
232
|
+
await db.selectFrom(users).limit(10).execute();
|
|
233
233
|
// SELECT * FROM users LIMIT 10
|
|
234
234
|
```
|
|
235
235
|
|
|
@@ -238,7 +238,7 @@ await db.select().from(users).limit(10).execute();
|
|
|
238
238
|
Skip N rows.
|
|
239
239
|
|
|
240
240
|
```ts
|
|
241
|
-
await db.
|
|
241
|
+
await db.selectFrom(users).limit(10).offset(20).execute();
|
|
242
242
|
// SELECT * FROM users LIMIT 10 OFFSET 20
|
|
243
243
|
```
|
|
244
244
|
|
|
@@ -247,7 +247,7 @@ await db.select().from(users).limit(10).offset(20).execute();
|
|
|
247
247
|
Return unique rows.
|
|
248
248
|
|
|
249
249
|
```ts
|
|
250
|
-
await db.
|
|
250
|
+
await db.selectFrom(users).columns(['name']).distinct().execute();
|
|
251
251
|
// SELECT DISTINCT name FROM users
|
|
252
252
|
```
|
|
253
253
|
|
|
@@ -536,7 +536,7 @@ import { sql } from 'flint-orm';
|
|
|
536
536
|
const expr = sql`name = ${'Alice'} AND age > ${18}`;
|
|
537
537
|
// { sql: "name = ? AND age > ?", params: ["Alice", 18] }
|
|
538
538
|
|
|
539
|
-
const result = await db.
|
|
539
|
+
const result = await db.selectFrom(users).where(expr).execute();
|
|
540
540
|
```
|
|
541
541
|
|
|
542
542
|
---
|
|
@@ -595,7 +595,7 @@ import { addTable, dropTable, renameTable, addColumn, dropColumn, renameColumn,
|
|
|
595
595
|
| `dropIndex` | `DROP INDEX ...` |
|
|
596
596
|
| `modifyColumn` | `ALTER TABLE ... ALTER COLUMN ...` |
|
|
597
597
|
| `modifyIndex` | `DROP INDEX IF EXISTS ...; CREATE ...` |
|
|
598
|
-
| `rebuildTable` | Temp table → copy → drop → rename
|
|
598
|
+
| `rebuildTable` | Temp table → copy → drop → rename |
|
|
599
599
|
|
|
600
600
|
---
|
|
601
601
|
|
package/README.md
CHANGED
|
@@ -42,11 +42,11 @@ const db = flint({ url: './app.db' });
|
|
|
42
42
|
await db.insert(users).values({ id: 'u1', name: 'Alice', email: 'alice@example.com' }).execute();
|
|
43
43
|
|
|
44
44
|
// Query
|
|
45
|
-
const adults = await db.
|
|
45
|
+
const adults = await db.selectFrom(users).where(eq(users.age, 18)).execute();
|
|
46
46
|
// ^? { id: string; name: string; email: string; age: number; createdAt: Date }[]
|
|
47
47
|
|
|
48
48
|
// Single row
|
|
49
|
-
const alice = await db.
|
|
49
|
+
const alice = await db.selectFrom(users).where(eq(users.id, 'u1')).single().execute();
|
|
50
50
|
// ^? { id: string; name: string; email: string; age: number; createdAt: Date } | null
|
|
51
51
|
```
|
|
52
52
|
|
|
@@ -118,24 +118,24 @@ type NewUser = InsertRow<typeof users>;
|
|
|
118
118
|
|
|
119
119
|
```ts
|
|
120
120
|
// All rows
|
|
121
|
-
const all = await db.
|
|
121
|
+
const all = await db.selectFrom(users).execute();
|
|
122
122
|
|
|
123
123
|
// With conditions
|
|
124
|
-
const active = await db.
|
|
124
|
+
const active = await db.selectFrom(users).where(eq(users.active, true)).execute();
|
|
125
125
|
|
|
126
126
|
// Narrow columns
|
|
127
|
-
const names = await db.
|
|
127
|
+
const names = await db.selectFrom(users).columns(['id', 'name']).execute();
|
|
128
128
|
// ^? { id: string; name: string }[]
|
|
129
129
|
|
|
130
130
|
// Single row
|
|
131
|
-
const user = await db.
|
|
131
|
+
const user = await db.selectFrom(users).where(eq(users.id, 'u1')).single().execute();
|
|
132
132
|
// ^? { ... } | null
|
|
133
133
|
|
|
134
134
|
// Ordering and pagination
|
|
135
|
-
const page = await db.
|
|
135
|
+
const page = await db.selectFrom(users).orderBy('name', 'asc').limit(10).offset(20).execute();
|
|
136
136
|
|
|
137
137
|
// Distinct
|
|
138
|
-
const unique = await db.
|
|
138
|
+
const unique = await db.selectFrom(users).columns(['email']).distinct().execute();
|
|
139
139
|
```
|
|
140
140
|
|
|
141
141
|
### INSERT
|
|
@@ -236,7 +236,7 @@ await db.batch([db.insert(users).values({ id: 'u1', name: 'Alice' }), db.insert(
|
|
|
236
236
|
import { sql } from 'flint-orm';
|
|
237
237
|
|
|
238
238
|
const expr = sql`name = ${'Alice'} AND age > ${18}`;
|
|
239
|
-
const result = await db.
|
|
239
|
+
const result = await db.selectFrom(users).where(expr).execute();
|
|
240
240
|
|
|
241
241
|
// Direct execution
|
|
242
242
|
await db.$run('CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)');
|
|
@@ -17,10 +17,10 @@ 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
|
-
}): {
|
|
23
|
-
|
|
22
|
+
} & Database.Options): {
|
|
23
|
+
selectFrom: <T extends import("..").AnyTable>(table: T) => import("..").SelectBuilder<T>;
|
|
24
24
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
25
25
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
|
26
26
|
delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<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,10 +18,10 @@ 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
|
-
|
|
23
|
+
} & DatabaseOptions): {
|
|
24
|
+
selectFrom: <T extends import("..").AnyTable>(table: T) => import("..").SelectBuilder<T>;
|
|
24
25
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
25
26
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
|
26
27
|
delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<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,8 +20,8 @@ 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(
|
|
29
|
-
|
|
23
|
+
export declare function flint(options: Config): {
|
|
24
|
+
selectFrom: <T extends import("..").AnyTable>(table: T) => import("..").SelectBuilder<T>;
|
|
30
25
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
31
26
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
|
32
27
|
delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<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,8 +17,8 @@ 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(
|
|
25
|
-
|
|
20
|
+
export declare function flint(options: Config): {
|
|
21
|
+
selectFrom: <T extends import("..").AnyTable>(table: T) => import("..").SelectBuilder<T>;
|
|
26
22
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
27
23
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
|
28
24
|
delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<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,23 +10,25 @@ export declare class TursoSyncExecutor implements Executor {
|
|
|
10
10
|
transaction(fn: () => void | Promise<void>): Promise<void>;
|
|
11
11
|
close(): void;
|
|
12
12
|
}
|
|
13
|
-
export interface
|
|
14
|
-
/** Local path for the synced database files. */
|
|
13
|
+
export interface TursoSyncOptions extends Omit<DatabaseOpts, 'path' | 'url' | 'authToken'> {
|
|
14
|
+
/** Local path for the synced database files (maps to `path` in `@tursodatabase/sync`). */
|
|
15
15
|
url: string;
|
|
16
|
-
/** Remote Turso database URL (
|
|
16
|
+
/** Remote Turso database URL (maps to `url` in `@tursodatabase/sync`). */
|
|
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(
|
|
29
|
-
|
|
30
|
+
export declare function flint(options: TursoSyncOptions): {
|
|
31
|
+
selectFrom: <T extends import("..").AnyTable>(table: T) => import("..").SelectBuilder<T>;
|
|
30
32
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
31
33
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
|
32
34
|
delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<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,14 +14,16 @@ 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
|
-
}):
|
|
23
|
-
|
|
25
|
+
} & Parameters<typeof connect>[1]): {
|
|
26
|
+
selectFrom: <T extends import("..").AnyTable>(table: T) => import("..").SelectBuilder<T>;
|
|
24
27
|
insert: <T extends import("..").AnyTable>(table: T) => import("..").InsertStage1<T>;
|
|
25
28
|
update: <T extends import("..").AnyTable>(table: T) => import("..").UpdateStage1<T>;
|
|
26
29
|
delete: <T extends import("..").AnyTable>(table: T) => import("../query/builder").DeleteBuilder<T, false, keyof import("..").InferRow<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/flint.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Executor } from './executor';
|
|
2
|
-
import { DeleteBuilder } from './query/builder';
|
|
3
|
-
import type { Executable,
|
|
2
|
+
import { SelectBuilder, DeleteBuilder } from './query/builder';
|
|
3
|
+
import type { Executable, InsertStage1, UpdateStage1, JoinSelectStage1 } from './query/builder';
|
|
4
4
|
import type { AnyTable } from './schema/table';
|
|
5
5
|
import type { Condition } from './query/conditions';
|
|
6
6
|
import type { ColumnDef } from './schema/columns';
|
|
7
|
-
export type { Executable,
|
|
7
|
+
export type { Executable, SelectBuilder, InsertStage1, UpdateStage1, JoinSelectStage1, JoinBuilder, SingleJoinBuilder } from './query/builder';
|
|
8
8
|
export type { JoinResult } from './query/builder';
|
|
9
9
|
/**
|
|
10
10
|
* A raw SQL expression with parameters.
|
|
@@ -29,12 +29,12 @@ export interface SQLExpression {
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function createClient(executor: Executor): {
|
|
31
31
|
/**
|
|
32
|
-
* Start a SELECT query —
|
|
32
|
+
* Start a SELECT query — pass a table definition.
|
|
33
33
|
*
|
|
34
34
|
* @example
|
|
35
|
-
* const rows = db.
|
|
35
|
+
* const rows = db.selectFrom(users).execute()
|
|
36
36
|
*/
|
|
37
|
-
|
|
37
|
+
selectFrom: <T extends AnyTable>(table: T) => SelectBuilder<T>;
|
|
38
38
|
/**
|
|
39
39
|
* Start an INSERT — call `.values(row)` next.
|
|
40
40
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { sql, createClient } from './flint';
|
|
2
|
-
export type { SQLExpression, Executable,
|
|
2
|
+
export type { SQLExpression, Executable, SelectBuilder, InsertStage1, UpdateStage1 } from './flint';
|
|
3
3
|
export type { Executor } from './executor';
|
|
4
4
|
export { text, integer, boolean, json, date, real } from './schema/columns';
|
|
5
5
|
export type { ColumnDef, IntegerColumnDef, DateColumnDef, DateColumnDefWithDefault } from './schema/columns';
|
package/dist/query/builder.d.ts
CHANGED
|
@@ -24,12 +24,9 @@ export interface Executable {
|
|
|
24
24
|
params: unknown[];
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
/** Phase 1 of a SELECT — only `.from()` is available. */
|
|
28
|
-
export interface SelectStage1 {
|
|
29
|
-
from<U extends AnyTable>(table: U): SelectBuilder<U>;
|
|
30
|
-
}
|
|
31
27
|
/**
|
|
32
|
-
* Full SELECT builder —
|
|
28
|
+
* Full SELECT builder — created directly via `db.selectFrom(table)`.
|
|
29
|
+
* Entry point: `db.selectFrom(table)`.
|
|
33
30
|
* Returns `InferRow<T>[]` (all columns) from `execute()`.
|
|
34
31
|
* Call `.columns()` to narrow — returns a `NarrowedSelectBuilder`.
|
|
35
32
|
*/
|
|
@@ -46,7 +43,7 @@ export declare class SelectBuilder<T extends AnyTable> implements Executable {
|
|
|
46
43
|
* Returns a `NarrowedSelectBuilder` with a clean `{ id: string; name: string }` return type.
|
|
47
44
|
*
|
|
48
45
|
* @example
|
|
49
|
-
* db.
|
|
46
|
+
* db.selectFrom(users).columns(["id", "name"]).execute()
|
|
50
47
|
* // ^? { id: string; name: string }[]
|
|
51
48
|
*/
|
|
52
49
|
columns<K extends keyof InferRow<T>>(keys: K[]): NarrowedSelectBuilder<T, K>;
|
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;
|
|
@@ -1373,18 +1376,6 @@ function resolveColumns(table, selectedColumns, prefix) {
|
|
|
1373
1376
|
return entries.map(([, c3]) => prefix ? `${prefix}.${c3.name}` : c3.name).join(", ");
|
|
1374
1377
|
}
|
|
1375
1378
|
|
|
1376
|
-
class SelectFromBuilder {
|
|
1377
|
-
#executor;
|
|
1378
|
-
#conditions;
|
|
1379
|
-
constructor(executor, conditions = []) {
|
|
1380
|
-
this.#executor = executor;
|
|
1381
|
-
this.#conditions = conditions;
|
|
1382
|
-
}
|
|
1383
|
-
from(table) {
|
|
1384
|
-
return new SelectBuilder(this.#executor, table._.name, table, this.#conditions);
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
1379
|
class SelectBuilder {
|
|
1389
1380
|
#executor;
|
|
1390
1381
|
#tableName;
|
|
@@ -2281,7 +2272,7 @@ var init_aggregates = () => {};
|
|
|
2281
2272
|
// src/flint.ts
|
|
2282
2273
|
function createClient(executor) {
|
|
2283
2274
|
return {
|
|
2284
|
-
|
|
2275
|
+
selectFrom: (table) => new SelectBuilder(executor, table._.name, table),
|
|
2285
2276
|
insert: (table) => new InsertValuesBuilder(executor, table._.name, table),
|
|
2286
2277
|
update: (table) => new UpdateSetBuilder(executor, table._.name, table),
|
|
2287
2278
|
delete: (table) => new DeleteBuilder(executor, table._.name, table),
|
|
@@ -2370,8 +2361,9 @@ class BunSqliteExecutor {
|
|
|
2370
2361
|
this.#client.close();
|
|
2371
2362
|
}
|
|
2372
2363
|
}
|
|
2373
|
-
function flint(
|
|
2374
|
-
const
|
|
2364
|
+
function flint(options) {
|
|
2365
|
+
const { url, ...opts } = options;
|
|
2366
|
+
const client = new Database(url, Object.keys(opts).length ? opts : undefined);
|
|
2375
2367
|
return createClient(new BunSqliteExecutor(client));
|
|
2376
2368
|
}
|
|
2377
2369
|
var init_bun_sqlite = __esm(() => {
|
|
@@ -3188,8 +3180,9 @@ class BetterSqlite3Executor {
|
|
|
3188
3180
|
this.#client.close();
|
|
3189
3181
|
}
|
|
3190
3182
|
}
|
|
3191
|
-
function flint2(
|
|
3192
|
-
const
|
|
3183
|
+
function flint2(options) {
|
|
3184
|
+
const { url, ...opts } = options;
|
|
3185
|
+
const client = new import_better_sqlite3.default(url, Object.keys(opts).length ? opts : undefined);
|
|
3193
3186
|
return createClient(new BetterSqlite3Executor(client));
|
|
3194
3187
|
}
|
|
3195
3188
|
var import_better_sqlite3;
|
|
@@ -9164,11 +9157,8 @@ class LibsqlExecutor {
|
|
|
9164
9157
|
this.#client.close();
|
|
9165
9158
|
}
|
|
9166
9159
|
}
|
|
9167
|
-
function flint3(
|
|
9168
|
-
const client = createClient2({
|
|
9169
|
-
url: normalizeUrl(details.url),
|
|
9170
|
-
authToken: details.authToken
|
|
9171
|
-
});
|
|
9160
|
+
function flint3(options) {
|
|
9161
|
+
const client = createClient2({ ...options, url: normalizeUrl(options.url) });
|
|
9172
9162
|
return createClient(new LibsqlExecutor(client));
|
|
9173
9163
|
}
|
|
9174
9164
|
var init_libsql = __esm(() => {
|
|
@@ -9245,8 +9235,8 @@ class LibsqlWebExecutor {
|
|
|
9245
9235
|
this.#client.close();
|
|
9246
9236
|
}
|
|
9247
9237
|
}
|
|
9248
|
-
function flint4(
|
|
9249
|
-
const client = createClient3(
|
|
9238
|
+
function flint4(options) {
|
|
9239
|
+
const client = createClient3(options);
|
|
9250
9240
|
return createClient(new LibsqlWebExecutor(client));
|
|
9251
9241
|
}
|
|
9252
9242
|
var init_libsql_web = __esm(() => {
|
|
@@ -11475,6 +11465,46 @@ var init_promise2 = __esm(() => {
|
|
|
11475
11465
|
};
|
|
11476
11466
|
});
|
|
11477
11467
|
|
|
11468
|
+
// src/drivers/lazy-executor.ts
|
|
11469
|
+
class LazyExecutor {
|
|
11470
|
+
#factory;
|
|
11471
|
+
#executor;
|
|
11472
|
+
#promise;
|
|
11473
|
+
constructor(factory) {
|
|
11474
|
+
this.#factory = factory;
|
|
11475
|
+
}
|
|
11476
|
+
async#resolve() {
|
|
11477
|
+
if (this.#executor)
|
|
11478
|
+
return this.#executor;
|
|
11479
|
+
if (!this.#promise) {
|
|
11480
|
+
this.#promise = this.#factory().then((exec2) => {
|
|
11481
|
+
this.#executor = exec2;
|
|
11482
|
+
return exec2;
|
|
11483
|
+
});
|
|
11484
|
+
}
|
|
11485
|
+
return this.#promise;
|
|
11486
|
+
}
|
|
11487
|
+
async all(sql2, params) {
|
|
11488
|
+
const exec2 = await this.#resolve();
|
|
11489
|
+
return exec2.all(sql2, params);
|
|
11490
|
+
}
|
|
11491
|
+
async get(sql2, params) {
|
|
11492
|
+
const exec2 = await this.#resolve();
|
|
11493
|
+
return exec2.get(sql2, params);
|
|
11494
|
+
}
|
|
11495
|
+
async run(sql2, params) {
|
|
11496
|
+
const exec2 = await this.#resolve();
|
|
11497
|
+
return exec2.run(sql2, params);
|
|
11498
|
+
}
|
|
11499
|
+
async transaction(fn) {
|
|
11500
|
+
const exec2 = await this.#resolve();
|
|
11501
|
+
return exec2.transaction(fn);
|
|
11502
|
+
}
|
|
11503
|
+
close() {
|
|
11504
|
+
this.#executor?.close();
|
|
11505
|
+
}
|
|
11506
|
+
}
|
|
11507
|
+
|
|
11478
11508
|
// src/drivers/turso-sync.ts
|
|
11479
11509
|
var exports_turso_sync = {};
|
|
11480
11510
|
__export(exports_turso_sync, {
|
|
@@ -11514,14 +11544,19 @@ class TursoSyncExecutor {
|
|
|
11514
11544
|
this.#db.close();
|
|
11515
11545
|
}
|
|
11516
11546
|
}
|
|
11517
|
-
|
|
11518
|
-
const
|
|
11519
|
-
const
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
|
|
11547
|
+
function flint5(options) {
|
|
11548
|
+
const { url, syncUrl, authToken, ...rest } = options;
|
|
11549
|
+
const localPath = url.includes("://") ? url : resolve2(url);
|
|
11550
|
+
const executor = new LazyExecutor(async () => {
|
|
11551
|
+
const db = await connect2({
|
|
11552
|
+
path: localPath,
|
|
11553
|
+
url: syncUrl,
|
|
11554
|
+
authToken,
|
|
11555
|
+
...rest
|
|
11556
|
+
});
|
|
11557
|
+
return new TursoSyncExecutor(db);
|
|
11523
11558
|
});
|
|
11524
|
-
return createClient(
|
|
11559
|
+
return createClient(executor);
|
|
11525
11560
|
}
|
|
11526
11561
|
var init_turso_sync = __esm(() => {
|
|
11527
11562
|
init_promise2();
|
|
@@ -12099,9 +12134,13 @@ class TursoExecutor {
|
|
|
12099
12134
|
this.#db.close();
|
|
12100
12135
|
}
|
|
12101
12136
|
}
|
|
12102
|
-
|
|
12103
|
-
const
|
|
12104
|
-
|
|
12137
|
+
function flint6(options) {
|
|
12138
|
+
const { url, ...opts } = options;
|
|
12139
|
+
const executor = new LazyExecutor(async () => {
|
|
12140
|
+
const db = await connect3(url, Object.keys(opts).length ? opts : undefined);
|
|
12141
|
+
return new TursoExecutor(db);
|
|
12142
|
+
});
|
|
12143
|
+
return createClient(executor);
|
|
12105
12144
|
}
|
|
12106
12145
|
var init_turso = __esm(() => {
|
|
12107
12146
|
init_promise3();
|
|
@@ -1037,18 +1037,6 @@ function resolveColumns(table, selectedColumns, prefix) {
|
|
|
1037
1037
|
return entries.map(([, c]) => prefix ? `${prefix}.${c.name}` : c.name).join(", ");
|
|
1038
1038
|
}
|
|
1039
1039
|
|
|
1040
|
-
class SelectFromBuilder {
|
|
1041
|
-
#executor;
|
|
1042
|
-
#conditions;
|
|
1043
|
-
constructor(executor, conditions = []) {
|
|
1044
|
-
this.#executor = executor;
|
|
1045
|
-
this.#conditions = conditions;
|
|
1046
|
-
}
|
|
1047
|
-
from(table) {
|
|
1048
|
-
return new SelectBuilder(this.#executor, table._.name, table, this.#conditions);
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
1040
|
class SelectBuilder {
|
|
1053
1041
|
#executor;
|
|
1054
1042
|
#tableName;
|
|
@@ -1945,7 +1933,7 @@ var init_aggregates = () => {};
|
|
|
1945
1933
|
// src/flint.ts
|
|
1946
1934
|
function createClient(executor) {
|
|
1947
1935
|
return {
|
|
1948
|
-
|
|
1936
|
+
selectFrom: (table) => new SelectBuilder(executor, table._.name, table),
|
|
1949
1937
|
insert: (table) => new InsertValuesBuilder(executor, table._.name, table),
|
|
1950
1938
|
update: (table) => new UpdateSetBuilder(executor, table._.name, table),
|
|
1951
1939
|
delete: (table) => new DeleteBuilder(executor, table._.name, table),
|
|
@@ -2033,8 +2021,9 @@ class BetterSqlite3Executor {
|
|
|
2033
2021
|
this.#client.close();
|
|
2034
2022
|
}
|
|
2035
2023
|
}
|
|
2036
|
-
function flint(
|
|
2037
|
-
const
|
|
2024
|
+
function flint(options) {
|
|
2025
|
+
const { url, ...opts } = options;
|
|
2026
|
+
const client = new import_better_sqlite3.default(url, Object.keys(opts).length ? opts : undefined);
|
|
2038
2027
|
return createClient(new BetterSqlite3Executor(client));
|
|
2039
2028
|
}
|
|
2040
2029
|
var import_better_sqlite3;
|
|
@@ -272,18 +272,6 @@ function resolveColumns(table, selectedColumns, prefix) {
|
|
|
272
272
|
return entries.map(([, c]) => prefix ? `${prefix}.${c.name}` : c.name).join(", ");
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
class SelectFromBuilder {
|
|
276
|
-
#executor;
|
|
277
|
-
#conditions;
|
|
278
|
-
constructor(executor, conditions = []) {
|
|
279
|
-
this.#executor = executor;
|
|
280
|
-
this.#conditions = conditions;
|
|
281
|
-
}
|
|
282
|
-
from(table) {
|
|
283
|
-
return new SelectBuilder(this.#executor, table._.name, table, this.#conditions);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
275
|
class SelectBuilder {
|
|
288
276
|
#executor;
|
|
289
277
|
#tableName;
|
|
@@ -1180,7 +1168,7 @@ var init_aggregates = () => {};
|
|
|
1180
1168
|
// src/flint.ts
|
|
1181
1169
|
function createClient(executor) {
|
|
1182
1170
|
return {
|
|
1183
|
-
|
|
1171
|
+
selectFrom: (table) => new SelectBuilder(executor, table._.name, table),
|
|
1184
1172
|
insert: (table) => new InsertValuesBuilder(executor, table._.name, table),
|
|
1185
1173
|
update: (table) => new UpdateSetBuilder(executor, table._.name, table),
|
|
1186
1174
|
delete: (table) => new DeleteBuilder(executor, table._.name, table),
|
|
@@ -1269,8 +1257,9 @@ class BunSqliteExecutor {
|
|
|
1269
1257
|
this.#client.close();
|
|
1270
1258
|
}
|
|
1271
1259
|
}
|
|
1272
|
-
function flint(
|
|
1273
|
-
const
|
|
1260
|
+
function flint(options) {
|
|
1261
|
+
const { url, ...opts } = options;
|
|
1262
|
+
const client = new Database(url, Object.keys(opts).length ? opts : undefined);
|
|
1274
1263
|
return createClient(new BunSqliteExecutor(client));
|
|
1275
1264
|
}
|
|
1276
1265
|
var init_bun_sqlite = __esm(() => {
|
|
@@ -272,18 +272,6 @@ function resolveColumns(table, selectedColumns, prefix) {
|
|
|
272
272
|
return entries.map(([, c]) => prefix ? `${prefix}.${c.name}` : c.name).join(", ");
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
class SelectFromBuilder {
|
|
276
|
-
#executor;
|
|
277
|
-
#conditions;
|
|
278
|
-
constructor(executor, conditions = []) {
|
|
279
|
-
this.#executor = executor;
|
|
280
|
-
this.#conditions = conditions;
|
|
281
|
-
}
|
|
282
|
-
from(table) {
|
|
283
|
-
return new SelectBuilder(this.#executor, table._.name, table, this.#conditions);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
275
|
class SelectBuilder {
|
|
288
276
|
#executor;
|
|
289
277
|
#tableName;
|
|
@@ -1180,7 +1168,7 @@ var init_aggregates = () => {};
|
|
|
1180
1168
|
// src/flint.ts
|
|
1181
1169
|
function createClient(executor) {
|
|
1182
1170
|
return {
|
|
1183
|
-
|
|
1171
|
+
selectFrom: (table) => new SelectBuilder(executor, table._.name, table),
|
|
1184
1172
|
insert: (table) => new InsertValuesBuilder(executor, table._.name, table),
|
|
1185
1173
|
update: (table) => new UpdateSetBuilder(executor, table._.name, table),
|
|
1186
1174
|
delete: (table) => new DeleteBuilder(executor, table._.name, table),
|
|
@@ -5058,18 +5058,6 @@ function resolveColumns(table, selectedColumns, prefix) {
|
|
|
5058
5058
|
return entries.map(([, c]) => prefix ? `${prefix}.${c.name}` : c.name).join(", ");
|
|
5059
5059
|
}
|
|
5060
5060
|
|
|
5061
|
-
class SelectFromBuilder {
|
|
5062
|
-
#executor;
|
|
5063
|
-
#conditions;
|
|
5064
|
-
constructor(executor, conditions = []) {
|
|
5065
|
-
this.#executor = executor;
|
|
5066
|
-
this.#conditions = conditions;
|
|
5067
|
-
}
|
|
5068
|
-
from(table) {
|
|
5069
|
-
return new SelectBuilder(this.#executor, table._.name, table, this.#conditions);
|
|
5070
|
-
}
|
|
5071
|
-
}
|
|
5072
|
-
|
|
5073
5061
|
class SelectBuilder {
|
|
5074
5062
|
#executor;
|
|
5075
5063
|
#tableName;
|
|
@@ -5966,7 +5954,7 @@ var init_aggregates = () => {};
|
|
|
5966
5954
|
// src/flint.ts
|
|
5967
5955
|
function createClient2(executor) {
|
|
5968
5956
|
return {
|
|
5969
|
-
|
|
5957
|
+
selectFrom: (table) => new SelectBuilder(executor, table._.name, table),
|
|
5970
5958
|
insert: (table) => new InsertValuesBuilder(executor, table._.name, table),
|
|
5971
5959
|
update: (table) => new UpdateSetBuilder(executor, table._.name, table),
|
|
5972
5960
|
delete: (table) => new DeleteBuilder(executor, table._.name, table),
|
|
@@ -6049,8 +6037,8 @@ class LibsqlWebExecutor {
|
|
|
6049
6037
|
this.#client.close();
|
|
6050
6038
|
}
|
|
6051
6039
|
}
|
|
6052
|
-
function flint(
|
|
6053
|
-
const client = createClient(
|
|
6040
|
+
function flint(options) {
|
|
6041
|
+
const client = createClient(options);
|
|
6054
6042
|
return createClient2(new LibsqlWebExecutor(client));
|
|
6055
6043
|
}
|
|
6056
6044
|
var init_libsql_web = __esm(() => {
|
|
@@ -6192,18 +6192,6 @@ function resolveColumns(table, selectedColumns, prefix) {
|
|
|
6192
6192
|
return entries.map(([, c]) => prefix ? `${prefix}.${c.name}` : c.name).join(", ");
|
|
6193
6193
|
}
|
|
6194
6194
|
|
|
6195
|
-
class SelectFromBuilder {
|
|
6196
|
-
#executor;
|
|
6197
|
-
#conditions;
|
|
6198
|
-
constructor(executor, conditions = []) {
|
|
6199
|
-
this.#executor = executor;
|
|
6200
|
-
this.#conditions = conditions;
|
|
6201
|
-
}
|
|
6202
|
-
from(table) {
|
|
6203
|
-
return new SelectBuilder(this.#executor, table._.name, table, this.#conditions);
|
|
6204
|
-
}
|
|
6205
|
-
}
|
|
6206
|
-
|
|
6207
6195
|
class SelectBuilder {
|
|
6208
6196
|
#executor;
|
|
6209
6197
|
#tableName;
|
|
@@ -7100,7 +7088,7 @@ var init_aggregates = () => {};
|
|
|
7100
7088
|
// src/flint.ts
|
|
7101
7089
|
function createClient2(executor) {
|
|
7102
7090
|
return {
|
|
7103
|
-
|
|
7091
|
+
selectFrom: (table) => new SelectBuilder(executor, table._.name, table),
|
|
7104
7092
|
insert: (table) => new InsertValuesBuilder(executor, table._.name, table),
|
|
7105
7093
|
update: (table) => new UpdateSetBuilder(executor, table._.name, table),
|
|
7106
7094
|
delete: (table) => new DeleteBuilder(executor, table._.name, table),
|
|
@@ -7189,11 +7177,8 @@ class LibsqlExecutor {
|
|
|
7189
7177
|
this.#client.close();
|
|
7190
7178
|
}
|
|
7191
7179
|
}
|
|
7192
|
-
function flint(
|
|
7193
|
-
const client = createClient({
|
|
7194
|
-
url: normalizeUrl(details.url),
|
|
7195
|
-
authToken: details.authToken
|
|
7196
|
-
});
|
|
7180
|
+
function flint(options) {
|
|
7181
|
+
const client = createClient({ ...options, url: normalizeUrl(options.url) });
|
|
7197
7182
|
return createClient2(new LibsqlExecutor(client));
|
|
7198
7183
|
}
|
|
7199
7184
|
var init_libsql = __esm(() => {
|
|
@@ -2493,18 +2493,6 @@ function resolveColumns(table, selectedColumns, prefix) {
|
|
|
2493
2493
|
return entries.map(([, c]) => prefix ? `${prefix}.${c.name}` : c.name).join(", ");
|
|
2494
2494
|
}
|
|
2495
2495
|
|
|
2496
|
-
class SelectFromBuilder {
|
|
2497
|
-
#executor;
|
|
2498
|
-
#conditions;
|
|
2499
|
-
constructor(executor, conditions = []) {
|
|
2500
|
-
this.#executor = executor;
|
|
2501
|
-
this.#conditions = conditions;
|
|
2502
|
-
}
|
|
2503
|
-
from(table) {
|
|
2504
|
-
return new SelectBuilder(this.#executor, table._.name, table, this.#conditions);
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2508
2496
|
class SelectBuilder {
|
|
2509
2497
|
#executor;
|
|
2510
2498
|
#tableName;
|
|
@@ -3401,7 +3389,7 @@ var init_aggregates = () => {};
|
|
|
3401
3389
|
// src/flint.ts
|
|
3402
3390
|
function createClient(executor) {
|
|
3403
3391
|
return {
|
|
3404
|
-
|
|
3392
|
+
selectFrom: (table) => new SelectBuilder(executor, table._.name, table),
|
|
3405
3393
|
insert: (table) => new InsertValuesBuilder(executor, table._.name, table),
|
|
3406
3394
|
update: (table) => new UpdateSetBuilder(executor, table._.name, table),
|
|
3407
3395
|
delete: (table) => new DeleteBuilder(executor, table._.name, table),
|
|
@@ -3444,6 +3432,46 @@ var init_flint = __esm(() => {
|
|
|
3444
3432
|
init_aggregates();
|
|
3445
3433
|
});
|
|
3446
3434
|
|
|
3435
|
+
// src/drivers/lazy-executor.ts
|
|
3436
|
+
class LazyExecutor {
|
|
3437
|
+
#factory;
|
|
3438
|
+
#executor;
|
|
3439
|
+
#promise;
|
|
3440
|
+
constructor(factory) {
|
|
3441
|
+
this.#factory = factory;
|
|
3442
|
+
}
|
|
3443
|
+
async#resolve() {
|
|
3444
|
+
if (this.#executor)
|
|
3445
|
+
return this.#executor;
|
|
3446
|
+
if (!this.#promise) {
|
|
3447
|
+
this.#promise = this.#factory().then((exec) => {
|
|
3448
|
+
this.#executor = exec;
|
|
3449
|
+
return exec;
|
|
3450
|
+
});
|
|
3451
|
+
}
|
|
3452
|
+
return this.#promise;
|
|
3453
|
+
}
|
|
3454
|
+
async all(sql2, params) {
|
|
3455
|
+
const exec = await this.#resolve();
|
|
3456
|
+
return exec.all(sql2, params);
|
|
3457
|
+
}
|
|
3458
|
+
async get(sql2, params) {
|
|
3459
|
+
const exec = await this.#resolve();
|
|
3460
|
+
return exec.get(sql2, params);
|
|
3461
|
+
}
|
|
3462
|
+
async run(sql2, params) {
|
|
3463
|
+
const exec = await this.#resolve();
|
|
3464
|
+
return exec.run(sql2, params);
|
|
3465
|
+
}
|
|
3466
|
+
async transaction(fn) {
|
|
3467
|
+
const exec = await this.#resolve();
|
|
3468
|
+
return exec.transaction(fn);
|
|
3469
|
+
}
|
|
3470
|
+
close() {
|
|
3471
|
+
this.#executor?.close();
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3447
3475
|
// src/drivers/turso-sync.ts
|
|
3448
3476
|
var exports_turso_sync = {};
|
|
3449
3477
|
__export(exports_turso_sync, {
|
|
@@ -3483,14 +3511,19 @@ class TursoSyncExecutor {
|
|
|
3483
3511
|
this.#db.close();
|
|
3484
3512
|
}
|
|
3485
3513
|
}
|
|
3486
|
-
|
|
3487
|
-
const
|
|
3488
|
-
const
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3514
|
+
function flint(options) {
|
|
3515
|
+
const { url, syncUrl, authToken, ...rest } = options;
|
|
3516
|
+
const localPath = url.includes("://") ? url : resolve(url);
|
|
3517
|
+
const executor = new LazyExecutor(async () => {
|
|
3518
|
+
const db = await connect2({
|
|
3519
|
+
path: localPath,
|
|
3520
|
+
url: syncUrl,
|
|
3521
|
+
authToken,
|
|
3522
|
+
...rest
|
|
3523
|
+
});
|
|
3524
|
+
return new TursoSyncExecutor(db);
|
|
3492
3525
|
});
|
|
3493
|
-
return createClient(
|
|
3526
|
+
return createClient(executor);
|
|
3494
3527
|
}
|
|
3495
3528
|
var init_turso_sync = __esm(() => {
|
|
3496
3529
|
init_promise2();
|
|
@@ -1374,18 +1374,6 @@ function resolveColumns(table, selectedColumns, prefix) {
|
|
|
1374
1374
|
return entries.map(([, c]) => prefix ? `${prefix}.${c.name}` : c.name).join(", ");
|
|
1375
1375
|
}
|
|
1376
1376
|
|
|
1377
|
-
class SelectFromBuilder {
|
|
1378
|
-
#executor;
|
|
1379
|
-
#conditions;
|
|
1380
|
-
constructor(executor, conditions = []) {
|
|
1381
|
-
this.#executor = executor;
|
|
1382
|
-
this.#conditions = conditions;
|
|
1383
|
-
}
|
|
1384
|
-
from(table) {
|
|
1385
|
-
return new SelectBuilder(this.#executor, table._.name, table, this.#conditions);
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
1377
|
class SelectBuilder {
|
|
1390
1378
|
#executor;
|
|
1391
1379
|
#tableName;
|
|
@@ -2282,7 +2270,7 @@ var init_aggregates = () => {};
|
|
|
2282
2270
|
// src/flint.ts
|
|
2283
2271
|
function createClient(executor) {
|
|
2284
2272
|
return {
|
|
2285
|
-
|
|
2273
|
+
selectFrom: (table) => new SelectBuilder(executor, table._.name, table),
|
|
2286
2274
|
insert: (table) => new InsertValuesBuilder(executor, table._.name, table),
|
|
2287
2275
|
update: (table) => new UpdateSetBuilder(executor, table._.name, table),
|
|
2288
2276
|
delete: (table) => new DeleteBuilder(executor, table._.name, table),
|
|
@@ -2325,6 +2313,46 @@ var init_flint = __esm(() => {
|
|
|
2325
2313
|
init_aggregates();
|
|
2326
2314
|
});
|
|
2327
2315
|
|
|
2316
|
+
// src/drivers/lazy-executor.ts
|
|
2317
|
+
class LazyExecutor {
|
|
2318
|
+
#factory;
|
|
2319
|
+
#executor;
|
|
2320
|
+
#promise;
|
|
2321
|
+
constructor(factory) {
|
|
2322
|
+
this.#factory = factory;
|
|
2323
|
+
}
|
|
2324
|
+
async#resolve() {
|
|
2325
|
+
if (this.#executor)
|
|
2326
|
+
return this.#executor;
|
|
2327
|
+
if (!this.#promise) {
|
|
2328
|
+
this.#promise = this.#factory().then((exec) => {
|
|
2329
|
+
this.#executor = exec;
|
|
2330
|
+
return exec;
|
|
2331
|
+
});
|
|
2332
|
+
}
|
|
2333
|
+
return this.#promise;
|
|
2334
|
+
}
|
|
2335
|
+
async all(sql2, params) {
|
|
2336
|
+
const exec = await this.#resolve();
|
|
2337
|
+
return exec.all(sql2, params);
|
|
2338
|
+
}
|
|
2339
|
+
async get(sql2, params) {
|
|
2340
|
+
const exec = await this.#resolve();
|
|
2341
|
+
return exec.get(sql2, params);
|
|
2342
|
+
}
|
|
2343
|
+
async run(sql2, params) {
|
|
2344
|
+
const exec = await this.#resolve();
|
|
2345
|
+
return exec.run(sql2, params);
|
|
2346
|
+
}
|
|
2347
|
+
async transaction(fn) {
|
|
2348
|
+
const exec = await this.#resolve();
|
|
2349
|
+
return exec.transaction(fn);
|
|
2350
|
+
}
|
|
2351
|
+
close() {
|
|
2352
|
+
this.#executor?.close();
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2328
2356
|
// src/drivers/turso.ts
|
|
2329
2357
|
var exports_turso = {};
|
|
2330
2358
|
__export(exports_turso, {
|
|
@@ -2363,9 +2391,13 @@ class TursoExecutor {
|
|
|
2363
2391
|
this.#db.close();
|
|
2364
2392
|
}
|
|
2365
2393
|
}
|
|
2366
|
-
|
|
2367
|
-
const
|
|
2368
|
-
|
|
2394
|
+
function flint(options) {
|
|
2395
|
+
const { url, ...opts } = options;
|
|
2396
|
+
const executor = new LazyExecutor(async () => {
|
|
2397
|
+
const db = await connect(url, Object.keys(opts).length ? opts : undefined);
|
|
2398
|
+
return new TursoExecutor(db);
|
|
2399
|
+
});
|
|
2400
|
+
return createClient(executor);
|
|
2369
2401
|
}
|
|
2370
2402
|
var init_turso = __esm(() => {
|
|
2371
2403
|
init_promise2();
|
package/dist/src/index.js
CHANGED
|
@@ -272,18 +272,6 @@ function resolveColumns(table, selectedColumns, prefix) {
|
|
|
272
272
|
return entries.map(([, c]) => prefix ? `${prefix}.${c.name}` : c.name).join(", ");
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
class SelectFromBuilder {
|
|
276
|
-
#executor;
|
|
277
|
-
#conditions;
|
|
278
|
-
constructor(executor, conditions = []) {
|
|
279
|
-
this.#executor = executor;
|
|
280
|
-
this.#conditions = conditions;
|
|
281
|
-
}
|
|
282
|
-
from(table) {
|
|
283
|
-
return new SelectBuilder(this.#executor, table._.name, table, this.#conditions);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
275
|
class SelectBuilder {
|
|
288
276
|
#executor;
|
|
289
277
|
#tableName;
|
|
@@ -1180,7 +1168,7 @@ var init_aggregates = () => {};
|
|
|
1180
1168
|
// src/flint.ts
|
|
1181
1169
|
function createClient(executor) {
|
|
1182
1170
|
return {
|
|
1183
|
-
|
|
1171
|
+
selectFrom: (table) => new SelectBuilder(executor, table._.name, table),
|
|
1184
1172
|
insert: (table) => new InsertValuesBuilder(executor, table._.name, table),
|
|
1185
1173
|
update: (table) => new UpdateSetBuilder(executor, table._.name, table),
|
|
1186
1174
|
delete: (table) => new DeleteBuilder(executor, table._.name, table),
|
|
@@ -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) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flint-orm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"bin": {
|
|
5
5
|
"flint": "./dist/src/cli.js"
|
|
6
6
|
},
|
|
@@ -87,9 +87,17 @@
|
|
|
87
87
|
"typescript": ">=5.0.0"
|
|
88
88
|
},
|
|
89
89
|
"peerDependenciesMeta": {
|
|
90
|
-
"@libsql/client": {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"
|
|
90
|
+
"@libsql/client": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"@tursodatabase/database": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"@tursodatabase/sync": {
|
|
97
|
+
"optional": true
|
|
98
|
+
},
|
|
99
|
+
"better-sqlite3": {
|
|
100
|
+
"optional": true
|
|
101
|
+
}
|
|
94
102
|
}
|
|
95
103
|
}
|