rdf_store_postgres/
store.rs1use crate::PostgresError;
4use derive_more::Debug;
5use futures::executor::block_on;
6use tokio_postgres::{Client, Connection, NoTls, Socket, tls::NoTlsStream};
7
8pub const DEFAULT_URL: &str = "postgres://postgres@localhost:5432";
12
13#[cfg_attr(doc, aquamarine::aquamarine)]
14#[derive(Debug)]
27pub struct PostgresStore {
28 pub client: Client,
29
30 #[debug(skip)]
31 pub connection: Connection<Socket, NoTlsStream>,
32}
33
34impl PostgresStore {
35 pub async fn open(url: impl AsRef<str>) -> Result<Self, PostgresError> {
36 let (client, connection) = tokio_postgres::connect(url.as_ref(), NoTls).await?;
37 Ok(Self { client, connection })
38 }
39}
40
41impl Default for PostgresStore {
42 fn default() -> Self {
43 block_on(Self::open(DEFAULT_URL))
44 .expect("should connect to postgres://postgres@localhost:5432")
45 }
46}