remote-sql-libsql
v0.0.7
Published
LibSQL implementation of the remote-sql interface
Maintainers
Readme
remote-sql-libsql
LibSQL implementation of the remote-sql interface.
Overview
remote-sql-libsql provides an implementation of the RemoteSQL interface for LibSQL databases (including Turso), enabling batch transaction workflows with libsql-compatible databases.
Installation
pnpm add remote-sql-libsql @libsql/coreUsage
import { RemoteLibSQL } from 'remote-sql-libsql';
import { createClient } from '@libsql/core';
// Create a LibSQL client
const client = createClient({
url: 'libsql://your-database.turso.io',
authToken: 'your-auth-token'
});
// Wrap the client with RemoteLibSQL
const remoteLibSQL = new RemoteLibSQL(client);
// Prepare and execute statements
const stmt = remoteLibSQL.prepare('SELECT * FROM users WHERE id = ?');
const result = await stmt.bind(userId).all<User>();
// Execute batch transactions
const stmt1 = remoteLibSQL.prepare('INSERT INTO users (name) VALUES (?)').bind('Alice');
const stmt2 = remoteLibSQL.prepare('INSERT INTO users (name) VALUES (?)').bind('Bob');
const results = await remoteLibSQL.batch([stmt1, stmt2]);API
RemoteLibSQL
constructor(client: Client)
Creates a new RemoteLibSQL instance wrapping a LibSQL client from @libsql/core.
prepare(sql: string): SQLPreparedStatement
Creates a prepared statement from a SQL string.
batch<T>(list: SQLPreparedStatement[]): Promise<SQLResult<T>[]>
Executes multiple prepared statements as a batch transaction using LibSQL's native batch API.
LibSQLPreparedStatement
A wrapper around LibSQL's client that implements the SQLPreparedStatement interface.
bind(...values: any[]): SQLPreparedStatement
Binds values to the prepared statement parameters. Returns a new prepared statement with accumulated arguments.
all<T>(): Promise<SQLResult<T>>
Executes the prepared statement with bound arguments and returns all results.
License
MIT
