Trait bonsaidb_core::connection::Connection
source · [−]pub trait Connection: Send + Sync {
Show 21 methods
fn get<'life0, 'async_trait, C, PrimaryKey>(
&'life0 self,
id: PrimaryKey
) -> Pin<Box<dyn Future<Output = Result<Option<OwnedDocument>, Error>> + Send + 'async_trait>>
where
C: Collection,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send,
C: 'async_trait,
PrimaryKey: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn get_multiple<'life0, 'async_trait, C, PrimaryKey, DocumentIds, I>(
&'life0 self,
ids: DocumentIds
) -> Pin<Box<dyn Future<Output = Result<Vec<OwnedDocument>, Error>> + Send + 'async_trait>>
where
C: Collection,
DocumentIds: IntoIterator<Item = PrimaryKey, IntoIter = I> + Send + Sync,
I: Iterator<Item = PrimaryKey> + Send + Sync,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send + Sync,
C: 'async_trait,
PrimaryKey: 'async_trait,
DocumentIds: 'async_trait,
I: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn list<'life0, 'async_trait, C, R, PrimaryKey>(
&'life0 self,
ids: R,
order: Sort,
limit: Option<usize>
) -> Pin<Box<dyn Future<Output = Result<Vec<OwnedDocument>, Error>> + Send + 'async_trait>>
where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send,
C: 'async_trait,
R: 'async_trait,
PrimaryKey: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn query<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
order: Sort,
limit: Option<usize>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<Vec<Map<V::Key, V::Value>>, Error>> + Send + 'async_trait>>
where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn query_with_docs<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
order: Sort,
limit: Option<usize>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<MappedDocuments<OwnedDocument, V>, Error>> + Send + 'async_trait>>
where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn reduce<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<V::Value, Error>> + Send + 'async_trait>>
where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn reduce_grouped<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<Vec<MappedValue<V::Key, V::Value>>, Error>> + Send + 'async_trait>>
where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn delete_docs<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn apply_transaction<'life0, 'async_trait>(
&'life0 self,
transaction: Transaction
) -> Pin<Box<dyn Future<Output = Result<Vec<OperationResult>, Error>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait;
fn list_executed_transactions<'life0, 'async_trait>(
&'life0 self,
starting_id: Option<u64>,
result_limit: Option<usize>
) -> Pin<Box<dyn Future<Output = Result<Vec<Executed>, Error>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait;
fn last_transaction_id<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Option<u64>, Error>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait;
fn compact<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait;
fn compact_collection<'life0, 'async_trait, C: Collection>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
C: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn compact_key_value_store<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait;
fn collection<C: Collection>(&self) -> Collection<'_, Self, C>
where
Self: Sized,
{ ... }
fn insert<'life0, 'async_trait, C: Collection, PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send, B: Into<Bytes> + Send>(
&'life0 self,
id: Option<PrimaryKey>,
contents: B
) -> Pin<Box<dyn Future<Output = Result<CollectionHeader<C::PrimaryKey>, Error>> + Send + 'async_trait>>
where
C: 'async_trait,
PrimaryKey: 'async_trait,
B: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
{ ... }
fn update<'life0, 'life1, 'async_trait, C: Collection, D: Document<C> + Send + Sync>(
&'life0 self,
doc: &'life1 mut D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
C: 'async_trait,
D: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
{ ... }
fn overwrite<'a, 'life0, 'async_trait, C, PrimaryKey>(
&'life0 self,
id: PrimaryKey,
contents: Vec<u8>
) -> Pin<Box<dyn Future<Output = Result<CollectionHeader<C::PrimaryKey>, Error>> + Send + 'async_trait>>
where
C: Collection,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send,
'a: 'async_trait,
C: 'async_trait,
PrimaryKey: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
{ ... }
fn delete<'life0, 'life1, 'async_trait, C: Collection, H: HasHeader + Send + Sync>(
&'life0 self,
doc: &'life1 H
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where
C: 'async_trait,
H: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
{ ... }
fn view<V: SerializedView>(&self) -> View<'_, Self, V>
where
Self: Sized,
{ ... }
fn query_with_collection_docs<'life0, 'async_trait, V>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
order: Sort,
limit: Option<usize>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<MappedDocuments<CollectionDocument<V::Collection>, V>, Error>> + Send + 'async_trait>>
where
V: SerializedView,
V::Collection: SerializedCollection,
<V::Collection as SerializedCollection>::Contents: Debug,
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
{ ... }
}Expand description
Defines all interactions with a schema::Schema, regardless of whether it
is local or remote.
Required methods
fn get<'life0, 'async_trait, C, PrimaryKey>(
&'life0 self,
id: PrimaryKey
) -> Pin<Box<dyn Future<Output = Result<Option<OwnedDocument>, Error>> + Send + 'async_trait>> where
C: Collection,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send,
C: 'async_trait,
PrimaryKey: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn get<'life0, 'async_trait, C, PrimaryKey>(
&'life0 self,
id: PrimaryKey
) -> Pin<Box<dyn Future<Output = Result<Option<OwnedDocument>, Error>> + Send + 'async_trait>> where
C: Collection,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send,
C: 'async_trait,
PrimaryKey: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Retrieves a stored document from Collection C identified by id.
This is the lower-level API. For better ergonomics, consider using one of:
fn get_multiple<'life0, 'async_trait, C, PrimaryKey, DocumentIds, I>(
&'life0 self,
ids: DocumentIds
) -> Pin<Box<dyn Future<Output = Result<Vec<OwnedDocument>, Error>> + Send + 'async_trait>> where
C: Collection,
DocumentIds: IntoIterator<Item = PrimaryKey, IntoIter = I> + Send + Sync,
I: Iterator<Item = PrimaryKey> + Send + Sync,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send + Sync,
C: 'async_trait,
PrimaryKey: 'async_trait,
DocumentIds: 'async_trait,
I: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn get_multiple<'life0, 'async_trait, C, PrimaryKey, DocumentIds, I>(
&'life0 self,
ids: DocumentIds
) -> Pin<Box<dyn Future<Output = Result<Vec<OwnedDocument>, Error>> + Send + 'async_trait>> where
C: Collection,
DocumentIds: IntoIterator<Item = PrimaryKey, IntoIter = I> + Send + Sync,
I: Iterator<Item = PrimaryKey> + Send + Sync,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send + Sync,
C: 'async_trait,
PrimaryKey: 'async_trait,
DocumentIds: 'async_trait,
I: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Retrieves all documents matching ids. Documents that are not found
are not returned, but no error will be generated.
This is the lower-level API. For better ergonomics, consider using one of:
fn list<'life0, 'async_trait, C, R, PrimaryKey>(
&'life0 self,
ids: R,
order: Sort,
limit: Option<usize>
) -> Pin<Box<dyn Future<Output = Result<Vec<OwnedDocument>, Error>> + Send + 'async_trait>> where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send,
C: 'async_trait,
R: 'async_trait,
PrimaryKey: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn list<'life0, 'async_trait, C, R, PrimaryKey>(
&'life0 self,
ids: R,
order: Sort,
limit: Option<usize>
) -> Pin<Box<dyn Future<Output = Result<Vec<OwnedDocument>, Error>> + Send + 'async_trait>> where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send,
C: 'async_trait,
R: 'async_trait,
PrimaryKey: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Retrieves all documents within the range of ids. Documents that are
not found are not returned, but no error will be generated. To retrieve
all documents, pass in .. for ids.
This is the lower-level API. For better ergonomics, consider using one of:
fn query<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
order: Sort,
limit: Option<usize>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<Vec<Map<V::Key, V::Value>>, Error>> + Send + 'async_trait>> where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn query<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
order: Sort,
limit: Option<usize>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<Vec<Map<V::Key, V::Value>>, Error>> + Send + 'async_trait>> where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Queries for view entries matching View.
This is the lower-level API. For better ergonomics, consider querying
the view using self.view::<View>().query() instead.
The parameters for the query can be customized on the builder returned
from Self::view().
fn query_with_docs<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
order: Sort,
limit: Option<usize>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<MappedDocuments<OwnedDocument, V>, Error>> + Send + 'async_trait>> where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn query_with_docs<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
order: Sort,
limit: Option<usize>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<MappedDocuments<OwnedDocument, V>, Error>> + Send + 'async_trait>> where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Queries for view entries matching View with their source documents.
This is the lower-level API. For better ergonomics, consider querying
the view using self.view::<View>().query_with_docs() instead.
The parameters for the query can be customized on the builder returned
from Self::view().
Reduces the view entries matching View.
This is the lower-level API. For better ergonomics, consider reducing
the view using self.view::<View>().reduce() instead.
The parameters for the query can be customized on the builder returned
from Self::view().
fn reduce_grouped<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<Vec<MappedValue<V::Key, V::Value>>, Error>> + Send + 'async_trait>> where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn reduce_grouped<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<Vec<MappedValue<V::Key, V::Value>>, Error>> + Send + 'async_trait>> where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Reduces the view entries matching View, reducing the values by each
unique key.
This is the lower-level API. For better ergonomics, consider reducing
the view using
self.view::<View>().reduce_grouped() instead.
The parameters for the query can be customized on the builder returned
from Self::view().
fn delete_docs<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>> where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn delete_docs<'life0, 'async_trait, V: SerializedView>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>> where
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Deletes all of the documents associated with this view.
This is the lower-level API. For better ergonomics, consider querying
the view using self.view::<View>().delete_docs() instead.
The parameters for the query can be customized on the builder returned
from Self::view().
fn apply_transaction<'life0, 'async_trait>(
&'life0 self,
transaction: Transaction
) -> Pin<Box<dyn Future<Output = Result<Vec<OperationResult>, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
fn apply_transaction<'life0, 'async_trait>(
&'life0 self,
transaction: Transaction
) -> Pin<Box<dyn Future<Output = Result<Vec<OperationResult>, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Applies a Transaction to the schema::Schema. If any operation in the
Transaction fails, none of the operations will be applied to the
schema::Schema.
Lists executed Transactions from this schema::Schema. By default, a maximum of
1000 entries will be returned, but that limit can be overridden by
setting result_limit. A hard limit of 100,000 results will be
returned. To begin listing after another known transaction_id, pass
transaction_id + 1 into starting_id.
Fetches the last transaction id that has been committed, if any.
Compacts the entire database to reclaim unused disk space.
This process is done by writing data to a new file and swapping the file once the process completes. This ensures that if a hardware failure, power outage, or crash occurs that the original collection data is left untouched.
Errors
Error::Io: an error occurred while compacting the database.
fn compact_collection<'life0, 'async_trait, C: Collection>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where
C: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn compact_collection<'life0, 'async_trait, C: Collection>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where
C: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Compacts the collection to reclaim unused disk space.
This process is done by writing data to a new file and swapping the file once the process completes. This ensures that if a hardware failure, power outage, or crash occurs that the original collection data is left untouched.
Errors
Error::CollectionNotFound: databasenamedoes not exist.Error::Io: an error occurred while compacting the database.
Compacts the key value store to reclaim unused disk space.
This process is done by writing data to a new file and swapping the file once the process completes. This ensures that if a hardware failure, power outage, or crash occurs that the original collection data is left untouched.
Errors
Error::Io: an error occurred while compacting the database.
Provided methods
fn collection<C: Collection>(&self) -> Collection<'_, Self, C> where
Self: Sized,
fn collection<C: Collection>(&self) -> Collection<'_, Self, C> where
Self: Sized,
Accesses a collection for the connected schema::Schema.
fn insert<'life0, 'async_trait, C: Collection, PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send, B: Into<Bytes> + Send>(
&'life0 self,
id: Option<PrimaryKey>,
contents: B
) -> Pin<Box<dyn Future<Output = Result<CollectionHeader<C::PrimaryKey>, Error>> + Send + 'async_trait>> where
C: 'async_trait,
PrimaryKey: 'async_trait,
B: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn insert<'life0, 'async_trait, C: Collection, PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send, B: Into<Bytes> + Send>(
&'life0 self,
id: Option<PrimaryKey>,
contents: B
) -> Pin<Box<dyn Future<Output = Result<CollectionHeader<C::PrimaryKey>, Error>> + Send + 'async_trait>> where
C: 'async_trait,
PrimaryKey: 'async_trait,
B: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Inserts a newly created document into the connected schema::Schema
for the Collection C. If id is None a unique id will be
generated. If an id is provided and a document already exists with that
id, a conflict error will be returned.
This is the lower-level API. For better ergonomics, consider using one of:
Updates an existing document in the connected schema::Schema for the
Collection C. Upon success, doc.revision will be updated with
the new revision.
This is the lower-level API. For better ergonomics, consider using one of:
fn overwrite<'a, 'life0, 'async_trait, C, PrimaryKey>(
&'life0 self,
id: PrimaryKey,
contents: Vec<u8>
) -> Pin<Box<dyn Future<Output = Result<CollectionHeader<C::PrimaryKey>, Error>> + Send + 'async_trait>> where
C: Collection,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send,
'a: 'async_trait,
C: 'async_trait,
PrimaryKey: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn overwrite<'a, 'life0, 'async_trait, C, PrimaryKey>(
&'life0 self,
id: PrimaryKey,
contents: Vec<u8>
) -> Pin<Box<dyn Future<Output = Result<CollectionHeader<C::PrimaryKey>, Error>> + Send + 'async_trait>> where
C: Collection,
PrimaryKey: Into<AnyDocumentId<C::PrimaryKey>> + Send,
'a: 'async_trait,
C: 'async_trait,
PrimaryKey: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Overwrites an existing document, or inserts a new document. Upon success,
doc.revision will be updated with the new revision information.
This is the lower-level API. For better ergonomics, consider using one of:
Removes a Document from the database.
This is the lower-level API. For better ergonomics, consider using one of:
fn view<V: SerializedView>(&self) -> View<'_, Self, V> where
Self: Sized,
fn view<V: SerializedView>(&self) -> View<'_, Self, V> where
Self: Sized,
Initializes View for schema::View V.
fn query_with_collection_docs<'life0, 'async_trait, V>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
order: Sort,
limit: Option<usize>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<MappedDocuments<CollectionDocument<V::Collection>, V>, Error>> + Send + 'async_trait>> where
V: SerializedView,
V::Collection: SerializedCollection,
<V::Collection as SerializedCollection>::Contents: Debug,
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn query_with_collection_docs<'life0, 'async_trait, V>(
&'life0 self,
key: Option<QueryKey<V::Key>>,
order: Sort,
limit: Option<usize>,
access_policy: AccessPolicy
) -> Pin<Box<dyn Future<Output = Result<MappedDocuments<CollectionDocument<V::Collection>, V>, Error>> + Send + 'async_trait>> where
V: SerializedView,
V::Collection: SerializedCollection,
<V::Collection as SerializedCollection>::Contents: Debug,
Self: Sized,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Queries for view entries matching View with their source documents, deserialized.
This is the lower-level API. For better ergonomics, consider querying
the view using self.view::<View>().query_with_collection_docs() instead.
The parameters for the query can be customized on the builder returned
from Self::view().