Dependencies
= { = "<version>", = ["mysql"] }
You can replace postgres
, mysql
, sqlite
feature to select the appropriate database driver.
optional features:
with-json
with-chrono
with-rust_decimal
with-bigdecimal
with-uuid
with-time
Configuration items
[]
= "postgres://root:123456@localhost:5432/pg_db" # Database address
= 1 # Minimum number of connections in the connection pool, the default value is 1
= 10 # Maximum number of connections in the connection pool, the default value is 10
= 30000 # Connection timeout, in milliseconds, default 30s
= 600000 # Connection idle time, in milliseconds, default 10min
= 1800000 # Maximum connection survival time, in milliseconds, default 30min
Components
After configuring the above configuration items, the plugin will automatically register a ConnectPool
connection pool object. This object is an alias for sqlx::AnyPool
.
pub type ConnectPool = AnyPool;
Extract the Component registered by the plugin
The SqlxPlugin
plugin automatically registers a Sqlx connection pool component for us. We can use Component
to extract this connection pool from AppState. Component
is an axum extractor.
use ;
use get;
use Component;
use Result;
use Context;
async
Complete code reference sqlx-example