The API is built with Rust, using a web server crate called tide.
-
Install the Rust toolchain
-
Install the SQLx CLI. We use it to run DB migrations and create a cached version of the type-checked SQL queries using the
prepare
command.Note: Until version 0.4 is officially released on crates.io, we use a version from master:
cargo install --git https://github.com/launchbadge/sqlx --rev 144dcceb445e804b16258d0dd9e580d6a484a01e sqlx-cli
-
Run the tests to make sure everything is set up correctly:
cargo test
-
Start Docker for Desktop
-
Run locally:
make run-local
After you changed the database schema:
- Run
make prepare
to update sqlx-data.json
After you changed the GraphQL schema:
- Run
make graphql-schema.json
to update graphql-schema.json
To add a new database migration:
- Run
sqlx migrate add <NAME>
, which will create a new file in the migrations folder. - Edit the file and write your migration.
- Run
make prepare
to update the sqlx-data.json file.
rustfmt is used for formatting our rust code. CI will fail if code is not formatted correctly.
To run locally: cargo fmt
Most of the team uses Visual Studio Code with the rust-analyser plugin.
The default formatter for .sql files in VS Code is not PostgreSQL-specific and highlights many words that are not keywords in PostgreSQL. It is worthwhile using some PostgreSQL-specific syntax highlighting to avoid confusion (for example, you could install a plugin like this one and run Cmd+Shift+P
, Change Language Mode
, Configure File Association for '.sql'...
, PGSQL
).