🐬 A MySQL/MariaDB database client for Gleam, based on mysql-otp
- Gleam 88%
- Erlang 12%
|
SLM
3aafc80b76
All checks were successful
Test / test (push) Successful in 47s
There were two issues: - The environment variables for the whole pipeline were defined at the wrong position (in "on" instead of the YML root), thus the DB password was always empty, which prevented the MySQL service from starting properly. Unfortunately, Forgejo's error reporting for this sort of stuff is pretty lackluster, so the only symptom was that the "mysql" host name was not resolved properly. -> Fixed by removing the indentation of the "env" key. - Debugging this was made more difficult by the second problem: The tests did not specify a host name to connect to. Instead they defaulted to "localhost", which hid the non-existing domain error and replaced it with a connection refused error. -> Fixed my explicitly setting the DB host in the tests. |
||
|---|---|---|
| .forgejo/workflows | chore: Fix CI pipeline & tests | |
| src | renamed .codeberg to .forgejo | |
| test | chore: Fix CI pipeline & tests | |
| .gitignore | fix truncates, add compose file, update deps | |
| CHANGELOG.md | fix truncates, add compose file, update deps | |
| compose.yml | fix truncates, add compose file, update deps | |
| gleam.toml | fix truncates, add compose file, update deps | |
| LICENSE | 📄 lincense added | |
| LICENSE.LESSER | 📝 added LICENSE.LESSER | |
| manifest.toml | fix truncates, add compose file, update deps | |
| README.md | fix truncates, add compose file, update deps | |
shork
A MySQL / MariaDB database client for Gleam, based on MySQL-OTP. Heavily inspired by POG
importshorkpubfnmain(){// Start database connection
letconnection=shork.default_config()|>shork.user("root")|>shork.password("strong_password")|>shork.database("poke")|>shork.connect// A SQL query with one parameter
letquery="select name, hp from pokemon where id = ?"// The decoder for the returned data
letrow_decoder={usename<-decode.field(0,decode.name)usehp<-decode.field(1,decode.int)decode.success(#(name,hp))}// Runs the query
// The int 1 is given as parameter
letassertOk(response)=shork.query(query)|>shork.parameter(shork.int(1))|>shork.returning(row_decoder)|>shork.execute(connection)response.rows|>should.equal([#("bulbasaur",45)])}Further documentation can be found at https://hexdocs.pm/shork.
Development
gleam test # Run the tests
To run tests, a mysql instance must be running with the following parameters:
- host: localhost
- port: 3306
- user: root
- password: root
- database: short_test
You can start it using docker like this:
docker run -d --rm -p 3306:3306 -e MYSQL_ROOT_PASSWORD="root" -e MYSQL_DATABASE=shork_test
mysql
alternatively:
docker compose up
Acknowledgement
This project is kindly supported by binary butterfly.
License
GNU Lesser General Public License (LGPL) version 3 or any later version. Since the LGPL is a set of additional permissions on top of the GPL, both license texts are included in the files LICENSE and LICENSE.LESSER respectively.
In short, LGPL allows you to use the library in non-free software and software with incompatible licenses.