October 21, 2021
Without needing to access to the database for code generation. You can generate a file, and reffer to the file on compile time. I use docker to compile for deployment, and i didn't want my container to access to the database on each compilation.
Edit Cargo.toml and add offline feature to sqlx.
sqlx = { version = "0.4.1", features = [ "postgres", "runtime-actix-rustls", "offline" ] }Edit .env and enable SQLX_OFFLINE mode.
SQLX_OFFLINE=trueInstall sqlx-cli, and run cargo sqlx prepare.
cargo install sqlx-cli
cargo sqlx prepareThis will create sqlx-data.json, which has the schema information needed on compile time.