Struct Collection

Source
pub struct Collection(/* private fields */);
Expand description

Collection of documents

Implementations§

Source§

impl Collection

Source

pub fn name(&self) -> &str

Source

pub fn insert<T: Serialize + Document>(&self, doc: T) -> Result<Primary>

Insert document into collection

The primary key/identifier of document will be selected by auto incrementing the id of last inserted document.

Primary key/identifier of new inserted document will be returned.

Source

pub fn find<T: DeserializeOwned + Document>( &self, filter: Option<Filter>, order: Order, ) -> Result<DocumentsIterator<T>>

Find documents using optional filter and ordering

When none filter specified then all documents will be found.

Iterator across found documents will be returned.

You can use DocumentsIterator::len() for getting the total number of found documents.

Source

pub fn find_all<T: DeserializeOwned + Document>( &self, filter: Option<Filter>, order: Order, ) -> Result<Vec<T>>

Find documents using optional filter and ordering

When none filter specified then all documents will be found.

The vector with found documents will be returned.

Source

pub fn find_ids(&self, filter: Option<Filter>) -> Result<HashSet<Primary>>

Source

pub fn update(&self, filter: Option<Filter>, modify: Modify) -> Result<usize>

Update documents using optional filter and modifier

Note: When none filter specified then all documents will be modified.

Returns the number of affected documents.

Source

pub fn remove(&self, filter: Option<Filter>) -> Result<usize>

Remove documents using optional filter

Note: When none filter specified then all documents will be removed.

Returns the number of affected documents.

Source

pub fn dump<T: DeserializeOwned + Document>( &self, ) -> Result<DocumentsIterator<T>>

Dump all documents which stored into the collection

Source

pub fn load<T: Serialize + Document, I>(&self, docs: I) -> Result<usize>
where I: IntoIterator<Item = T>,

Load new documents into the collection

Note: The old documents will be removed.

Source

pub fn purge(&self) -> Result<()>

Remove all documents from the collection

Source

pub fn has(&self, id: Primary) -> Result<bool>

Checks the collection contains document with specified primary key

Source

pub fn get<T: DeserializeOwned + Document>( &self, id: Primary, ) -> Result<Option<T>>

Get document from collection using primary key/identifier

Source

pub fn put<T: Serialize + Document>(&self, doc: T) -> Result<()>

Replace document in the collection

Note: The document must have primary key/identifier.

Source

pub fn delete(&self, id: Primary) -> Result<bool>

Delete document with specified primary key/identifier from the collection

Source

pub fn last_id(&self) -> Result<Primary>

Get the last primary key/identifier of inserted document

Source

pub fn new_id(&self) -> Result<Primary>

Get the new primary key/identifier

Source

pub fn get_indexes(&self) -> Result<KeyFields>

Get indexes info from the collection

Source

pub fn set_indexes<T, I: AsRef<[T]>>(&self, indexes: I) -> Result<()>
where T: Clone, KeyField: From<T>,

Set indexes of collection

This method overrides collection indexes

Source

pub fn index<T: Document>(&self) -> Result<()>

Set indexes using document type

This method overrides collection indexes

Source

pub fn ensure_index<P: AsRef<str>>( &self, path: P, kind: IndexKind, key: KeyType, ) -> Result<bool>

Ensure index for the collection

Source

pub fn has_index<P: AsRef<str>>(&self, path: P) -> Result<bool>

Checks the index for specified field exists for the collection

Source

pub fn create_index<P: AsRef<str>>( &self, path: P, kind: IndexKind, key: KeyType, ) -> Result<bool>

Create index for the collection

Source

pub fn drop_index<P: AsRef<str>>(&self, path: P) -> Result<bool>

Remove index from the collection

Methods from Deref<Target = Database<'static>>§

Source

pub fn env(&self) -> &Environment

Returns a reference to the Environment to which this Database belongs.

This can be used to elide needing to pass both an &Environment and an &Database around, but is also useful for the use-case wherein the Database owns the Environment.

Because this may borrow an Environment owned by this Database, the lifetime of the returned reference is dependent on self rather than being 'env. (In fact, 'env is usually 'static if the Environment is owned by the Database, so returning &'env Environment is impossible anyway.)

§Example
let env: lmdb::Environment = create_env();
// We only want one `Database`, so don't bother keeping both variables
// around and instead let the `Database` own the `Environment`.
let db = lmdb::Database::open(
  env, None, &lmdb::DatabaseOptions::defaults()).unwrap();

// `env` has been consumed, but we can still do useful things by
// getting a reference to the inner value.
let txn = lmdb::ReadTransaction::new(db.env()).unwrap();

// Do stuff with `txn`, etc.
Source

pub fn assert_same_env(&self, other_env: &Environment) -> Result<(), Error>

Checks that other_env is the same as the environment on this Database.

If it matches, returns Ok(()); otherwise, returns Err.

Source

pub fn dbi(&self) -> u32

👎Deprecated since 0.4.4: use as_raw() instead

Returns the underlying integer handle for this database.

§Deprecated

Renamed to as_raw() for consistency.

Source

pub fn as_raw(&self) -> u32

Returns the underlying integer handle for this database.

Trait Implementations§

Source§

impl Clone for Collection

Source§

fn clone(&self) -> Collection

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ConstDeref for Collection

Source§

type Target = Database<'static>

The type this value dereferences to.
Source§

fn const_deref(&self) -> &Self::Target

Returns the (constant) value that this value dereferences to.
Source§

impl Deref for Collection

Source§

type Target = Database<'static>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Drop for Collection

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> Into<Supercow<'a, Database<'a>>> for Collection

Source§

fn into(self) -> Supercow<'a, Database<'a>>

Converts this type into the (usually inferred) input type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<'a, T> DefaultFeatures<'a> for T
where T: 'a + Send + Sync + Clone,

Source§

fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a>>

Clone this value, and then immediately put it into a Box behind a trait object of this trait.
Source§

fn self_address_mut(&mut self) -> *mut ()

Returns the address of self. 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<'a, T> NonSyncFeatures<'a> for T
where T: 'a + Clone,

Source§

fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a>>

Clone this value, and then immediately put it into a Box behind a trait object of this trait.
Source§

fn self_address_mut(&mut self) -> *mut ()

Returns the address of self. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

fn borrow_replacement(ptr: &T) -> &T

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.