Skip to main content

rdf_store_postgres/
transaction.rs

1// This is free and unencumbered software released into the public domain.
2
3use crate::{PostgresError, PostgresStore};
4use derive_more::Debug;
5use futures::{Stream, stream};
6use rdf_model::{HeapQuad, HeapQuadPattern, HeapTerm, StatementPattern};
7use rdf_store::{ReadTransaction, WriteTransaction};
8
9#[cfg_attr(doc, aquamarine::aquamarine)]
10/// A transaction for reading and writing statements in PostgreSQL.
11#[derive(Debug)]
12pub struct PostgresTransaction {
13    pub writable: bool,
14}
15
16impl PostgresTransaction {
17    pub async fn begin(_store: &PostgresStore, writable: bool) -> Result<Self, PostgresError> {
18        // TODO
19        Ok(Self { writable })
20    }
21
22    pub fn is_writable(&self) -> bool {
23        self.writable
24    }
25}
26
27impl WriteTransaction for PostgresTransaction {
28    type Error = PostgresError;
29    type Term = HeapTerm; // TODO
30    type Statement = HeapQuad; // TODO
31    type StatementPattern = HeapQuadPattern; // TODO
32
33    async fn rollback(self) -> Result<(), Self::Error> {
34        Ok(()) // TODO
35    }
36
37    async fn commit(self) -> Result<(), Self::Error> {
38        Ok(()) // TODO
39    }
40
41    async fn clear(&mut self) -> Result<(), Self::Error> {
42        Ok(()) // TODO
43    }
44
45    async fn insert(
46        &mut self,
47        _statement: impl Into<Self::Statement> + Send,
48    ) -> Result<(), Self::Error> {
49        Ok(()) // TODO
50    }
51
52    async fn remove(
53        &mut self,
54        _statement: impl Into<Self::Statement> + Send,
55    ) -> Result<(), Self::Error> {
56        Ok(()) // TODO
57    }
58
59    async fn delete(
60        &mut self,
61        _pattern: impl Into<Self::StatementPattern> + Send,
62    ) -> Result<(), Self::Error> {
63        Ok(()) // TODO
64    }
65}
66
67impl ReadTransaction for PostgresTransaction {
68    type Error = PostgresError;
69    type Term = HeapTerm; // TODO
70    type Statement = HeapQuad; // TODO
71    type StatementPattern = HeapQuadPattern; // TODO
72
73    fn r#match(
74        &self,
75        _pattern: impl Into<Self::StatementPattern>,
76    ) -> impl Stream<Item = Result<Self::Statement, Self::Error>> {
77        stream::empty() // TODO
78    }
79}