title: Library example description: Run the repository's Books and Authors REST application with Docker Compose. #
The repository includes a small Books and Authors REST application in
examples/library. It demonstrates schema blocks, shared fields, projections,
composable predicates, generated enums, pagination, mutations, and optional updates.
Run it #
From the repository root, with Docker Compose available:
docker compose -f examples/library/compose.yaml up --build
Compose builds the Go application, starts PostgreSQL 18, and loads the schema and seed data on first startup. No local Go or PostgreSQL installation is required for this mode. The application uses checked-in generated Go files.
curl http://localhost:8080/books
curl http://localhost:8080/authors
If port 8080 is occupied:
LIBRARY_PORT=8081 docker compose -f examples/library/compose.yaml up --build
Explore the source #
| Path | Contents |
|---|---|
examples/library/store/books.stitchql |
Book schema, enum, projection, filters, and mutations |
examples/library/store/authors.stitchql |
Author schema, shared fields, collections, and summary queries |
examples/library/store/*_gen.go |
Generated constructors, results, and execution methods |
examples/library/schema.sql |
Generated schema used by Compose |
examples/library/seed.sql |
Sample authors and books |
examples/library/README.md |
Full endpoint examples and local development commands |
Books have one required author. List queries page by ID, and author collections
keep explicit SQL ordering. The book_status enum generates BookStatus constants;
new books use the database's draft default.
Change the schema #
Schema SQL is generated from the store's blocks:
go run ./cmd/stitchql schema generate ./examples/library/store > examples/library/schema.sql
This does not update an existing Compose volume. Regenerating or rebuilding the application alone does not migrate persisted data. Use a migration for data you need to keep; a disposable demo can be reset as shown below.
Stop or reset #
Stop the stack while keeping its data:
docker compose -f examples/library/compose.yaml down
To remove the demo's persisted data and reinitialize from the schema and seeds:
docker compose -f examples/library/compose.yaml down --volumes
docker compose -f examples/library/compose.yaml up --build
The reset deletes the demo database. The Compose credentials and loopback-bound HTTP service are intended for local exploration.