1# Database Package
2
3This package provides database operations for the Shelley AI coding agent using SQLite and sqlc.
4
5## Architecture
6
7The database contains two main entities:
8
9- **Conversations**: Represent individual chat sessions with the AI agent
10- **Messages**: Individual messages within conversations (user, agent, or tool messages)
11
12## Testing
13
14Run tests with:
15
16```bash
17go test -v ./db/...
18```
19
20The tests use in-memory SQLite databases and cover all major operations including:
21
22- CRUD operations for conversations and messages
23- Pagination and search functionality
24- JSON data marshalling/unmarshalling
25- Foreign key constraints
26- Transaction handling
27
28## Code Generation
29
30This package uses [sqlc](https://sqlc.dev/) to generate type-safe Go code from SQL queries.
31
32To regenerate code after modifying SQL:
33
34```bash
35go run github.com/sqlc-dev/sqlc/cmd/sqlc generate
36```