The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | --- |
| 2 | title: Turso |
| 3 | description: Create Turso SQLite databases and query them from your Workers. |
| 4 | --- |
| 5 | |
| 6 | Turso hosts SQLite databases for you. Create them in the same Stack as your Workers, and query them with Effect SQL or Drizzle. |
| 7 | |
| 8 | New here? [Set up credentials](/turso/setup) first, then [build the tutorial](/turso/tutorial/part-1). |
| 9 | |
| 10 | ## Create a database |
| 11 | |
| 12 | Every database lives in a group. The group decides where its databases run. |
| 13 | |
| 14 | ```typescript |
| 15 | import * as Turso from "@alchemy.run/turso"; |
| 16 | |
| 17 | export const Group = Turso.Group("Group", { location: "aws-us-east-1" }); |
| 18 | |
| 19 | export const Db = Effect.gen(function* () { |
| 20 | const group = yield* Group; |
| 21 | return yield* Turso.Database("Db", { |
| 22 | group: group.name, |
| 23 | migrations: "./migrations", |
| 24 | }); |
| 25 | }); |
| 26 | ``` |
| 27 | |
| 28 | Each deploy runs any new migrations. See [Migrations](/turso/migrations). |
| 29 | |
| 30 | ## Query it from a Worker |
| 31 | |
| 32 | `Turso.Connect` gives the Worker the database's URL and a token. Pass it to [Drizzle](/sql/drizzle/libsql) or [Effect SQL](/sql/effect-sql/libsql): |
| 33 | |
| 34 | ```typescript |
| 35 | const conn = yield* Turso.Connect(Db); |
| 36 | const db = yield* Drizzle.LibSQL(conn); |
| 37 | ``` |
| 38 | |
| 39 | See [Connections](/turso/connections). |
| 40 | |
| 41 | ## One database per tenant |
| 42 | |
| 43 | Turso databases are cheap, so you can give each customer their own. `Turso.ManageDatabases` lets a Worker create, query, and delete databases in one group: |
| 44 | |
| 45 | ```typescript |
| 46 | const tenants = yield* Turso.ManageDatabases(Tenants); |
| 47 | const acme = yield* tenants.create("acme"); |
| 48 | const sql = yield* SQL.LibSQL(tenants.connect(acme.name)); |
| 49 | ``` |
| 50 | |
| 51 | The [tutorial](/turso/tutorial/part-1) builds this step by step. The [Database per tenant](/turso/database-per-tenant) guide has the details. |
| 52 | |
| 53 | ## Where next |
| 54 | |
| 55 | - [Groups](/turso/groups) and [Databases](/turso/databases) |
| 56 | - [Tokens](/turso/tokens) for apps outside your Stack |
| 57 | - [Preview databases](/turso/preview-databases), one copy per pull request |
| 58 | - [Team & organization](/turso/organization): invites, members, and settings |