@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 04:45 UTC

main
mdx 106 lines 2.44 KB
Raw
1 ---
2 title: Create & configure databases
3 description: Create, copy, and protect Turso databases.
4 ---
5
6 A Turso database is a SQLite database that lives in a [group](/turso/groups).
7
8 ## Create a database
9
10 ```typescript
11 const group = yield* Turso.Group("Group", { location: "aws-us-east-1" });
12 const db = yield* Turso.Database("Db", { group: group.name });
13 ```
14
15 `db.url` is the URL apps connect to. `db.hostname` and `db.httpUrl` are there too.
16
17 Moving a database to another group creates a new, empty one.
18
19 ## Name it
20
21 ```typescript
22 const db = yield* Turso.Database("Db", { group: group.name, name: "app" });
23 ```
24
25 Without `name`, Alchemy picks one for each stage. Names must be unique in your organization.
26
27 ## Apply migrations
28
29 ```typescript
30 const db = yield* Turso.Database("Db", {
31 group: group.name,
32 migrations: "./migrations",
33 });
34 ```
35
36 See [Migrations](/turso/migrations).
37
38 ## Copy another database
39
40 ```typescript
41 const preview = yield* Turso.Database("Preview", {
42 group: group.name,
43 seed: { type: "database", name: db.name },
44 });
45 ```
46
47 The new database starts with all of `db`'s tables and rows. Add `timestamp` to copy it as it was at that time:
48
49 ```typescript
50 seed: { type: "database", name: db.name, timestamp: "2026-10-07T12:00:00Z" },
51 ```
52
53 `seed` only matters when the database is first created.
54
55 ## Block reads or writes
56
57 ```typescript
58 const db = yield* Turso.Database("Db", {
59 group: group.name,
60 blockWrites: true,
61 });
62 ```
63
64 `blockWrites` makes the database read-only. `blockReads` turns it off completely. Remove the prop and deploy to undo it.
65
66 ## Protect it from deletion
67
68 ```typescript
69 const db = yield* Turso.Database("Db", {
70 group: group.name,
71 deleteProtection: true,
72 });
73 ```
74
75 While this is on, you can't destroy the database. Set it to `false` and deploy first.
76
77 ## Limit who can connect
78
79 ```typescript
80 const db = yield* Turso.Database("Db", {
81 group: group.name,
82 allowedIps: ["203.0.113.0/24"],
83 });
84 ```
85
86 `allowedIps` and `allowedAwsVpcIds` need a paid Turso plan.
87
88 ## Encrypt with your own key
89
90 ```typescript
91 const db = yield* Turso.Database("Db", {
92 group: group.name,
93 encryption: {
94 key: Redacted.make(process.env.DB_KEY!),
95 cipher: "aes256gcm",
96 },
97 });
98 ```
99
100 The key is 32 random bytes, base64-encoded. Changing `encryption` creates a new database. Encryption needs a Pro or Enterprise plan.
101
102 ## Where next
103
104 - [Connections](/turso/connections)
105 - [Preview databases](/turso/preview-databases)
106 - [Database reference](/providers/turso/reference/database)