sqlc-gen-crystal v1.0.0
crsql
crsql generates type-checked Crystal methods for PostgreSQL, MySQL, and SQLite. Write a named query against your schema and call it with typed arguments and results from Crystal.
Run your first query · Add crsql to an existing app
Installation
The repository is shootingfly/sqlc-gen-crystal; the shard and the command are both named crsql. Build the command from a release tag:
git clone --branch v1.0.0 https://github.com/shootingfly/sqlc-gen-crystal.git
cd sqlc-gen-crystal
crystal build src/cli.cr --release -o bin/crsql
Or pin it as a development dependency of your application and build it from lib:
development_dependencies:
crsql:
github: shootingfly/sqlc-gen-crystal
version: ~> 1.0
shards install
crystal build lib/crsql/src/cli.cr --release -o bin/crsql
Generated code needs only your database driver at runtime. sqlc 1.31.1 must be on the search path when you run crsql generate. See tool setup.
From a query file to a Crystal call
The quickstart creates an authors table and a named query in db/queries.sql.
-- name: GetAuthor :one
SELECT id, name, bio
FROM authors
WHERE id = sqlc.arg(id);
Run crsql generate from the application directory. After the quickstart inserts the sample row, save this as src/lookup.cr.
require "./db/queries"
App::Store.open(ENV["DATABASE_URL"]) do |queries|
if author = queries.get_author?(id: 1_i64)
puts author.name
end
end
For the SQLite quickstart, run DATABASE_URL=sqlite3:./crsql_dev.db crystal run src/lookup.cr. It prints Ada.
Crystal checks the id argument and result fields at compile time. get_author? returns nil when no row matches. Use get_author when the caller expects exactly one row. See query annotations.
crsql uses sqlc to analyze queries during generation. Commit the generated queries.cr along with the schema and query files. crsql check detects stale output. The deployed application uses the generated code and its database driver.
Documentation
| I want to… | Read |
|---|---|
| Check what my database supports | Feature checklist, PostgreSQL, MySQL, SQLite |
| Configure generation or map a custom type | Configuration |
| Create, read, update, and delete rows | Basic queries, joins, batch operations |
| Deploy, handle failures, or verify a version | Production guide, release verification |
| Review changes or contribute | Changelog, development guide |
sqlc-gen-crystal
- 1
- 0
- 0
- 1
- 3
- about 3 hours ago
- November 30, 2026
MIT License
Mon, 30 Nov 2026 06:27:51 GMT