Struct UnQLite

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

UnQLite database entry point.

UnQLite support both in-memory and on-disk database. There’s several constructors:

ConstructorMeaning
create_in_memoryCreate a private, in-memory database.
create_tempCreate a private, temporary on-disk database.
createCreate if not exists, otherwise, open as read-write.
open_mmapObtain a read-only memory view of the whole database.
open_readonlyOpen the database in a read-only mode.

Implementations§

Source§

impl UnQLite

Source

pub fn create<P: AsRef<str>>(filename: P) -> UnQLite

Create UnQLite database as filename.

By default, the database is created in read-write mode.

§Panics

Will panic if failed in creating.

§Example
let _ = UnQLite::create("test.db");
§C
unqlite *pDb;

// on-disk database
rc = unqlite_open(&pDb,"test.db",UNQLITE_OPEN_CREATE);

// in-memory database
rc = unqlite_open(&pDb, ":mem:", UNQLITE_OPEN_MEM);
Source

pub fn create_in_memory() -> UnQLite

Create database in memory.

Equivalent to:

let _ = UnQLite::create(":mem:");
§Panics

Will panic if failed in creating.

Source

pub fn create_temp() -> UnQLite

A private, temporary on-disk database will be created.

This private database will be automatically deleted as soon as the database connection is closed.

§Panics

Will panic if failed in creating.

§C
int rc = unqlite_open("test.db", UNQLITE_OPEN_TEMP_DB);
Source

pub fn open_mmap<P: AsRef<str>>(filename: P) -> UnQLite

Obtain a read-only memory view of the whole database.

You will get significant performance improvements with this combination but your database is still read-only.

§Panics

Panic if open failed.

§C
unqlite_open(&pDb, "test.db", UNQLITE_OPEN_MMAP | UNQLITE_OPEN_READONLY);
Source

pub fn open_readonly<P: AsRef<str>>(filename: P) -> UnQLite

Open the database in a read-only mode.

That is, you cannot perform a store, append, commit or rollback operations with this control flag.

Always prefer to use open_mmap for readonly in disk database.

§Panics

Panic too.

§C
unqlite_open(&pDb, "test.db", UNQLITE_OPEN_READONLY);

Trait Implementations§

Source§

impl Config for UnQLite

Source§

fn max_page_cache(self, max: u32) -> Self

Maximum raw pages to cache in memory. Read more
Source§

fn disable_auto_commit(self) -> Self

To diable automatically commit action. Read more
Source§

fn kv_engine<S: Into<Vec<u8>>>(self, name: S) -> Self

Switch to another Key/Value storage engine. Read more
Source§

fn err_log(&self) -> Option<String>

The database error log is stored in an internal buffer. When something goes wrong during a commit, rollback, store, append operation, a human-readable error message is generated to help clients diagnose the problem. This option can be used to point to that buffer.
Source§

fn jx9_err_log(&self) -> Option<String>

When something goes wrong during compilation of the target Jx9 script due to an erroneous Jx9 code, the compiler error log is redirected to an internal buffer. This option can be used to point to that buffer.
Source§

fn kv_name(&self) -> String

Extract the name of the underlying Key/Value storage engine. Read more
Source§

impl Cursor for UnQLite

Source§

fn first(&self) -> Option<Entry>

Returns the first entry.
Source§

fn last(&self) -> Option<Entry>

Retruns the last entry.
Source§

fn seek<K: AsRef<[u8]>>(&self, key: K, pos: Direction) -> Option<Entry>

Seek an entry by key. Read more
Source§

impl Drop for UnQLite

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Jx9 for UnQLite

Jx9 script compiler Interface.

Source§

fn compile<T: AsRef<[u8]>>(&self, jx9: T) -> Result<UnQLiteVm>

Compile a Jx9 script to a bytecode program.

Source§

fn compile_file<P: AsRef<str>>(&self, filename: P) -> Result<UnQLiteVm>

Compile a Jx9 script file to a bytecode program.

Source§

impl KV for UnQLite

Key-Value Store Interface

Source§

fn kv_store<K: AsRef<[u8]>, V: AsRef<[u8]>>( &self, key: K, value: V, ) -> Result<()>

Store records in the database. Read more
Source§

fn kv_append<K: AsRef<[u8]>, V: AsRef<[u8]>>( &self, key: K, value: V, ) -> Result<()>

Append data to a database record. Read more
Source§

fn kv_delete<K: AsRef<[u8]>>(&self, key: K) -> Result<()>

Remove a record from the database. Read more
Source§

fn kv_contains<K: AsRef<[u8]>>(&self, key: K) -> bool

Check if key is contained in database.
Source§

fn kv_fetch_length<K: AsRef<[u8]>>(&self, key: K) -> Result<i64>

Fetch a record from the database and returns the length only
Source§

fn kv_fetch<K: AsRef<[u8]>>(&self, key: K) -> Result<Vec<u8>>

Fetch a record from the database. Read more
Source§

fn kv_fetch_callback<K: AsRef<[u8]>>( &self, key: K, consumer: extern "C" fn(data: *const c_void, len: u32, user_data: *mut c_void) -> i32, ) -> Result<()>

Fetch a record from the database and invoke the supplied callback to consume its data.
Source§

fn kv_config_hash( &self, hash: extern "C" fn(key: *const c_void, len: u32) -> u32, ) -> Result<()>

Configure the hash function of the underlying Key/Value (KV) storage engine. Read more
Source§

fn kv_config_cmp( &self, cmp: extern "C" fn(key: *const c_void, len: u32) -> u32, ) -> Result<()>

Configure the compare function of the underlying Key/Value (KV) storage engine. Read more
Source§

impl Transaction for UnQLite

Source§

fn begin(&self) -> Result<()>

Manually begin a write-transaction on the specified database handle. Read more
Source§

fn commit(&self) -> Result<()>

Commit all changes to the database. Read more
Source§

fn rollback(&self) -> Result<()>

Rollback a write-transaction on the specified database handle. Read more
Source§

impl Util for UnQLite

Source§

fn random_string(&self, buf_size: u32) -> Vec<u8>

Generate random string using the UnQLite PRNG. Read more
Source§

fn random_num(&self) -> u32

Generate random number using the UnQLite PRNG. Read more
Source§

impl Send for UnQLite

Source§

impl Sync for UnQLite

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.