SeaQL is an ORM for rust with an async runtime compatible with tokio. SeaQL is implemented on top of rust sqlx which means that example code for sqlx should work. For example the axum-login examples.
Entity Code Generation
It’s best to manually set up the entity create as per the guide
An example minimal Cargo.toml file for the entity crate might look like this:
then we can use the cli to generate the entities from the db
The -l flag tells seaql to generate a lib.rs file rather than a mod.rs file.
By default the tool will read DATABASE_URL from the .env file and use that to generate entities.
Migrations
Applying Multiple Changes in the same migration
As seen in the example docs we can use results and await? style syntax to apply multiple operations in the same migration.
Migrations inside the application
We need to make the migrations sub-crate a dependency of the main application:
Cargo.toml
Then we apply Migrator::up() to the database connection as described here
Inline Foreign Key
You don’t need to run separate commands to create foreign keys and in fact in Sqlite you can’t do that as it’s not possible to add foreign keys to existing tables.
Foreign keys can be added as part of a table migration up command