mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-18 00:54:19 +01:00
This package is for serverless access to the Turso Cloud using SQL over HTTP protocol. The purpose of this package is to provide the same interface as `@tursodatabase/turso`, but for serverless environments that cannot host the database engine. The package also provides a `@libsql/client` compatibility layer in the `@tursodatabase/serverless/compat` module for drop-in replacement for existing clients.
21 lines
566 B
JavaScript
21 lines
566 B
JavaScript
import { createClient } from "@tursodatabase/serverless/compat";
|
|
|
|
const client = createClient({
|
|
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",
|
|
);
|
|
|
|
const result = await client.execute("SELECT * FROM users");
|
|
|
|
console.log("Users:", result.rows);
|