tokio-postgres is a database connection tool similar to sqlx. Unlike sqlx, it only focuses on implementing postgresql database connections.
Dependencies
= { = "0.1.0" }
Configuration items
[]
= "postgres://root:12341234@localhost:5432/myapp_development" # Database address to connect to
Components
After configuring the above configuration items, the plugin will automatically register a Postgres
object. This object wraps tokio_postgres::Client
.
;
Extract the Component registered by the plugin
The PgPlugin
plugin automatically registers a Postgres
object for us. We can use Component
to extract this connection pool from AppState. Component
is an axum extractor.
async
Complete code reference postgres-example