SQL -> Gleam (sqlc-gen-gleam)
Project Status
this project is currently pre-alpha. it will be released under v1.0.0 once ready for usage.
How it works
This library makes use of a sqlc-gen-json plugin, which it then converts into gleam code.
So in a simplified manner, the pipeline looks like this:
graph LR
SQL[SQL Queries] -- sqlc-gen-json --> JSON[JSON Schema]
JSON -- sql-gen-gleam --> Gleam[Gleam Code]
Installation
$ gleam add sqlc_gen_gleam@1
$ gleam run -m sqlc_gen_gleam
Further documentation can be found at https://hexdocs.pm/sqlc_gen_gleam.
Development
1. Database
There are scripts to spawn MySQL or PostgreSQL docker container:
For example:
$ ./scripts/mysql/docker.sh
# or
$ ./scripts/psql/docker.sh
2. Generating the JSON schema
This library uses the JSON schema, generated by sqlc, to generate gleam code. To generate the JSON with the example schema & queries:
$ ./scripts/sqlc.sh # wrapper for "sqlc generate" with additional parameters
3. Running the project and tests
$ gleam run # Run the project
$ gleam test # Run the tests
Acknowledgements
- This project was heavily inspired by
squirrel
(Hex, GitHub). Thank you @giacomocavalieri! - Thank you to
sqlc
(GitHub, Website)
License
Currently unsupported sqlc functionality
- embeddeding structs (https://docs.sqlc.dev/en/stable/howto/embedding.html)