mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-04 17:04:18 +01:00
Add @tursodatabase/serverless package
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.
This commit is contained in:
36
packages/turso-serverless/examples/remote/index.mjs
Normal file
36
packages/turso-serverless/examples/remote/index.mjs
Normal file
@@ -0,0 +1,36 @@
|
||||
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 execute method
|
||||
const result = await client.execute("SELECT * FROM users");
|
||||
console.log("Users (execute):", result.rows);
|
||||
|
||||
// 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]);
|
||||
}
|
||||
Reference in New Issue
Block a user