Expand description
Postgres Driver
§Examples
Single connection:
use postro::Connection;
let mut conn = Connection::connect_env().await?;
let res = postro::query::<_, _, (i32,String)>("SELECT 420,$1", &mut conn)
.bind("Foo")
.fetch_one()
.await?;
assert_eq!(res.0,420);
assert_eq!(res.1.as_str(),"Foo");
Database connection pooling:
use postro::Pool;
let mut pool = Pool::connect_env().await?;
let mut handles = vec![];
for i in 0..14 {
let mut pool = pool.clone();
let t = tokio::spawn(async move {
postro::execute("INSERT INTO foo(id) VALUES($1)", &mut pool)
.bind(i)
.execute()
.await
});
handles.push(t);
}
for h in handles {
h.await.unwrap();
}
let foos = postro::query::<_, _, (i32,)>("SELECT * FROM foo", &mut pool)
.fetch_all()
.await?;
assert_eq!(foos.len(), 14);
Begin a transaction:
use postro::Connection;
let mut conn = Connection::connect_env().await?;
let mut tx = postro::begin(&mut conn).await?;
let _res = postro::query::<_, _, (i32,String)>("INSERT INTO foo(id) VALUES($1)", &mut tx)
.bind(14)
.execute()
.await?;
// if this failed, `tx` will be droped and transaction is rolledback
fallible_operation()?;
tx.commit().await?;
Re-exports§
pub use sql::SqlExt;
Modules§
- common
- Supporting utility type.
- connection
- The
Connection
type. - encode
- Query parameter encoding.
- error
postro
error types.- executor
- The
Executor
trait. - pool
- Database connection pooling.
- postgres
- Postgres Frontend and Backend Protocol
- query
- Query API types.
- row
- Postgres row operation.
- sql
- Sql string operation.
- transaction
- The
Transaction
type. - transport
- The
PgTransport
trait. - types
- Type integration with external types
Structs§
- Config
- Postgres connection config.
- Connection
- Postgres Connection.
- Error
- All possible error from
postro
library. - Pool
- Database connection pool.
- Pool
Config - Pool configuration builder.
- Row
- Postgres row.
Enums§
- Decode
Error - An error when decoding row value.
Traits§
- Decode
- A type that can be constructed from
Column
. - Encode
- Value that can be encoded to be bound to sql parameter.
- Executor
- A type that can returns a
PgTransport
. - FromRow
- Type that can be constructed from a row.
Functions§
- begin
- Begin transaction with given executor.
- execute
- Same as
query
withRow
as the output. - query
- Entrypoint of the query API.
- query_
row - Same as
query
withRow
as the output. - startup
- Perform a startup message.
Type Aliases§
Derive Macros§
- FromRow
- Foo