mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
feat: enhance SQLite connection configurations to allow WAL
Updated the Bun and Node SQLite connection implementations to support additional configuration options, including `onCreateConnection`. Introduced tests for connection creation to validate database instance types and ensure proper callback execution. Improved type exports for better integration with existing code.
This commit is contained in:
@@ -63,7 +63,7 @@ import type { BkndConfig } from "bknd";
|
||||
|
||||
export default {
|
||||
connection: { url: "file:data.db" },
|
||||
} as const satisfies BkndConfig;
|
||||
} satisfies BkndConfig;
|
||||
```
|
||||
|
||||
Throughout the documentation, it is assumed you use `bknd.config.ts` to define your connection.
|
||||
@@ -93,17 +93,51 @@ import type { BkndConfig } from "bknd";
|
||||
|
||||
// no connection is required, bknd will use a SQLite database in-memory
|
||||
// this does not work on edge environments!
|
||||
export default {} as const satisfies BkndConfig;
|
||||
export default {} satisfies BkndConfig;
|
||||
|
||||
// or explicitly in-memory
|
||||
export default {
|
||||
connection: { url: ":memory:" },
|
||||
} as const satisfies BkndConfig;
|
||||
} satisfies BkndConfig;
|
||||
|
||||
// or explicitly as a file
|
||||
export default {
|
||||
connection: { url: "file:<path/to/your/database.db>" },
|
||||
} as const satisfies BkndConfig;
|
||||
} satisfies BkndConfig;
|
||||
```
|
||||
|
||||
### Bun SQLite
|
||||
|
||||
You can explicitly use the Bun SQLite adapter by passing the `bunSqlite` function to the `connection` property. This allows further configuration of the database, e.g. enabling WAL mode.
|
||||
|
||||
```typescript title="bknd.config.ts"
|
||||
import { bunSqlite, type BunBkndConfig } from "bknd/adapter/bun";
|
||||
|
||||
export default {
|
||||
connection: bunSqlite({
|
||||
url: "file:<path/to/your/database.db>",
|
||||
onCreateConnection: (db) => {
|
||||
db.run("PRAGMA journal_mode = WAL;");
|
||||
},
|
||||
}),
|
||||
} satisfies BunBkndConfig;
|
||||
```
|
||||
|
||||
### Node.js SQLite
|
||||
|
||||
To use the Node.js SQLite adapter directly, set the `connection` property to the result of the `nodeSqlite` function. This lets you customize the database connection, such as enabling WAL mode.
|
||||
|
||||
```typescript title="bknd.config.ts"
|
||||
import { nodeSqlite, type NodeBkndConfig } from "bknd/adapter/node";
|
||||
|
||||
export default {
|
||||
connection: nodeSqlite({
|
||||
url: "file:<path/to/your/database.db>",
|
||||
onCreateConnection: (db) => {
|
||||
db.exec("PRAGMA journal_mode = WAL;");
|
||||
},
|
||||
}),
|
||||
} satisfies NodeBkndConfig;
|
||||
```
|
||||
|
||||
### LibSQL
|
||||
@@ -118,7 +152,7 @@ export default {
|
||||
url: "libsql://<database>.turso.io",
|
||||
authToken: "<auth-token>",
|
||||
}),
|
||||
} as const satisfies BkndConfig;
|
||||
} satisfies BkndConfig;
|
||||
```
|
||||
|
||||
If you wish to use LibSQL as file, in-memory or make use of [Embedded Replicas](https://docs.turso.tech/features/embedded-replicas/introduction), you have to pass in the `Client` from `@libsql/client`:
|
||||
@@ -134,7 +168,7 @@ const client = createClient({
|
||||
|
||||
export default {
|
||||
connection: libsql(client),
|
||||
} as const satisfies BkndConfig;
|
||||
} satisfies BkndConfig;
|
||||
```
|
||||
|
||||
### Cloudflare D1
|
||||
|
||||
Reference in New Issue
Block a user