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,

Transaction

You an manually start a transaction by 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 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(docs).unwrap();

Implementations§

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

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

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

Manually start a transaction. There are three types of transaction.

  • None: Auto transaction
  • Some(Transaction::Write): Write transaction
  • Some(Transaction::Read): Read transaction

When you pass None to type parameter. The PoloDB will go into auto mode. The PoloDB will go into read mode firstly, once the users execute write operations(insert/update/delete), the DB will turn into write mode.

Gets the names of the collections in the database.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.