Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage trait API changes #268

Merged
merged 28 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c5f82a6
Changes for new storage provider API
sandreae Jan 5, 2023
8c86baf
Remove SchemaStore trait
sandreae Jan 5, 2023
120ba3b
Rename SqlStorage to SqlStore
sandreae Jan 5, 2023
9384964
Move storage types into own module
sandreae Jan 5, 2023
d4c4809
Consistent exporting from models module
sandreae Jan 5, 2023
d968eab
Remove outdated comment
sandreae Jan 9, 2023
103a076
Update p2panda_rs
sandreae Jan 9, 2023
46125c3
Remove use of deprecated conversion traits on StorageEntry
sandreae Jan 9, 2023
9df58ba
Remove use of EntryWithOperation trait
sandreae Jan 9, 2023
2ec7a66
Merge branch 'main' into storage-trait-changes
sandreae Jan 9, 2023
cd38f25
Introduce StorageDocument struct
sandreae Jan 17, 2023
24124e4
Add document_id column to document_views table
sandreae Jan 17, 2023
9559be5
Introduce DocumentRow struct
sandreae Jan 17, 2023
fe33b15
Complete re-write of DocumentStore (with docs ;-p)
sandreae Jan 17, 2023
c7b9946
Update Cargo.lock
sandreae Jan 17, 2023
a7b5c02
Update all effected modules
sandreae Jan 17, 2023
7c99dbd
Make the ugly SQL pretty
sandreae Feb 10, 2023
5d53e0a
Use ref for p2panda dependency
sandreae Feb 10, 2023
64ea9ee
Use where for readability
sandreae Feb 10, 2023
621a214
Correct SqlStore doc string
sandreae Feb 10, 2023
1526cba
Typo
sandreae Feb 10, 2023
a4d6f4d
License header
sandreae Feb 10, 2023
833fcce
Docs for all db modules
sandreae Feb 10, 2023
2c334a3
Re-organize db modules a little
sandreae Feb 10, 2023
1a5a036
fmt
sandreae Feb 10, 2023
208a92e
Update CHANGELOG
sandreae Feb 10, 2023
d281bef
Merge branch 'main' into storage-trait-changes
sandreae Feb 10, 2023
f242db9
Improve CHANGELOG entry
sandreae Feb 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions aquadoggo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ lipmaa-link = "^0.2.2"
log = "^0.4.17"
once_cell = "^1.12.0"
openssl-probe = "^0.1.5"
p2panda-rs = { version = "^0.6.0", features = [
p2panda-rs = { git = "https://github.com/p2panda/p2panda", branch = "storage-trait-changes", features = [
sandreae marked this conversation as resolved.
Show resolved Hide resolved
"storage-provider",
] }
serde = { version = "^1.0.144", features = ["derive"] }
Expand Down Expand Up @@ -66,7 +66,7 @@ env_logger = "^0.9.0"
http = "^0.2.8"
hyper = "^0.14.19"
once_cell = "^1.12.0"
p2panda-rs = { version = "^0.6.0", features = [
p2panda-rs = { git = "https://github.com/p2panda/p2panda", branch = "storage-trait-changes", features = [
sandreae marked this conversation as resolved.
Show resolved Hide resolved
"test-utils",
"storage-provider",
] }
Expand Down
3 changes: 3 additions & 0 deletions aquadoggo/migrations/20230114140233_alter-documents.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- SPDX-License-Identifier: AGPL-3.0-or-later

ALTER TABLE document_views ADD COLUMN document_id TEXT NOT NULL;
18 changes: 10 additions & 8 deletions aquadoggo/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
use std::ops::Deref;
use std::sync::Arc;

use p2panda_rs::storage_provider::traits::StorageProvider;
use p2panda_rs::storage_provider::traits::{DocumentStore, EntryStore, LogStore, OperationStore};

use crate::config::Configuration;
use crate::db::provider::SqlStorage;
use crate::db::sql_store::SqlStore;
use crate::schema::SchemaProvider;

/// Inner data shared across all services.
#[derive(Debug)]
pub struct Data<S: StorageProvider> {
pub struct Data<S: EntryStore + OperationStore + LogStore + DocumentStore> {
/// Node configuration.
pub config: Configuration,

Expand All @@ -22,7 +22,7 @@ pub struct Data<S: StorageProvider> {
pub schema_provider: SchemaProvider,
}

impl<S: StorageProvider> Data<S> {
impl<S: EntryStore + OperationStore + LogStore + DocumentStore> Data<S> {
pub fn new(store: S, config: Configuration, schema_provider: SchemaProvider) -> Self {
Self {
config,
Expand All @@ -34,22 +34,24 @@ impl<S: StorageProvider> Data<S> {

/// Data shared across all services.
#[derive(Debug)]
pub struct Context<S: StorageProvider = SqlStorage>(pub Arc<Data<S>>);
pub struct Context<S: EntryStore + OperationStore + LogStore + DocumentStore = SqlStore>(
sandreae marked this conversation as resolved.
Show resolved Hide resolved
pub Arc<Data<S>>,
);

impl<S: StorageProvider> Context<S> {
impl<S: EntryStore + OperationStore + LogStore + DocumentStore> Context<S> {
/// Returns a new instance of `Context`.
pub fn new(store: S, config: Configuration, schema_provider: SchemaProvider) -> Self {
Self(Arc::new(Data::new(store, config, schema_provider)))
}
}

impl<S: StorageProvider> Clone for Context<S> {
impl<S: EntryStore + OperationStore + LogStore + DocumentStore> Clone for Context<S> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}

impl<S: StorageProvider> Deref for Context<S> {
impl<S: EntryStore + OperationStore + LogStore + DocumentStore> Deref for Context<S> {
type Target = Data<S>;

fn deref(&self) -> &Self::Target {
Expand Down
8 changes: 6 additions & 2 deletions aquadoggo/src/db/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use p2panda_rs::schema::error::{SchemaError, SchemaIdError};
use p2panda_rs::schema::system::SystemSchemaError;
use p2panda_rs::storage_provider::error::DocumentStorageError;
use p2panda_rs::storage_provider::error::{DocumentStorageError, OperationStorageError};

/// `SQLStorage` errors.
#[derive(thiserror::Error, Debug)]
pub enum SqlStorageError {
pub enum SqlStoreError {
#[error("SQL query failed: {0}")]
Transaction(String),

Expand Down Expand Up @@ -37,4 +37,8 @@ pub enum SchemaStoreError {
/// Error returned from `DocumentStore` methods.
#[error(transparent)]
DocumentStorageError(#[from] DocumentStorageError),

/// Error returned from `OperationStore` methods.
#[error(transparent)]
OperationStorageError(#[from] OperationStorageError),
}
4 changes: 2 additions & 2 deletions aquadoggo/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use sqlx::migrate::MigrateDatabase;

pub mod errors;
pub mod models;
pub mod provider;
pub mod sql_store;
pub mod stores;
pub mod traits;
pub mod types;
pub mod utils;

/// Re-export of generic connection pool type.
Expand Down
19 changes: 19 additions & 0 deletions aquadoggo/src/db/models/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,22 @@ pub struct DocumentViewFieldRow {
/// The actual value contained in this field.
pub value: String,
}

/// A struct representing a single row of a document table.
#[derive(FromRow, Debug, Clone)]
pub struct DocumentRow {
/// The id of this document
pub document_id: String,

/// The id of this documents most recent view.
pub document_view_id: String,

/// The id of the author of this document.
pub public_key: String,

/// The id of this documents schema.
pub schema_id: String,

/// Flag for if this document is deleted.
pub is_deleted: bool,
}
3 changes: 2 additions & 1 deletion aquadoggo/src/db/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

pub mod document;
mod document;
mod entry;
mod log;
mod operation;
mod task;

pub use self::log::LogRow;
pub use document::{DocumentRow, DocumentViewFieldRow};
pub use entry::EntryRow;
pub use operation::{OperationFieldsJoinedRow, OperationRow};
pub use task::TaskRow;
157 changes: 0 additions & 157 deletions aquadoggo/src/db/provider.rs

This file was deleted.

16 changes: 16 additions & 0 deletions aquadoggo/src/db/sql_store.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

use crate::db::Pool;

/// Sql based storage that implements `StorageProvider`.
sandreae marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Clone, Debug)]
pub struct SqlStore {
pub(crate) pool: Pool,
}

impl SqlStore {
/// Create a new `SqlStore` using the provided db `Pool`.
pub fn new(pool: Pool) -> Self {
Self { pool }
}
}
Loading