rdf_store_postgres/
store.rs1use crate::{PostgresError, PostgresTransaction};
4use derive_more::Debug;
5use futures::executor::block_on;
6use rdf_store::Store;
7use tokio_postgres::{Client, Connection, NoTls, Socket, tls::NoTlsStream};
8
9pub const DEFAULT_URL: &str = "postgres://postgres@localhost:5432";
13
14#[cfg_attr(doc, aquamarine::aquamarine)]
15#[derive(Debug)]
28pub struct PostgresStore {
29 pub client: Client,
30
31 #[debug(skip)]
32 pub connection: Connection<Socket, NoTlsStream>,
33}
34
35impl PostgresStore {
36 pub async fn open(url: impl AsRef<str>) -> Result<Self, PostgresError> {
37 let (client, connection) = tokio_postgres::connect(url.as_ref(), NoTls).await?;
38 Ok(Self { client, connection })
39 }
40}
41
42impl Default for PostgresStore {
43 fn default() -> Self {
45 block_on(Self::open(DEFAULT_URL))
46 .expect("should connect to postgres://postgres@localhost:5432")
47 }
48}
49
50impl Store for PostgresStore {
51 type Error = PostgresError;
52 type Read = PostgresTransaction;
53 type Write = PostgresTransaction;
54
55 async fn read(&mut self) -> Result<Self::Read, Self::Error> {
56 todo!() }
58
59 async fn write(&mut self) -> Result<Self::Write, Self::Error> {
60 todo!() }
62}