$npx -y skills add fusengine/agents --skill astro-dbAstro DB — defineDb, defineTable, column types, CRUD with db.select/insert/update/delete, db/config.ts, db/seed.ts, Turso for production, type-safety, integration with Astro Actions. Use for any database operation in an Astro project.
| 1 | # Astro DB |
| 2 | |
| 3 | Type-safe SQL database built into Astro, powered by libSQL/Turso. Use for structured data without external backend services. |
| 4 | |
| 5 | > **⚠️ Deprecation notice**: `@astrojs/db` is **deprecated and no longer actively maintained** (still published on npm, currently v0.21.3 — it has not been removed from Astro 7). For new projects, prefer **Drizzle**, **Kysely**, or a direct **libSQL** client instead. Existing projects can keep using it, but should plan a migration. |
| 6 | |
| 7 | ## Agent Workflow (MANDATORY) |
| 8 | |
| 9 | Before ANY implementation, use `TeamCreate` to spawn 3 agents: |
| 10 | |
| 11 | 1. **fuse-ai-pilot:explore-codebase** - Check existing db/config.ts, tables, and Actions |
| 12 | 2. **fuse-ai-pilot:research-expert** - Verify Astro DB API via Context7/Exa |
| 13 | 3. **mcp__context7__query-docs** - Check Astro 6 DB docs for column types and CRUD |
| 14 | |
| 15 | After implementation, run **fuse-ai-pilot:sniper** for validation. |
| 16 | |
| 17 | --- |
| 18 | |
| 19 | ## Overview |
| 20 | |
| 21 | ### When to Use |
| 22 | |
| 23 | - Storing structured data (comments, users, posts, forms) |
| 24 | - Building full-stack Astro apps without external DB setup |
| 25 | - Combining with Astro Actions for type-safe form handling |
| 26 | - Deploying to production with Turso (libSQL cloud) |
| 27 | - Seeding development data for local testing |
| 28 | |
| 29 | ### Architecture |
| 30 | |
| 31 | ``` |
| 32 | db/ |
| 33 | ├── config.ts # Schema definition (defineDb, defineTable) |
| 34 | └── seed.ts # Development data seeding |
| 35 | ``` |
| 36 | |
| 37 | --- |
| 38 | |
| 39 | ## Core Concepts |
| 40 | |
| 41 | ### Schema Definition |
| 42 | |
| 43 | Define tables in `db/config.ts` using `defineDb` and `defineTable`. Export tables for use in pages and actions. Column types: `column.text()`, `column.number()`, `column.boolean()`, `column.date()`, `column.json()`. |
| 44 | |
| 45 | ### CRUD Operations |
| 46 | |
| 47 | Import `db` and table from `astro:db`. All operations are async and type-safe based on your schema definition. |
| 48 | |
| 49 | ### Turso for Production |
| 50 | |
| 51 | Set `ASTRO_DB_REMOTE_URL` and `ASTRO_DB_APP_TOKEN` environment variables. Run `astro db push` to sync schema to Turso. Use `astro db execute` to run seed scripts against remote DB. |
| 52 | |
| 53 | ### Actions Integration |
| 54 | |
| 55 | Combine with `astro:actions` for end-to-end type safety: Zod input validation → DB operation → typed response. |
| 56 | |
| 57 | --- |
| 58 | |
| 59 | ## Reference Guide |
| 60 | |
| 61 | ### Concepts |
| 62 | |
| 63 | | Topic | Reference | When to Consult | |
| 64 | |-------|-----------|-----------------| |
| 65 | | **Schema Definition** | [schema-definition.md](references/schema-definition.md) | Table structure, column types | |
| 66 | | **CRUD Operations** | [crud-operations.md](references/crud-operations.md) | select, insert, update, delete | |
| 67 | | **Seed Data** | [seed-data.md](references/seed-data.md) | db/seed.ts, remote seeding | |
| 68 | | **Turso Production** | [turso-production.md](references/turso-production.md) | Deployment, env vars, push | |
| 69 | | **Actions Integration** | [actions-integration.md](references/actions-integration.md) | Type-safe form → DB flow | |
| 70 | |
| 71 | ### Templates |
| 72 | |
| 73 | | Template | When to Use | |
| 74 | |----------|-------------| |
| 75 | | [db-config.md](references/templates/db-config.md) | Complete db/config.ts + seed.ts | |
| 76 | | [crud-example.md](references/templates/crud-example.md) | Full CRUD with Actions | |
| 77 | |
| 78 | --- |
| 79 | |
| 80 | ## Best Practices |
| 81 | |
| 82 | 1. **Export tables from config.ts** - Import in pages and actions |
| 83 | 2. **Use Actions for mutations** - Type-safe with Zod validation |
| 84 | 3. **`.returning()` after insert** - Get back inserted rows |
| 85 | 4. **Push before deploy** - Run `astro db push` in CI/CD |
| 86 | 5. **Turso free tier** - 500 databases, generous for production |
| 87 | 6. **New projects: consider Drizzle/Kysely/libSQL instead** - `@astrojs/db` is deprecated and unmaintained; still usable for existing projects, but not recommended as a starting point |