https://github.com/kopera/erlang-sqlc
https://github.com/kopera/erlang-sqlc
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kopera/erlang-sqlc
- Owner: kopera
- License: apache-2.0
- Created: 2024-06-24T10:04:51.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-19T09:58:04.000Z (over 1 year ago)
- Last Synced: 2025-09-23T23:11:25.479Z (9 months ago)
- Language: Erlang
- Size: 30.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# sqlc
SQL compiler for Erlang
## Build
$ rebar3 compile
## Example
```erlang
1> {ok, Module} = sqlc:string(example, "
query by_id(:id uuid) returns user as
select user_id as id, name, avatar_url, created_at
from example.user
where user_id = :id;
").
{ok,{codegen,example,
[{by_id,1}],
[{by_id,[{tree,clause,
{attr,87,[],none},
{clause,[{tree,map_expr,
{attr,0,[],none},
{map_expr,none,[{tree,map_field_exact,{attr,...},{...}}]}}],
none,
[{tree,map_expr,
{attr,88,[],none},
{map_expr,none,
[{tree,map_field_assoc,...},{tree,...}]}}]}}]}]}}
2> io:format("~s~n", [sqlc_module:to_erl(Module)]).
%% @private
-module(example).
-export([by_id/1]).
by_id(#{id := Id}) ->
#{type => query,
statement =>
[<<"select user_id as id, name, avatar_url, created_at\n "
" from example.user\n where user_id = ">>,
<<"(">>,
{parameter, #{key => {example, by_id, id}, value => Id}},
<<"::", "uuid">>,
<<")">>]}.
ok
```