SQL -> Gleam (sqlc-gen-gleam)

Package Version Hex Docs

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

License

Apache License, Version 2.0

Currently unsupported sqlc functionality

Search Document