[][src]Struct ledb::Storage

pub struct Storage(_);

Storage of documents

Implementations

impl Storage[src]

pub fn new<P: AsRef<Path>>(path: P, opts: Options) -> Result<Self>[src]

Open documents storage using path to the database in filesystem

When storage does not exists it will be created automatically.

On opening storage the existing collections and indexes will be restored automatically.

You can open multiple storages using same path, actually all of them will use same storage instance. Also you can clone storage instance, share it and and send it to another threads.

pub fn has_collection<N: AsRef<str>>(&self, name: N) -> Result<bool>[src]

Checks if the collection exists

pub fn collection<N: AsRef<str>>(&self, name: N) -> Result<Collection>[src]

Get collection for documents

Note: The collection will be created automatically when is does not exists.

pub fn drop_collection<N: AsRef<str>>(&self, name: N) -> Result<bool>[src]

pub fn get_collections(&self) -> Result<Vec<String>>[src]

pub fn get_stats(&self) -> Result<Stats>[src]

pub fn get_info(&self) -> Result<Info>[src]

pub fn openned() -> Result<Vec<PathBuf>>[src]

Get openned storages

Methods from Deref<Target = Environment>

pub fn as_raw(&self) -> *mut MDB_env[src]

Return the underlying MDB_env handle.

Safety

While this call is in and of itself safe, the caller must ensure that operations against the backing store do not violate Rust aliasing rules, and must not take any action that would cause the MDB_env to be destroyed prematurely, or to use it after this Environment is destroyed.

pub fn copy(&self, path: &str, flags: Flags) -> Result<(), Error>[src]

Copy an LMDB environment to the specified path, with options.

This function may be used to make a backup of an existing environment. No lockfile is created, since it gets recreated at need.

Note

This call can trigger significant file size growth if run in parallel with write transactions, because it employs a read-only transaction. See long-lived transactions under Caveats.

Example

let out = tempdir::TempDir::new_in(".", "lmdbcopy").unwrap();
env.copy(out.path().to_str().unwrap(),
         lmdb::copy::COMPACT).unwrap();
// We could now open up an independent environment in `lmdbcopyXXXX`
// or upload it somewhere, eg, while `env` could continue being
// modified concurrently.

pub fn copyfd(&self, fd: i32, flags: Flags) -> Result<(), Error>[src]

Copy an LMDB environment to the specified file descriptor, with options.

This function may be used to make a backup of an existing environment. No lockfile is created, since it gets recreated at need. See copy() for further details.

Note

This call can trigger significant file size growth if run in parallel with write transactions, because it employs a read-only transaction. See long-lived transactions under Caveats.

pub fn stat(&self) -> Result<Stat, Error>[src]

Return statistics about the LMDB environment.

pub fn info(&self) -> Result<EnvInfo, Error>[src]

Return information about the LMDB environment.

pub fn sync(&self, force: bool) -> Result<(), Error>[src]

Flush the data buffers to disk.

Data is always written to disk when transactions are committed, but the operating system may keep it buffered. LMDB always flushes the OS buffers upon commit as well, unless the environment was opened with NOSYNC or in part NOMETASYNC. This call is not valid if the environment was opened with RDONLY.

If force is true, force a synchronous flush. Otherwise if the environment has the NOSYNC flag set the flushes will be omitted, and with MAPASYNC they will be asynchronous.

pub unsafe fn set_flags(&self, flags: Flags, onoff: bool) -> Result<(), Error>[src]

Set environment flags.

This may be used to set some flags in addition to those from EnvBuilder::open(), or to unset these flags. If several threads change the flags at the same time, the result is undefined.

flags specifies the flags to edit, not the new status of all flags. If onoff is true, all flags in flags are set; otherwise, all flags in flags are cleared.

Unsafety

The caller must ensure that multiple threads do not call this concurrently with itself or with get_flags(). This could not be accomplished by using &mut self, since any open databases necessarily have the environment borrowed already.

Example

unsafe {
  // Enable the NOMETASYNC and MAPASYNC flags
  env.set_flags(lmdb::open::NOMETASYNC | lmdb::open::MAPASYNC, true)
    .unwrap();
  assert!(env.flags().unwrap().contains(
    lmdb::open::NOMETASYNC | lmdb::open::MAPASYNC));
  // Turn MAPASYNC back off, leaving NOMETASYNC set
  env.set_flags(lmdb::open::MAPASYNC, false).unwrap();
  assert!(env.flags().unwrap().contains(lmdb::open::NOMETASYNC));
  assert!(!env.flags().unwrap().contains(lmdb::open::MAPASYNC));
}

pub fn flags(&self) -> Result<Flags, Error>[src]

Get environment flags.

pub fn path(&self) -> Result<&CStr, Error>[src]

Return the path that was used in EnvBuilder::open().

Panics

Panics if LMDB returns success but sets the path to a NULL pointer.

pub unsafe fn fd(&self) -> Result<i32, Error>[src]

Return the filedescriptor for the given environment.

Unsafety

The caller must ensure that the file descriptor is not used to subvert normal LMDB functionality, such as by writing to it or closing it.

pub unsafe fn set_mapsize(&self, size: usize) -> Result<(), Error>[src]

Set the size of the memory map to use for this environment.

The size should be a multiple of the OS page size. The default is 10485760 bytes. The size of the memory map is also the maximum size of the database. The value should be chosen as large as possible, to accommodate future growth of the database.

The new size takes effect immediately for the current process but will not be persisted to any others until a write transaction has been committed by the current process. Also, only mapsize increases are persisted into the environment.

If the mapsize is increased by another process, and data has grown beyond the range of the current mapsize, starting a transaction will return error::MAP_RESIZED. This function may be called with a size of zero to adopt the new size.

Unsafety

This may only be called if no transactions are active in the current process. Note that the library does not check for this condition, the caller must ensure it explicitly.

pub fn maxreaders(&self) -> Result<u32, Error>[src]

Get the maximum number of threads/reader slots for the environment.

pub fn maxkeysize(&self) -> u32[src]

Get the maximum size of keys and DUPSORT data we can write.

Depends on the compile-time constant MDB_MAXKEYSIZE in LMDB. Default 511.

pub fn reader_check(&self) -> Result<i32, Error>[src]

Check for stale entries in the reader lock table.

Returns the number of stale slots that were cleared.

Trait Implementations

impl Clone for Storage[src]

impl ConstDeref for Storage[src]

type Target = Environment

The type this value dereferences to.

impl Deref for Storage[src]

type Target = Environment

The resulting type after dereferencing.

impl Drop for Storage[src]

impl<'env> Into<Supercow<'env, Environment, Environment, Box<dyn DefaultFeatures<'static> + 'static>, BoxedStorage, *const Environment>> for Storage[src]

impl<'env> Into<Supercow<'env, Environment, Environment, Box<dyn NonSyncFeatures<'static> + 'static>, BoxedStorage, *const Environment>> for Storage[src]

Auto Trait Implementations

impl RefUnwindSafe for Storage

impl Send for Storage

impl Sync for Storage

impl Unpin for Storage

impl UnwindSafe for Storage

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<'a, T> NonSyncFeatures<'a> for T where
    T: 'a + Clone
[src]

impl<T> SafeBorrow<T> for T where
    T: ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.