Replies: 1 comment 1 reply
-
Hello, In order to use the PostgreSQL client with built-in pools, you have to selected the Here goes an example using [dependencies]
wtx = { default-features = false, features = ["pool", "postgres", "tokio"], version = "0.17" }
tokio = { features = ["macros", "net", "rt-multi-thread"], version = "1.0" } use std::sync::OnceLock;
use tokio::{net::TcpStream, sync::MutexGuard};
use wtx::{
database::{
client::postgres::{Executor, ExecutorBuffer},
Executor as _, Record,
},
pool::{Pool, PostgresRM, SimplePoolGetElem, SimplePoolResource, SimplePoolTokio},
};
#[tokio::main]
async fn main() -> wtx::Result<()> {
let mut lock = pool().await?;
let record = lock.fetch_with_stmt("SELECT name FROM persons WHERE id = $1", (123456,)).await?;
let name = record.decode::<_, &str>(0)?;
println!("Name: {name}");
Ok(())
}
async fn pool() -> wtx::Result<
SimplePoolGetElem<
MutexGuard<'static, SimplePoolResource<Executor<wtx::Error, ExecutorBuffer, TcpStream>>>,
>,
> {
static POOL: OnceLock<SimplePoolTokio<PostgresRM<wtx::Error, TcpStream>>> = OnceLock::new();
POOL
.get_or_init(|| {
SimplePoolTokio::new(4, PostgresRM::tokio("postgres://USER:PASSWORD@localhost:5432/DB_NAME"))
})
.get(&(), &())
.await
} For more examples, take a look at https://github.com/c410-f3r/wtx/blob/main/wtx-instances/examples/http-server-framework-tokio.rs or https://github.com/c410-f3r/wtx/blob/main/wtx-instances/examples/database-client-postgres-tokio.rs. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hi, how to use Postgres with pool? both
deadpool
orpool
(by wtx itself) is okBeta Was this translation helpful? Give feedback.
All reactions