Struct polodb_core::Database

source ·
pub struct Database { /* private fields */ }
Expand description

API wrapper for Rust-level

Use open API to open a database. A main database file will be generated in the path user provided.

When you own an instance of a Database, the instance holds a file descriptor of the database file. When the Database instance is dropped, the handle of the file will be released.

Collection

A Collection is a dataset of a kind of data. You can use create_collection to create a data collection. To obtain an exist collection, use collection,

Session

A ClientSession represents a logical session used for ordering sequential operations.

You an manually start a transaction by ClientSession::start_transaction method. If you don’t start it manually, a transaction will be automatically started in your every operation.

Example

use polodb_core::Database;
use polodb_core::bson::{Document, doc};

let db = Database::open_file(db_path).unwrap();

let mut session = db.start_session().unwrap();
session.start_transaction(None).unwrap();

let collection = db.collection::<Document>("books");

let docs = vec![
    doc! { "title": "1984", "author": "George Orwell" },
    doc! { "title": "Animal Farm", "author": "George Orwell" },
    doc! { "title": "The Great Gatsby", "author": "F. Scott Fitzgerald" },
];
collection.insert_many_with_session(docs, &mut session).unwrap();

session.commit_transaction().unwrap();

Implementations§

source§

impl Database

source

pub fn set_log(v: bool)

source

pub fn get_version() -> String

Return the version of package version in string. Defined in Cargo.toml.

source

pub fn open_memory() -> DbResult<Database>

source

pub fn open_memory_with_config(config: Config) -> DbResult<Database>

source

pub fn open_file<P: AsRef<Path>>(path: P) -> DbResult<Database>

source

pub fn open_file_with_config<P: AsRef<Path>>( path: P, config: Config ) -> DbResult<Database>

source

pub fn create_collection(&self, name: &str) -> DbResult<()>

Creates a new collection in the database with the given name.

source

pub fn create_collection_with_session( &self, name: &str, session: &mut ClientSession<'_> ) -> DbResult<()>

Creates a new collection in the database with the given name.

source

pub fn collection<T: Serialize>(&self, col_name: &str) -> Collection<'_, T>

Return an exist collection. If the collection is not exists, a new collection will be created.

source

pub fn start_session(&self) -> DbResult<ClientSession<'_>>

source

pub fn dump(&self) -> DbResult<FullDump>

source

pub fn list_collection_names(&self) -> DbResult<Vec<String>>

Gets the names of the collections in the database.

source

pub fn list_collection_names_with_session( &self, session: &mut ClientSession<'_> ) -> DbResult<Vec<String>>

Gets the names of the collections in the database.

source

pub fn handle_request<R: Read>( &self, pipe_in: &mut R ) -> DbResult<HandleRequestResult>

handle request for database

source

pub fn handle_request_doc(&self, value: Bson) -> DbResult<HandleRequestResult>

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V