flint-orm 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/package.json +15 -3
- package/skills/batch-transactions/SKILL.md +120 -0
- package/skills/define-schema/SKILL.md +212 -0
- package/skills/define-schema/references/column-modifiers.md +176 -0
- package/skills/driver-selection/SKILL.md +180 -0
- package/skills/driver-selection/references/driver-comparison.md +141 -0
- package/skills/run-migrations/SKILL.md +163 -0
- package/skills/setup-client/SKILL.md +142 -0
- package/skills/update-schema/SKILL.md +186 -0
- package/skills/write-queries/SKILL.md +267 -0
- package/skills/write-queries/references/condition-operators.md +220 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: driver-selection
|
|
3
|
+
description: >
|
|
4
|
+
Choose the right driver for your environment: local file, in-memory,
|
|
5
|
+
serverless, or remote. Covers bun:sqlite, better-sqlite3, @libsql/client,
|
|
6
|
+
@libsql/client/web, @tursodatabase/database, @tursodatabase/sync. Load
|
|
7
|
+
when deciding which driver to use or when troubleshooting driver-specific
|
|
8
|
+
issues.
|
|
9
|
+
metadata:
|
|
10
|
+
type: core
|
|
11
|
+
library: flint-orm
|
|
12
|
+
library_version: 0.7.0
|
|
13
|
+
sources:
|
|
14
|
+
- 'kavenlabs/flint-orm:src/entries/bun-sqlite.ts'
|
|
15
|
+
- 'kavenlabs/flint-orm:src/entries/better-sqlite3.ts'
|
|
16
|
+
- 'kavenlabs/flint-orm:src/entries/libsql.ts'
|
|
17
|
+
- 'kavenlabs/flint-orm:src/entries/libsql-web.ts'
|
|
18
|
+
- 'kavenlabs/flint-orm:src/entries/turso.ts'
|
|
19
|
+
- 'kavenlabs/flint-orm:src/entries/turso-sync.ts'
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
# flint-orm — Driver Selection
|
|
23
|
+
|
|
24
|
+
## Setup
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
// bun:sqlite — Bun runtime only, local file
|
|
28
|
+
import { flint } from 'flint-orm/bun-sqlite';
|
|
29
|
+
const db = flint({ url: './app.db' });
|
|
30
|
+
|
|
31
|
+
// better-sqlite3 — Node.js, local file
|
|
32
|
+
import { flint } from 'flint-orm/better-sqlite3';
|
|
33
|
+
const db = flint({ url: './app.db' });
|
|
34
|
+
|
|
35
|
+
// libsql — local file or remote (Turso)
|
|
36
|
+
import { flint } from 'flint-orm/libsql';
|
|
37
|
+
const db = flint({ url: 'libsql://your-db.turso.io', authToken: '...' });
|
|
38
|
+
|
|
39
|
+
// libsql-web — serverless/edge, remote only (no native binary)
|
|
40
|
+
import { flint } from 'flint-orm/libsql-web';
|
|
41
|
+
const db = flint({ url: 'libsql://your-db.turso.io', authToken: '...' });
|
|
42
|
+
|
|
43
|
+
// turso — Turso database
|
|
44
|
+
import { flint } from 'flint-orm/turso';
|
|
45
|
+
const db = flint({ url: 'libsql://your-db.turso.io', authToken: '...' });
|
|
46
|
+
|
|
47
|
+
// turso-sync — Turso with sync support
|
|
48
|
+
import { flint } from 'flint-orm/turso-sync';
|
|
49
|
+
const db = flint({ url: 'libsql://your-db.turso.io', authToken: '...' });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Core Patterns
|
|
53
|
+
|
|
54
|
+
### Local file database
|
|
55
|
+
|
|
56
|
+
Use bun:sqlite (Bun) or better-sqlite3 (Node.js) for local SQLite files:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
// Bun runtime
|
|
60
|
+
import { flint } from 'flint-orm/bun-sqlite';
|
|
61
|
+
const db = flint({ url: './app.db' });
|
|
62
|
+
|
|
63
|
+
// Node.js
|
|
64
|
+
import { flint } from 'flint-orm/better-sqlite3';
|
|
65
|
+
const db = flint({ url: './app.db' });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Remote database (Turso)
|
|
69
|
+
|
|
70
|
+
Use libsql or turso for remote Turso databases:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { flint } from 'flint-orm/libsql';
|
|
74
|
+
const db = flint({
|
|
75
|
+
url: 'libsql://your-db.turso.io',
|
|
76
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Serverless/edge environment
|
|
81
|
+
|
|
82
|
+
Use libsql-web for serverless or edge runtimes (no native binary):
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { flint } from 'flint-orm/libsql-web';
|
|
86
|
+
const db = flint({
|
|
87
|
+
url: 'libsql://your-db.turso.io',
|
|
88
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### In-memory database
|
|
93
|
+
|
|
94
|
+
All drivers support in-memory databases via `:memory:`:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { flint } from 'flint-orm/bun-sqlite';
|
|
98
|
+
const db = flint({ url: ':memory:' });
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Driver Comparison
|
|
102
|
+
|
|
103
|
+
| Driver | Runtime | File URLs | Remote URLs | Serverless | Auth Token |
|
|
104
|
+
|--------|---------|-----------|-------------|------------|------------|
|
|
105
|
+
| bun:sqlite | Bun only | ✅ | ❌ | ❌ | ❌ |
|
|
106
|
+
| better-sqlite3 | Node.js | ✅ | ❌ | ❌ | ❌ |
|
|
107
|
+
| libsql | Bun/Node | ✅ | ✅ | ✅ | ✅ |
|
|
108
|
+
| libsql-web | Any | ❌ | ✅ | ✅ | ✅ |
|
|
109
|
+
| turso | Bun/Node | ✅ | ✅ | ✅ | ✅ |
|
|
110
|
+
| turso-sync | Bun/Node | ✅ | ✅ | ✅ | ✅ |
|
|
111
|
+
|
|
112
|
+
## Common Mistakes
|
|
113
|
+
|
|
114
|
+
### HIGH libsql requires file: prefix for local paths
|
|
115
|
+
|
|
116
|
+
Wrong:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { flint } from 'flint-orm/libsql';
|
|
120
|
+
const db = flint({ url: 'app.db' }); // ERROR: URL_INVALID
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Correct:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { flint } from 'flint-orm/libsql';
|
|
127
|
+
const db = flint({ url: 'file:./app.db' });
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Unlike bun:sqlite and better-sqlite3, the libsql driver requires the `file:` prefix for local file paths.
|
|
131
|
+
|
|
132
|
+
Source: maintainer interview
|
|
133
|
+
|
|
134
|
+
### HIGH Using libsql-web with file: URLs
|
|
135
|
+
|
|
136
|
+
Wrong:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { flint } from 'flint-orm/libsql-web';
|
|
140
|
+
const db = flint({ url: 'file:./app.db' }); // ERROR
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Correct:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
// For local files, use libsql or bun-sqlite
|
|
147
|
+
import { flint } from 'flint-orm/libsql';
|
|
148
|
+
const db = flint({ url: 'file:./app.db' });
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
libsql-web only supports HTTP/WebSocket URLs — it has no native binary and cannot access local files.
|
|
152
|
+
|
|
153
|
+
Source: src/entries/libsql-web.ts
|
|
154
|
+
|
|
155
|
+
### HIGH Missing authToken for remote databases
|
|
156
|
+
|
|
157
|
+
Wrong:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import { flint } from 'flint-orm/libsql';
|
|
161
|
+
const db = flint({ url: 'libsql://my-db.turso.io' }); // Missing authToken
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Correct:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
import { flint } from 'flint-orm/libsql';
|
|
168
|
+
const db = flint({
|
|
169
|
+
url: 'libsql://my-db.turso.io',
|
|
170
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Remote Turso/libsql databases require authentication.
|
|
175
|
+
|
|
176
|
+
Source: maintainer interview
|
|
177
|
+
|
|
178
|
+
## References
|
|
179
|
+
|
|
180
|
+
- [Full driver comparison](references/driver-comparison.md)
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Driver Comparison Reference
|
|
2
|
+
|
|
3
|
+
Detailed comparison of all flint-orm drivers.
|
|
4
|
+
|
|
5
|
+
## bun:sqlite
|
|
6
|
+
|
|
7
|
+
**Runtime:** Bun only
|
|
8
|
+
**Type:** Sync (Promise-wrapped for uniform API)
|
|
9
|
+
**Install:** Built into Bun — no separate install needed
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { flint } from 'flint-orm/bun-sqlite';
|
|
13
|
+
const db = flint({ url: './app.db' });
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Options:**
|
|
17
|
+
- `url: string` — Path to SQLite file or `:memory:`
|
|
18
|
+
|
|
19
|
+
**Limitations:**
|
|
20
|
+
- Only works in Bun runtime
|
|
21
|
+
- No remote database support
|
|
22
|
+
- No authentication support
|
|
23
|
+
|
|
24
|
+
## better-sqlite3
|
|
25
|
+
|
|
26
|
+
**Runtime:** Node.js
|
|
27
|
+
**Type:** Sync (Promise-wrapped for uniform API)
|
|
28
|
+
**Install:** `npm install better-sqlite3`
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { flint } from 'flint-orm/better-sqlite3';
|
|
32
|
+
const db = flint({ url: './app.db' });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Options:**
|
|
36
|
+
- `url: string` — Path to SQLite file or `:memory:`
|
|
37
|
+
|
|
38
|
+
**Limitations:**
|
|
39
|
+
- No remote database support
|
|
40
|
+
- No authentication support
|
|
41
|
+
|
|
42
|
+
## @libsql/client
|
|
43
|
+
|
|
44
|
+
**Runtime:** Bun/Node.js
|
|
45
|
+
**Type:** Async
|
|
46
|
+
**Install:** `npm install @libsql/client`
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { flint } from 'flint-orm/libsql';
|
|
50
|
+
const db = flint({
|
|
51
|
+
url: 'libsql://your-db.turso.io',
|
|
52
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Options:**
|
|
57
|
+
- `url: string` — Local file (`file:./app.db`), remote (`libsql://...`), or in-memory (`:memory:`)
|
|
58
|
+
- `authToken: string` — Required for remote databases
|
|
59
|
+
|
|
60
|
+
**Capabilities:**
|
|
61
|
+
- Local file access
|
|
62
|
+
- Remote database access
|
|
63
|
+
- Serverless compatible
|
|
64
|
+
- Authentication support
|
|
65
|
+
|
|
66
|
+
## @libsql/client/web
|
|
67
|
+
|
|
68
|
+
**Runtime:** Any (browser, edge, serverless)
|
|
69
|
+
**Type:** Async
|
|
70
|
+
**Install:** `npm install @libsql/client`
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { flint } from 'flint-orm/libsql-web';
|
|
74
|
+
const db = flint({
|
|
75
|
+
url: 'libsql://your-db.turso.io',
|
|
76
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Options:**
|
|
81
|
+
- `url: string` — Remote only (`ws://`, `wss://`, `http://`, `https://`)
|
|
82
|
+
- `authToken: string` — Required for remote databases
|
|
83
|
+
|
|
84
|
+
**Capabilities:**
|
|
85
|
+
- No native binary — works in any JavaScript runtime
|
|
86
|
+
- Serverless/edge optimized
|
|
87
|
+
- Authentication support
|
|
88
|
+
|
|
89
|
+
**Limitations:**
|
|
90
|
+
- No local file access (`file:` URLs not supported)
|
|
91
|
+
- No in-memory database support
|
|
92
|
+
|
|
93
|
+
## @tursodatabase/database
|
|
94
|
+
|
|
95
|
+
**Runtime:** Bun/Node.js
|
|
96
|
+
**Type:** Async
|
|
97
|
+
**Install:** `npm install @tursodatabase/database`
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { flint } from 'flint-orm/turso';
|
|
101
|
+
const db = flint({
|
|
102
|
+
url: 'libsql://your-db.turso.io',
|
|
103
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Options:**
|
|
108
|
+
- `url: string` — Local file or remote Turso database
|
|
109
|
+
- `authToken: string` — Required for remote databases
|
|
110
|
+
|
|
111
|
+
## @tursodatabase/sync
|
|
112
|
+
|
|
113
|
+
**Runtime:** Bun/Node.js
|
|
114
|
+
**Type:** Async
|
|
115
|
+
**Install:** `npm install @tursodatabase/sync`
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { flint } from 'flint-orm/turso-sync';
|
|
119
|
+
const db = flint({
|
|
120
|
+
url: 'libsql://your-db.turso.io',
|
|
121
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Options:**
|
|
126
|
+
- `url: string` — Local file or remote Turso database
|
|
127
|
+
- `authToken: string` — Required for remote databases
|
|
128
|
+
|
|
129
|
+
**Capabilities:**
|
|
130
|
+
- Includes sync support for offline-first applications
|
|
131
|
+
|
|
132
|
+
## Decision Guide
|
|
133
|
+
|
|
134
|
+
| Use Case | Recommended Driver |
|
|
135
|
+
|----------|-------------------|
|
|
136
|
+
| Bun runtime, local file | bun:sqlite |
|
|
137
|
+
| Node.js, local file | better-sqlite3 |
|
|
138
|
+
| Remote Turso database | libsql |
|
|
139
|
+
| Serverless/edge | libsql-web |
|
|
140
|
+
| Turso with sync | turso-sync |
|
|
141
|
+
| Testing/prototyping | Any with `:memory:` |
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: run-migrations
|
|
3
|
+
description: >
|
|
4
|
+
Generate and apply schema migrations safely using the CLI or programmatic
|
|
5
|
+
API. Covers flint generate, flint migrate, flint.config.ts, and the
|
|
6
|
+
migration pipeline (serialize → diff → generateSQL). Load when creating
|
|
7
|
+
or applying migrations, or when troubleshooting migration issues.
|
|
8
|
+
metadata:
|
|
9
|
+
type: core
|
|
10
|
+
library: flint-orm
|
|
11
|
+
library_version: 0.7.0
|
|
12
|
+
sources:
|
|
13
|
+
- 'kavenlabs/flint-orm:src/migration/generate.ts'
|
|
14
|
+
- 'kavenlabs/flint-orm:src/migration/migrate.ts'
|
|
15
|
+
- 'kavenlabs/flint-orm:src/migration/sql.ts'
|
|
16
|
+
- 'kavenlabs/flint-orm:src/cli.ts'
|
|
17
|
+
- 'kavenlabs/flint-orm:README.md'
|
|
18
|
+
- 'kavenlabs/flint-orm:API.md'
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
# flint-orm — Migrations
|
|
22
|
+
|
|
23
|
+
## Setup
|
|
24
|
+
|
|
25
|
+
### flint.config.ts
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { defineConfig } from 'flint-orm/config';
|
|
29
|
+
|
|
30
|
+
export default defineConfig({
|
|
31
|
+
driver: 'bun-sqlite', // Must match the driver you import in your app
|
|
32
|
+
database: {
|
|
33
|
+
url: './app.db',
|
|
34
|
+
},
|
|
35
|
+
schema: './src/schema',
|
|
36
|
+
migrations: './flint',
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### CLI commands
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Generate a migration from schema changes
|
|
44
|
+
flint generate
|
|
45
|
+
flint generate --name add_users_table
|
|
46
|
+
flint generate --preview # Show SQL without writing
|
|
47
|
+
|
|
48
|
+
# Apply pending migrations
|
|
49
|
+
flint migrate
|
|
50
|
+
flint migrate --dry-run # Show what would run
|
|
51
|
+
flint migrate --status # Show applied vs pending
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Core Patterns
|
|
55
|
+
|
|
56
|
+
### Generate initial migration
|
|
57
|
+
|
|
58
|
+
After defining your schema, generate the first migration:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
flint generate --name init_schema
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This creates a folder in `./flint/` with:
|
|
65
|
+
- `migration.ts` — The operations to apply
|
|
66
|
+
- `state.json` — Snapshot of the schema
|
|
67
|
+
|
|
68
|
+
### Apply migrations
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
flint migrate
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This:
|
|
75
|
+
1. Reads pending migrations from the migrations directory
|
|
76
|
+
2. Applies them in order within transactions
|
|
77
|
+
3. Records applied migrations in `__flint_migrations` table
|
|
78
|
+
|
|
79
|
+
### Preview before applying
|
|
80
|
+
|
|
81
|
+
Always preview before applying in production:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
flint generate --preview # Review the SQL
|
|
85
|
+
flint migrate --dry-run # Verify what would run
|
|
86
|
+
flint migrate # Apply with confidence
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Programmatic API
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { flint } from 'flint-orm/bun-sqlite';
|
|
93
|
+
import { generate, migrate, getMigrationStatus } from 'flint-orm/migration';
|
|
94
|
+
|
|
95
|
+
const db = flint({ url: './app.db' });
|
|
96
|
+
|
|
97
|
+
// Generate a migration
|
|
98
|
+
await generate([users, posts], './flint', {
|
|
99
|
+
name: 'add_posts',
|
|
100
|
+
interactive: true,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Apply pending migrations
|
|
104
|
+
const result = await migrate(db.$executor, { migrationsDir: './flint' });
|
|
105
|
+
console.log(`Applied: ${result.applied.join(', ')}`);
|
|
106
|
+
|
|
107
|
+
// Check status
|
|
108
|
+
const status = await getMigrationStatus(db.$executor, './flint');
|
|
109
|
+
console.log(`Pending: ${status.pending.length}`);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## How It Works
|
|
113
|
+
|
|
114
|
+
1. `flint generate` serializes your `table()` definitions to JSON
|
|
115
|
+
2. Diffs against the last migration's `state.json`
|
|
116
|
+
3. Detects adds, drops, renames, and safe modifications
|
|
117
|
+
4. Prompts to confirm potential renames (interactive mode)
|
|
118
|
+
5. Writes a migration folder with `migration.ts` + `state.json`
|
|
119
|
+
6. `flint migrate` reads pending migrations and executes them in order
|
|
120
|
+
|
|
121
|
+
## Common Mistakes
|
|
122
|
+
|
|
123
|
+
### HIGH Running migrate without generate first
|
|
124
|
+
|
|
125
|
+
Wrong:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
// Modifying schema, then:
|
|
129
|
+
flint migrate // No migration files exist yet!
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Correct:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
// After schema changes:
|
|
136
|
+
flint generate --name add_users_table
|
|
137
|
+
flint migrate
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`migrate` applies existing migration files — you must generate them first from schema changes.
|
|
141
|
+
|
|
142
|
+
Source: README.md
|
|
143
|
+
|
|
144
|
+
### HIGH Not using --preview or --dry-run before applying
|
|
145
|
+
|
|
146
|
+
Wrong:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
flint generate
|
|
150
|
+
flint migrate // Applies without preview
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Correct:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
flint generate --preview // Review the SQL
|
|
157
|
+
flint migrate --dry-run // Verify what would run
|
|
158
|
+
flint migrate // Apply with confidence
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Migrations can be destructive (dropping columns, rebuilding tables). Always preview first.
|
|
162
|
+
|
|
163
|
+
Source: README.md
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: setup-client
|
|
3
|
+
description: >
|
|
4
|
+
Install flint-orm, choose a driver, and connect to a database. Covers
|
|
5
|
+
flint() factory, driver entry points (bun-sqlite, better-sqlite3, libsql,
|
|
6
|
+
libsql-web, turso, turso-sync), and flint.config.ts configuration. Load
|
|
7
|
+
when setting up a new project or switching drivers.
|
|
8
|
+
metadata:
|
|
9
|
+
type: core
|
|
10
|
+
library: flint-orm
|
|
11
|
+
library_version: 0.7.0
|
|
12
|
+
sources:
|
|
13
|
+
- 'kavenlabs/flint-orm:src/entries/bun-sqlite.ts'
|
|
14
|
+
- 'kavenlabs/flint-orm:src/entries/libsql.ts'
|
|
15
|
+
- 'kavenlabs/flint-orm:src/entries/libsql-web.ts'
|
|
16
|
+
- 'kavenlabs/flint-orm:src/entries/better-sqlite3.ts'
|
|
17
|
+
- 'kavenlabs/flint-orm:README.md'
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
# flint-orm — Client Setup
|
|
21
|
+
|
|
22
|
+
flint-orm is a type-safe, driver-agnostic SQLite ORM for JavaScript. One schema, any driver.
|
|
23
|
+
|
|
24
|
+
## Setup
|
|
25
|
+
|
|
26
|
+
### Install with a driver
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Choose ONE driver (bun:sqlite is built into Bun, no install needed):
|
|
30
|
+
bun add flint-orm # bun:sqlite (sync, Promise-wrapped) — Bun only
|
|
31
|
+
bun add flint-orm better-sqlite3 # better-sqlite3 (sync, Promise-wrapped)
|
|
32
|
+
bun add flint-orm @libsql/client # libsql (async, local or remote)
|
|
33
|
+
bun add flint-orm @libsql/client # libsql-web (async, serverless, no file: support)
|
|
34
|
+
bun add flint-orm @tursodatabase/database # turso (async)
|
|
35
|
+
bun add flint-orm @tursodatabase/sync # turso-sync (async, authToken)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Initialize the client
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { flint } from 'flint-orm/bun-sqlite';
|
|
42
|
+
|
|
43
|
+
const db = flint({ url: './app.db' });
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Create flint.config.ts
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { defineConfig } from 'flint-orm/config';
|
|
50
|
+
|
|
51
|
+
export default defineConfig({
|
|
52
|
+
driver: 'bun-sqlite', // Must match the driver you import in your app
|
|
53
|
+
database: {
|
|
54
|
+
url: './app.db',
|
|
55
|
+
},
|
|
56
|
+
schema: './src/schema',
|
|
57
|
+
migrations: './flint',
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Core Patterns
|
|
62
|
+
|
|
63
|
+
### Connect to a local file
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { flint } from 'flint-orm/bun-sqlite';
|
|
67
|
+
|
|
68
|
+
const db = flint({ url: './app.db' });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Connect to a remote database
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { flint } from 'flint-orm/libsql';
|
|
75
|
+
|
|
76
|
+
const db = flint({
|
|
77
|
+
url: 'libsql://your-db.turso.io',
|
|
78
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Connect in a serverless environment
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { flint } from 'flint-orm/libsql-web';
|
|
86
|
+
|
|
87
|
+
// libsql-web only supports ws://, wss://, http://, https:// URLs
|
|
88
|
+
const db = flint({
|
|
89
|
+
url: 'libsql://your-db.turso.io',
|
|
90
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Common Mistakes
|
|
95
|
+
|
|
96
|
+
### CRITICAL Driver mismatch between config and app
|
|
97
|
+
|
|
98
|
+
Wrong:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// flint.config.ts
|
|
102
|
+
export default defineConfig({ driver: 'bun-sqlite', ... });
|
|
103
|
+
|
|
104
|
+
// app.ts
|
|
105
|
+
import { flint } from 'flint-orm/libsql'; // MISMATCH
|
|
106
|
+
const db = flint({ url: '...' });
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Correct:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
// flint.config.ts
|
|
113
|
+
export default defineConfig({ driver: 'libsql', ... });
|
|
114
|
+
|
|
115
|
+
// app.ts
|
|
116
|
+
import { flint } from 'flint-orm/libsql'; // MATCHES
|
|
117
|
+
const db = flint({ url: '...' });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The CLI uses flint.config.ts to determine which driver to use for migrations, but the app uses whichever driver you import — these must match.
|
|
121
|
+
|
|
122
|
+
Source: maintainer interview
|
|
123
|
+
|
|
124
|
+
### HIGH Using libsql-web for local file databases
|
|
125
|
+
|
|
126
|
+
Wrong:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { flint } from 'flint-orm/libsql-web';
|
|
130
|
+
const db = flint({ url: './app.db' }); // ERROR: file: not supported
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Correct:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { flint } from 'flint-orm/libsql';
|
|
137
|
+
const db = flint({ url: './app.db' });
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
libsql-web only supports ws:, wss:, http:, https: URLs — it has no native binary and cannot access local files. Use the regular libsql driver for local files.
|
|
141
|
+
|
|
142
|
+
Source: src/entries/libsql-web.ts
|