knex-libsql-client
v0.1.2
Published
Knex dialect for @libsql/client.
Readme
knex-libsql-client
A Knex dialect for @libsql/client.
Install
npm install knex @libsql/client knex-libsql-clientUsage
Local database:
import { createLibsqlKnex } from "knex-libsql-client";
const db = createLibsqlKnex({
connection: {
url: "file:./my.db",
initCommands: ["PRAGMA foreign_keys = ON"],
},
});
const rows = await db("users").select("*");In-memory database:
const db = createLibsqlKnex({
connection: {
url: ":memory:",
initCommands: ["PRAGMA foreign_keys = ON"],
},
});Remote database (Turso / LibSQL server):
const db = createLibsqlKnex({
connection: {
url: "libsql://your-db.turso.io",
authToken: process.env.TURSO_AUTH_TOKEN,
initCommands: ["PRAGMA foreign_keys = ON"],
},
});Connection options
| Option | Description |
| --- | --- |
| url | Database URL. Use file:./path/to/db.sqlite for a local file, :memory: for in-memory, or an https:// / wss:// URL for a remote LibSQL server (e.g. Turso). |
| filename | Alternative to url for local files — converted to a file: URL automatically. |
| authToken | Auth token for remote LibSQL connections. |
| initCommands | Array of SQL statements to execute on each new connection, in order. Useful for PRAGMAs such as PRAGMA foreign_keys = ON. A failure in any command discards the connection. |
Contribute
After a fresh clone:
npm install
mkdir .plans # or `npx alignfirst plans setup <clone-path>` with the team plans repository
npm run workspace -- setupThe tooling runs AlignFirst through npx alignfirst. Install it globally (npm install -g alignfirst) to use the bare alignfirst command.
See DEVELOPERS.md for the development workflow.
License
MIT
