Skip to content

About

A Knex dialect for @libsql/client.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

knex-libsql-client

A Knex dialect for @libsql/client.

Install

npm install knex @libsql/client knex-libsql-client

Usage

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:

mkdir .plans   # or `npx alignfirst plans setup <clone-path>` with the team plans repository
npx -y alignfirst workspace setup

The 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

About

A Knex dialect for @libsql/client.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages