pub struct Collection { /* private fields */ }Expand description
A collection of documents.
Implementations§
Source§impl Collection
impl Collection
Sourcepub fn with_schema(name: impl Into<String>, schema: Schema) -> Self
pub fn with_schema(name: impl Into<String>, schema: Schema) -> Self
Create a collection with schema validation.
Sourcepub fn insert(&self, doc: Document) -> Result<DocumentId, CollectionError>
pub fn insert(&self, doc: Document) -> Result<DocumentId, CollectionError>
Insert a document.
Sourcepub fn insert_many(
&self,
docs: Vec<Document>,
) -> Result<Vec<DocumentId>, CollectionError>
pub fn insert_many( &self, docs: Vec<Document>, ) -> Result<Vec<DocumentId>, CollectionError>
Insert multiple documents.
Sourcepub fn get(&self, id: &DocumentId) -> Option<Document>
pub fn get(&self, id: &DocumentId) -> Option<Document>
Get a document by ID.
Sourcepub fn update(
&self,
id: &DocumentId,
doc: Document,
) -> Result<(), CollectionError>
pub fn update( &self, id: &DocumentId, doc: Document, ) -> Result<(), CollectionError>
Update a document.
Sourcepub fn delete(&self, id: &DocumentId) -> Result<Document, CollectionError>
pub fn delete(&self, id: &DocumentId) -> Result<Document, CollectionError>
Delete a document.
Sourcepub fn contains(&self, id: &DocumentId) -> bool
pub fn contains(&self, id: &DocumentId) -> bool
Check if a document exists.
Sourcepub fn ids(&self) -> Vec<DocumentId>
pub fn ids(&self) -> Vec<DocumentId>
Get all document IDs.
Sourcepub fn find(&self, query: &Query) -> QueryResult
pub fn find(&self, query: &Query) -> QueryResult
Find documents matching a query.
When possible, uses indexes on fields with Eq filters to narrow
the candidate set before applying the full filter chain, reducing
the number of documents scanned.
Sourcepub fn count_matching(&self, query: &Query) -> usize
pub fn count_matching(&self, query: &Query) -> usize
Count documents matching a query.
Sourcepub fn create_index(&self, field: impl Into<String>, index_type: IndexType)
pub fn create_index(&self, field: impl Into<String>, index_type: IndexType)
Create an index on a field.
Sourcepub fn drop_index(&self, field: &str)
pub fn drop_index(&self, field: &str)
Drop an index.
Sourcepub fn index_names(&self) -> Vec<String>
pub fn index_names(&self) -> Vec<String>
Get all index names.
Sourcepub fn set_schema(&mut self, schema: Schema)
pub fn set_schema(&mut self, schema: Schema)
Set the collection schema.
Sourcepub fn validate_all(&self) -> Vec<(DocumentId, ValidationResult)>
pub fn validate_all(&self) -> Vec<(DocumentId, ValidationResult)>
Validate all documents against the schema.
Auto Trait Implementations§
impl !Freeze for Collection
impl RefUnwindSafe for Collection
impl Send for Collection
impl Sync for Collection
impl Unpin for Collection
impl UnsafeUnpin for Collection
impl UnwindSafe for Collection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more