Turso Cheat Sheet
Quick reference for Turso: CLI commands, database operations, libSQL client usage, embedded replicas, and edge deployment. Build fast SQLite-based apps at the edge.
Setup & CLI
| curl -sSfL https://get.tur.so/install.sh | bash | Install the Turso CLI |
| turso auth signup | Create a new Turso account |
| turso auth login | Authenticate the CLI with your Turso account |
| turso auth token | Print your current authentication token |
| turso db create my-db | Create a new database named my-db |
| turso db create my-db --group default | Create a database in a specific group |
| turso db list | List all databases in your account |
| turso db show my-db | Show details and URL for a database |
| turso db tokens create my-db | Generate an auth token for a database |
Database Operations
| turso db shell my-db | Open an interactive SQL shell for a database |
| turso db shell my-db < schema.sql | Execute a SQL file against the database |
| turso db destroy my-db | Delete a database permanently |
| turso db inspect my-db | Inspect database size and row counts |
| turso group create us-east | Create a new database group in a region |
| turso group locations add us-east lax | Add a replica location to a group |
| turso db create my-db --from-dump dump.sql | Create a database from a SQL dump file |
| turso db update my-db --allow-attach | Enable cross-database attach for queries |
Queries
| CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL) | Create a table in Turso (standard SQLite syntax) |
| INSERT INTO users (name) VALUES (\'Alice\') | Insert a row into a table |
| SELECT * FROM users WHERE id = ? | Parameterized query (use ? placeholders) |
| CREATE INDEX idx_users_name ON users (name) | Create an index for faster lookups |
| ALTER TABLE users ADD COLUMN email TEXT | Add a column to an existing table |
| PRAGMA table_info(users) | Show column details for a table |
| SELECT COUNT(*) FROM users | Count all rows in a table |
| .tables | List all tables (in turso db shell) |
Embedded Replicas
| npm install @libsql/client | Install the libSQL client for Node.js |
| const db = createClient({ url: "file:local.db", syncUrl: TURSO_URL, authToken: TOKEN }) | Create a client with an embedded replica |
| await db.sync() | Sync the local embedded replica with the remote database |
| const db = createClient({ url: "file:local.db", syncUrl: TURSO_URL, syncInterval: 60 }) | Auto-sync the replica every 60 seconds |
| const db = createClient({ url: "file:local.db" }) | Use a local-only SQLite database (no remote sync) |
| encryptionKey: "my-secret-key" | Encrypt the local embedded replica at rest |
libSQL Client
| import { createClient } from "@libsql/client" | Import the libSQL client |
| const db = createClient({ url: TURSO_URL, authToken: TOKEN }) | Create a remote-only Turso client |
| const result = await db.execute("SELECT * FROM users") | Execute a simple query |
| await db.execute({ sql: "INSERT INTO users VALUES (?, ?)", args: [1, "Alice"] }) | Execute a parameterized query with args |
| const tx = await db.transaction("write") | Begin a write transaction |
| await tx.execute("INSERT INTO users VALUES (?, ?)", [2, "Bob"]) | Execute a query inside a transaction |
| await tx.commit() | Commit the transaction |
| const batch = await db.batch([ "INSERT INTO ...", "UPDATE ..." ], "write") | Execute multiple statements in a batch |
Try It Live
Test these patterns with our free SQL Formatter. No signup needed.
Open SQL Formatter →
Step-by-Step Guide
Read Guide →