Skip to main content

Collection

Struct Collection 

Source
pub struct Collection { /* private fields */ }
Expand description

A collection of documents.

Implementations§

Source§

impl Collection

Source

pub fn new(name: impl Into<String>) -> Self

Create a new collection.

Source

pub fn with_schema(name: impl Into<String>, schema: Schema) -> Self

Create a collection with schema validation.

Source

pub fn name(&self) -> &str

Get the collection name.

Source

pub fn insert(&self, doc: Document) -> Result<DocumentId, CollectionError>

Insert a document.

Source

pub fn insert_many( &self, docs: Vec<Document>, ) -> Result<Vec<DocumentId>, CollectionError>

Insert multiple documents.

Source

pub fn get(&self, id: &DocumentId) -> Option<Document>

Get a document by ID.

Source

pub fn update( &self, id: &DocumentId, doc: Document, ) -> Result<(), CollectionError>

Update a document.

Source

pub fn delete(&self, id: &DocumentId) -> Result<Document, CollectionError>

Delete a document.

Source

pub fn contains(&self, id: &DocumentId) -> bool

Check if a document exists.

Source

pub fn count(&self) -> usize

Get the number of documents.

Source

pub fn ids(&self) -> Vec<DocumentId>

Get all document IDs.

Source

pub fn all(&self) -> Vec<Document>

Get all documents.

Source

pub fn clear(&self)

Clear all documents.

Source

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.

Source

pub fn find_one(&self, query: &Query) -> Option<Document>

Find one document matching a query.

Source

pub fn count_matching(&self, query: &Query) -> usize

Count documents matching a query.

Source

pub fn create_index(&self, field: impl Into<String>, index_type: IndexType)

Create an index on a field.

Source

pub fn drop_index(&self, field: &str)

Drop an index.

Source

pub fn index_names(&self) -> Vec<String>

Get all index names.

Source

pub fn set_schema(&mut self, schema: Schema)

Set the collection schema.

Source

pub fn schema(&self) -> Option<&Schema>

Get the collection schema.

Source

pub fn validate_all(&self) -> Vec<(DocumentId, ValidationResult)>

Validate all documents against the schema.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.