sqlx
Sqlx Library
Docs - Truly asynchronous - Compile-time checked queries - Database agnostic - Runtime agnostic - Works on different runtimes (async-std / tokio / actix) and TLS backends (native-tls, rustls) - Automatic statement preparation and caching - Transport Layer Security (TLS/SSL) where supported (MySQL and PostgreSQL)
Migrations
- First, establish the required settings for migration to happen in
the
.env
file:- Example:
DATABASE_URL: postgres://postgres:mysecretpassword@localhost:5432/postgres
- Example:
- Create a migration file:
- sqlx migrate add initial-tables This command creates a new
file
migrations/<timestamp>_<name>.sql
for us to write the migration script. Open this file and add the following SQL statements to create our tables.
- sqlx migrate add initial-tables This command creates a new
file
- Apply migration using the sqlx client:
- sqlx migrate run