mirror of
https://github.com/allankoechke/turso.git
synced 2026-12-01 17:43:08 +00:00
The serverless driver's main entry point is meant to mirror the native
@tursodatabase/database surface, which has no execute() — it exposes
prepare/run/get/all/iterate/exec/batch/pragma/transaction. Connection.execute()
was a libsql-client-ism on that surface, and it returned the raw protocol
result shape rather than the {changes, lastInsertRowid} / row-array contracts
the sibling methods use.
The libsql compatibility layer keeps its own execute(), which talks to
Session.execute() directly and never went through Connection.execute(), so the
compat surface is unaffected.
Tests: rewrote the serverless integration tests and the serverless-only
conformance tests against exec/run/get/all; tsc and the package build pass.
Both suites need a live TURSO_DATABASE_URL and were not run.
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
import { connect } from "@tursodatabase/serverless";
|
|
|
|
const client = connect({
|
|
url: process.env.TURSO_DATABASE_URL,
|
|
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
});
|
|
|
|
await client.batch(
|
|
[
|
|
"CREATE TABLE IF NOT EXISTS users (email TEXT)",
|
|
"INSERT INTO users VALUES ('first@example.com')",
|
|
"INSERT INTO users VALUES ('second@example.com')",
|
|
"INSERT INTO users VALUES ('third@example.com')",
|
|
],
|
|
"write",
|
|
);
|
|
|
|
// Using the connection-level all method
|
|
const users = await client.all("SELECT * FROM users");
|
|
console.log("Users (all):", users);
|
|
|
|
// Using prepare and get method
|
|
const stmt = client.prepare("SELECT * FROM users LIMIT 1");
|
|
const firstUser = await stmt.get();
|
|
console.log("First user:", firstUser);
|
|
|
|
// Using prepare and all method
|
|
const allUsers = await stmt.all();
|
|
console.log("All users (all):", allUsers);
|
|
|
|
// Using prepare and iterate method
|
|
console.log("Users (iterate):");
|
|
const iterateStmt = client.prepare("SELECT * FROM users");
|
|
for await (const user of iterateStmt.iterate()) {
|
|
console.log(" -", user[0]);
|
|
}
|