Crates.io | actix-postgres |
lib.rs | actix-postgres |
version | 0.4.0 |
source | src |
created_at | 2020-02-27 08:24:23.641032 |
updated_at | 2022-03-31 09:35:57.728319 |
description | PostgreSQL integration for Actix framework. |
homepage | |
repository | https://github.com/aoyagikouhei/actix-postgres-rs |
max_upload_size | |
id | 212985 |
size | 8,681 |
PostgreSQL integration for Actix framework.
use actix::prelude::*;
use actix_postgres::{bb8_postgres::tokio_postgres::tls::NoTls, PostgresActor, PostgresMessage};
#[actix_rt::main]
async fn main() {
let path = std::env::var("PG_PATH").unwrap();
let pg_actor = PostgresActor::start(&path, NoTls).unwrap();
let task = PostgresMessage::new(|pool| {
Box::pin(async move {
let connection = pool.get().await?;
connection
.query("SELECT NOW()::TEXT as c", &vec![])
.await
.map_err(|err| err.into())
})
});
let res = pg_actor.send(task).await.unwrap().unwrap();
let val: &str = res[0].get(0);
println!("{}", val);
System::current().stop();
}