Trait bonsaidb_core::connection::LowLevelConnection
source · [−]pub trait LowLevelConnection: HasSession {
Show 28 methods
fn schematic(&self) -> &Schematic;
fn apply_transaction(
&self,
transaction: Transaction
) -> Result<Vec<OperationResult>, Error>;
fn get_from_collection(
&self,
id: DocumentId,
collection: &CollectionName
) -> Result<Option<OwnedDocument>, Error>;
fn get_multiple_from_collection(
&self,
ids: &[DocumentId],
collection: &CollectionName
) -> Result<Vec<OwnedDocument>, Error>;
fn list_from_collection(
&self,
ids: Range<DocumentId>,
order: Sort,
limit: Option<u32>,
collection: &CollectionName
) -> Result<Vec<OwnedDocument>, Error>;
fn list_headers_from_collection(
&self,
ids: Range<DocumentId>,
order: Sort,
limit: Option<u32>,
collection: &CollectionName
) -> Result<Vec<Header>, Error>;
fn count_from_collection(
&self,
ids: Range<DocumentId>,
collection: &CollectionName
) -> Result<u64, Error>;
fn compact_collection_by_name(
&self,
collection: CollectionName
) -> Result<(), Error>;
fn query_by_name(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<Vec<Serialized>, Error>;
fn query_by_name_with_docs(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<MappedSerializedDocuments, Error>;
fn reduce_by_name(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
access_policy: AccessPolicy
) -> Result<Vec<u8>, Error>;
fn reduce_grouped_by_name(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
access_policy: AccessPolicy
) -> Result<Vec<MappedSerializedValue>, Error>;
fn delete_docs_by_name(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
access_policy: AccessPolicy
) -> Result<u64, Error>;
fn insert<C: Collection, PrimaryKey: Send, B: Into<Bytes> + Send>(
&self,
id: Option<PrimaryKey>,
contents: B
) -> Result<CollectionHeader<C::PrimaryKey>, Error>
where
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
{ ... }
fn update<C: Collection, D: Document<C> + Send + Sync>(
&self,
doc: &mut D
) -> Result<(), Error> { ... }
fn overwrite<C, PrimaryKey>(
&self,
id: PrimaryKey,
contents: Vec<u8>
) -> Result<CollectionHeader<C::PrimaryKey>, Error>
where
C: Collection,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
{ ... }
fn get<C, PrimaryKey>(
&self,
id: PrimaryKey
) -> Result<Option<OwnedDocument>, Error>
where
C: Collection,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
{ ... }
fn get_multiple<C, PrimaryKey, DocumentIds, I>(
&self,
ids: DocumentIds
) -> Result<Vec<OwnedDocument>, Error>
where
C: Collection,
DocumentIds: IntoIterator<Item = PrimaryKey, IntoIter = I> + Send + Sync,
I: Iterator<Item = PrimaryKey> + Send + Sync,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
{ ... }
fn list<C, R, PrimaryKey>(
&self,
ids: R,
order: Sort,
limit: Option<u32>
) -> Result<Vec<OwnedDocument>, Error>
where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
{ ... }
fn list_headers<C, R, PrimaryKey>(
&self,
ids: R,
order: Sort,
limit: Option<u32>
) -> Result<Vec<Header>, Error>
where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
{ ... }
fn count<C, R, PrimaryKey>(&self, ids: R) -> Result<u64, Error>
where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
{ ... }
fn delete<C: Collection, H: HasHeader + Send + Sync>(
&self,
doc: &H
) -> Result<(), Error> { ... }
fn query<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<ViewMappings<V>, Error>
where
Key: for<'k> KeyEncoding<'k, V::Key>,
{ ... }
fn query_with_docs<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<MappedDocuments<OwnedDocument, V>, Error>
where
Key: for<'k> KeyEncoding<'k, V::Key>,
{ ... }
fn query_with_collection_docs<V, Key>(
&self,
key: Option<QueryKey<Key>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<MappedDocuments<CollectionDocument<V::Collection>, V>, Error>
where
Key: for<'k> KeyEncoding<'k, V::Key>,
V: SerializedView,
V::Collection: SerializedCollection,
<V::Collection as SerializedCollection>::Contents: Debug,
{ ... }
fn reduce<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
access_policy: AccessPolicy
) -> Result<V::Value, Error>
where
Key: for<'k> KeyEncoding<'k, V::Key>,
{ ... }
fn reduce_grouped<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
access_policy: AccessPolicy
) -> Result<GroupedReductions<V>, Error>
where
Key: for<'k> KeyEncoding<'k, V::Key>,
{ ... }
fn delete_docs<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
access_policy: AccessPolicy
) -> Result<u64, Error>
where
Key: for<'k> KeyEncoding<'k, V::Key>,
{ ... }
}Expand description
The low-level interface to a database’s schema::Schema, giving access to
Collections and
Viewss. This trait is not safe to use within async
contexts and will block the current thread. For async access, use
AsyncLowLevelConnection.
This trait’s methods are not designed for ergonomics. See
Connection for a higher-level interface.
Required methods
fn apply_transaction(
&self,
transaction: Transaction
) -> Result<Vec<OperationResult>, Error>
fn apply_transaction(
&self,
transaction: Transaction
) -> Result<Vec<OperationResult>, Error>
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.
fn get_from_collection(
&self,
id: DocumentId,
collection: &CollectionName
) -> Result<Option<OwnedDocument>, Error>
fn get_from_collection(
&self,
id: DocumentId,
collection: &CollectionName
) -> Result<Option<OwnedDocument>, Error>
Retrieves the document with id stored within the named collection.
This is a lower-level API. For better ergonomics, consider using one of:
fn get_multiple_from_collection(
&self,
ids: &[DocumentId],
collection: &CollectionName
) -> Result<Vec<OwnedDocument>, Error>
fn get_multiple_from_collection(
&self,
ids: &[DocumentId],
collection: &CollectionName
) -> Result<Vec<OwnedDocument>, Error>
Retrieves all documents matching ids from the named collection.
Documents that are not found are not returned, but no error will be
generated.
This is a lower-level API. For better ergonomics, consider using one of:
fn list_from_collection(
&self,
ids: Range<DocumentId>,
order: Sort,
limit: Option<u32>,
collection: &CollectionName
) -> Result<Vec<OwnedDocument>, Error>
fn list_from_collection(
&self,
ids: Range<DocumentId>,
order: Sort,
limit: Option<u32>,
collection: &CollectionName
) -> Result<Vec<OwnedDocument>, Error>
Retrieves all documents within the range of ids from the named
collection. To retrieve all documents, pass in .. for ids.
This is a lower-level API. For better ergonomics, consider using one of:
fn list_headers_from_collection(
&self,
ids: Range<DocumentId>,
order: Sort,
limit: Option<u32>,
collection: &CollectionName
) -> Result<Vec<Header>, Error>
fn list_headers_from_collection(
&self,
ids: Range<DocumentId>,
order: Sort,
limit: Option<u32>,
collection: &CollectionName
) -> Result<Vec<Header>, Error>
Retrieves all headers within the range of ids from the named
collection. To retrieve all documents, pass in .. for ids.
This is a lower-level API. For better ergonomics, consider using one of:
fn count_from_collection(
&self,
ids: Range<DocumentId>,
collection: &CollectionName
) -> Result<u64, Error>
fn count_from_collection(
&self,
ids: Range<DocumentId>,
collection: &CollectionName
) -> Result<u64, Error>
Counts the number of documents within the range of ids from the named
collection.
This is a lower-level API. For better ergonomics, consider using one of:
fn compact_collection_by_name(
&self,
collection: CollectionName
) -> Result<(), Error>
fn compact_collection_by_name(
&self,
collection: CollectionName
) -> Result<(), Error>
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.
fn query_by_name(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<Vec<Serialized>, Error>
fn query_by_name(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<Vec<Serialized>, Error>
Queries for view entries from the named view.
This is a 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
Connection::view().
fn query_by_name_with_docs(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<MappedSerializedDocuments, Error>
fn query_by_name_with_docs(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<MappedSerializedDocuments, Error>
Queries for view entries from the named view with their source
documents.
This is a 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 Connection::view().
Reduces the view entries from the named view.
This is a 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 Connection::view().
fn reduce_grouped_by_name(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
access_policy: AccessPolicy
) -> Result<Vec<MappedSerializedValue>, Error>
fn reduce_grouped_by_name(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
access_policy: AccessPolicy
) -> Result<Vec<MappedSerializedValue>, Error>
Reduces the view entries from the named view, reducing the values by each
unique key.
This is a 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 Connection::view().
fn delete_docs_by_name(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
access_policy: AccessPolicy
) -> Result<u64, Error>
fn delete_docs_by_name(
&self,
view: &ViewName,
key: Option<QueryKey<Bytes>>,
access_policy: AccessPolicy
) -> Result<u64, Error>
Deletes all source documents for entries that match within the named
view.
This is a 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 Connection::view().
Provided methods
fn insert<C: Collection, PrimaryKey: Send, B: Into<Bytes> + Send>(
&self,
id: Option<PrimaryKey>,
contents: B
) -> Result<CollectionHeader<C::PrimaryKey>, Error> where
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
fn insert<C: Collection, PrimaryKey: Send, B: Into<Bytes> + Send>(
&self,
id: Option<PrimaryKey>,
contents: B
) -> Result<CollectionHeader<C::PrimaryKey>, Error> where
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
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<C, PrimaryKey>(
&self,
id: PrimaryKey,
contents: Vec<u8>
) -> Result<CollectionHeader<C::PrimaryKey>, Error> where
C: Collection,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
fn overwrite<C, PrimaryKey>(
&self,
id: PrimaryKey,
contents: Vec<u8>
) -> Result<CollectionHeader<C::PrimaryKey>, Error> where
C: Collection,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
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:
fn get<C, PrimaryKey>(
&self,
id: PrimaryKey
) -> Result<Option<OwnedDocument>, Error> where
C: Collection,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
fn get<C, PrimaryKey>(
&self,
id: PrimaryKey
) -> Result<Option<OwnedDocument>, Error> where
C: Collection,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
Retrieves a stored document from Collection C identified by id.
This is a lower-level API. For better ergonomics, consider using one of:
fn get_multiple<C, PrimaryKey, DocumentIds, I>(
&self,
ids: DocumentIds
) -> Result<Vec<OwnedDocument>, Error> where
C: Collection,
DocumentIds: IntoIterator<Item = PrimaryKey, IntoIter = I> + Send + Sync,
I: Iterator<Item = PrimaryKey> + Send + Sync,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
fn get_multiple<C, PrimaryKey, DocumentIds, I>(
&self,
ids: DocumentIds
) -> Result<Vec<OwnedDocument>, Error> where
C: Collection,
DocumentIds: IntoIterator<Item = PrimaryKey, IntoIter = I> + Send + Sync,
I: Iterator<Item = PrimaryKey> + Send + Sync,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
Retrieves all documents matching ids. Documents that are not found are
not returned, but no error will be generated.
This is a lower-level API. For better ergonomics, consider using one of:
fn list<C, R, PrimaryKey>(
&self,
ids: R,
order: Sort,
limit: Option<u32>
) -> Result<Vec<OwnedDocument>, Error> where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
fn list<C, R, PrimaryKey>(
&self,
ids: R,
order: Sort,
limit: Option<u32>
) -> Result<Vec<OwnedDocument>, Error> where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
Retrieves all documents within the range of ids. To retrieve all
documents, pass in .. for ids.
This is a lower-level API. For better ergonomics, consider using one of:
fn list_headers<C, R, PrimaryKey>(
&self,
ids: R,
order: Sort,
limit: Option<u32>
) -> Result<Vec<Header>, Error> where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
fn list_headers<C, R, PrimaryKey>(
&self,
ids: R,
order: Sort,
limit: Option<u32>
) -> Result<Vec<Header>, Error> where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
Retrieves all documents within the range of ids. To retrieve all
documents, pass in .. for ids.
This is the lower-level API. For better ergonomics, consider using one of:
fn count<C, R, PrimaryKey>(&self, ids: R) -> Result<u64, Error> where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
fn count<C, R, PrimaryKey>(&self, ids: R) -> Result<u64, Error> where
C: Collection,
R: Into<Range<PrimaryKey>> + Send,
PrimaryKey: for<'k> KeyEncoding<'k, C::PrimaryKey>,
Counts the number of documents within the range of ids.
This is a lower-level API. For better ergonomics, consider using one of:
Removes a Document from the database.
This is a lower-level API. For better ergonomics, consider using one of:
fn query<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<ViewMappings<V>, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
fn query<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<ViewMappings<V>, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
Queries for view entries matching View.
This is a 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
Connection::view().
fn query_with_docs<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<MappedDocuments<OwnedDocument, V>, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
fn query_with_docs<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<MappedDocuments<OwnedDocument, V>, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
Queries for view entries matching View with their source documents.
This is a 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 Connection::view().
fn query_with_collection_docs<V, Key>(
&self,
key: Option<QueryKey<Key>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<MappedDocuments<CollectionDocument<V::Collection>, V>, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
V: SerializedView,
V::Collection: SerializedCollection,
<V::Collection as SerializedCollection>::Contents: Debug,
fn query_with_collection_docs<V, Key>(
&self,
key: Option<QueryKey<Key>>,
order: Sort,
limit: Option<u32>,
access_policy: AccessPolicy
) -> Result<MappedDocuments<CollectionDocument<V::Collection>, V>, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
V: SerializedView,
V::Collection: SerializedCollection,
<V::Collection as SerializedCollection>::Contents: Debug,
Queries for view entries matching View with their source documents, deserialized.
This is a 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 Connection::view().
fn reduce<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
access_policy: AccessPolicy
) -> Result<V::Value, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
fn reduce<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
access_policy: AccessPolicy
) -> Result<V::Value, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
Reduces the view entries matching View.
This is a 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 Connection::view().
fn reduce_grouped<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
access_policy: AccessPolicy
) -> Result<GroupedReductions<V>, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
fn reduce_grouped<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
access_policy: AccessPolicy
) -> Result<GroupedReductions<V>, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
Reduces the view entries matching View, reducing the values by each
unique key.
This is a 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 Connection::view().
fn delete_docs<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
access_policy: AccessPolicy
) -> Result<u64, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
fn delete_docs<V: SerializedView, Key>(
&self,
key: Option<QueryKey<Key>>,
access_policy: AccessPolicy
) -> Result<u64, Error> where
Key: for<'k> KeyEncoding<'k, V::Key>,
Deletes all of the documents associated with this view.
This is a 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 Connection::view().