Struct ledb::Collection
source · pub struct Collection(_);
Expand description
Collection of documents
Implementations§
source§impl Collection
impl Collection
pub fn name(&self) -> &str
sourcepub fn insert<T: Serialize>(&self, doc: T) -> Result<Primary>
pub fn insert<T: Serialize>(&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.
sourcepub fn find<T: DeserializeOwned>(
&self,
filter: Option<Filter>,
order: Order
) -> Result<DocumentsIterator<T>>
pub fn find<T: DeserializeOwned>(
&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.
sourcepub fn find_all<T: DeserializeOwned>(
&self,
filter: Option<Filter>,
order: Order
) -> Result<Vec<Document<T>>>
pub fn find_all<T: DeserializeOwned>(
&self,
filter: Option<Filter>,
order: Order
) -> Result<Vec<Document<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.
pub fn find_ids(&self, filter: Option<Filter>) -> Result<HashSet<Primary>>
sourcepub fn update(&self, filter: Option<Filter>, modify: Modify) -> Result<usize>
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.
sourcepub fn remove(&self, filter: Option<Filter>) -> Result<usize>
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.
sourcepub fn dump<T: DeserializeOwned>(&self) -> Result<DocumentsIterator<T>>
pub fn dump<T: DeserializeOwned>(&self) -> Result<DocumentsIterator<T>>
Dump all documents which stored into the collection
sourcepub fn load<T: Serialize, I>(&self, docs: I) -> Result<usize>where
I: IntoIterator<Item = Document<T>>,
pub fn load<T: Serialize, I>(&self, docs: I) -> Result<usize>where
I: IntoIterator<Item = Document<T>>,
Load new documents into the collection
Note: The old documents will be removed.
sourcepub fn has(&self, id: Primary) -> Result<bool>
pub fn has(&self, id: Primary) -> Result<bool>
Checks the collection contains document with specified primary key
sourcepub fn get<T: DeserializeOwned>(
&self,
id: Primary
) -> Result<Option<Document<T>>>
pub fn get<T: DeserializeOwned>(
&self,
id: Primary
) -> Result<Option<Document<T>>>
Get document from collection using primary key/identifier
sourcepub fn put<T: Serialize>(&self, doc: &Document<T>) -> Result<()>
pub fn put<T: Serialize>(&self, doc: &Document<T>) -> Result<()>
Replace document in the collection
Note: The document must have primary key/identifier.
sourcepub fn delete(&self, id: Primary) -> Result<bool>
pub fn delete(&self, id: Primary) -> Result<bool>
Delete document with specified primary key/identifier from the collection
sourcepub fn last_id(&self) -> Result<Primary>
pub fn last_id(&self) -> Result<Primary>
Get the last primary key/identifier of inserted document
sourcepub fn get_indexes(&self) -> Result<Vec<(Identifier, IndexKind, KeyType)>>
pub fn get_indexes(&self) -> Result<Vec<(Identifier, IndexKind, KeyType)>>
Get indexes info from the collection
sourcepub fn set_indexes(
&self,
indexes: &[(Identifier, IndexKind, KeyType)]
) -> Result<()>
pub fn set_indexes(
&self,
indexes: &[(Identifier, IndexKind, KeyType)]
) -> Result<()>
Set indexes of collection
This method overrides collection indexes
sourcepub fn ensure_index<P: AsRef<str>>(
&self,
path: P,
kind: IndexKind,
key: KeyType
) -> Result<bool>
pub fn ensure_index<P: AsRef<str>>(
&self,
path: P,
kind: IndexKind,
key: KeyType
) -> Result<bool>
Ensure index for the collection
sourcepub fn has_index<P: AsRef<str>>(&self, path: P) -> Result<bool>
pub fn has_index<P: AsRef<str>>(&self, path: P) -> Result<bool>
Checks the index for specified field exists for the collection
Methods from Deref<Target = Database<'static>>§
sourcepub fn env(&self) -> &Environment
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.
sourcepub fn assert_same_env(&self, other_env: &Environment) -> Result<(), Error>
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
.
sourcepub fn dbi(&self) -> u32
👎Deprecated since 0.4.4: use as_raw() instead
pub fn dbi(&self) -> u32
Returns the underlying integer handle for this database.
Deprecated
Renamed to as_raw()
for consistency.
Trait Implementations§
source§impl Clone for Collection
impl Clone for Collection
source§fn clone(&self) -> Collection
fn clone(&self) -> Collection
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl ConstDeref for Collection
impl ConstDeref for Collection
source§impl Deref for Collection
impl Deref for Collection
source§impl Drop for Collection
impl Drop for Collection
Auto Trait Implementations§
impl !RefUnwindSafe for Collection
impl Send for Collection
impl Sync for Collection
impl Unpin for Collection
impl !UnwindSafe for Collection
Blanket Implementations§
source§impl<'a, T> DefaultFeatures<'a> for Twhere
T: 'a + Send + Sync + Clone,
impl<'a, T> DefaultFeatures<'a> for Twhere
T: 'a + Send + Sync + Clone,
source§fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a> + 'a, Global>
fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a> + 'a, Global>
Box
behind a trait object of this trait. Read moresource§impl<'a, T> NonSyncFeatures<'a> for Twhere
T: 'a + Clone,
impl<'a, T> NonSyncFeatures<'a> for Twhere
T: 'a + Clone,
source§fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a> + 'a, Global>
fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a> + 'a, Global>
Box
behind a trait object of this trait. Read more