Struct bonsaidb::local::AsyncStorage [−][src]
pub struct AsyncStorage { /* fields omitted */ }
Expand description
A file-based, multi-database, multi-user database engine. This type is
designed for use with Tokio. For blocking
(non-asynchronous) code, see the Storage
type instead.
Converting between Blocking and Async Types
AsyncDatabase
and Database
can be converted to and from each other
using:
AsyncStorage::into_blocking()
AsyncStorage::to_blocking()
AsyncStorage::as_blocking()
Storage::into_async()
Storage::to_async()
Storage::into_async_with_runtime()
Storage::to_async_with_runtime()
Converting from AsyncDatabase::open
to AsyncStorage::open
AsyncDatabase::open
is a simple method that uses
AsyncStorage
to create a database named default
with the schema
provided. These two ways of opening the database are the same:
// `bonsaidb_core` is re-exported to `bonsaidb::core` or `bonsaidb_local::core`.
use bonsaidb_core::{connection::AsyncStorageConnection, schema::Schema};
// `bonsaidb_local` is re-exported to `bonsaidb::local` if using the omnibus crate.
use bonsaidb_local::{
config::{Builder, StorageConfiguration},
AsyncDatabase, AsyncStorage,
};
// This creates a Storage instance, creates a database, and returns it.
let db = AsyncDatabase::open::<MySchema>(StorageConfiguration::new("my-db.bonsaidb")).await?;
// This is the equivalent code being executed:
let storage =
AsyncStorage::open(StorageConfiguration::new("my-db.bonsaidb").with_schema::<MySchema>()?)
.await?;
storage.create_database::<MySchema>("default", true).await?;
let db = storage.database::<MySchema>("default").await?;
Using multiple databases
This example shows how to use AsyncStorage
to create and use multiple
databases with multiple schemas:
use bonsaidb_core::{
connection::AsyncStorageConnection,
schema::{Collection, Schema},
};
use bonsaidb_local::{
config::{Builder, StorageConfiguration},
AsyncStorage,
};
use serde::{Deserialize, Serialize};
#[derive(Debug, Schema)]
#[schema(name = "my-schema", collections = [BlogPost, Author])]
struct MySchema;
#[derive(Debug, Serialize, Deserialize, Collection)]
#[collection(name = "blog-posts")]
struct BlogPost {
pub title: String,
pub contents: String,
pub author_id: u64,
}
#[derive(Debug, Serialize, Deserialize, Collection)]
#[collection(name = "blog-posts")]
struct Author {
pub name: String,
}
let storage = AsyncStorage::open(
StorageConfiguration::new("my-db.bonsaidb")
.with_schema::<BlogPost>()?
.with_schema::<MySchema>()?,
)
.await?;
storage
.create_database::<BlogPost>("ectons-blog", true)
.await?;
let ectons_blog = storage.database::<BlogPost>("ectons-blog").await?;
storage
.create_database::<MySchema>("another-db", true)
.await?;
let another_db = storage.database::<MySchema>("another-db").await?;
Implementations
Creates or opens a multi-database AsyncStorage
with its data stored in directory
.
Restores all data from a previously stored backup location
.
Stores a copy of all data in this instance to location
.
pub fn with_effective_permissions(
&self,
effective_permissions: Permissions
) -> Option<AsyncStorage>
pub fn with_effective_permissions(
&self,
effective_permissions: Permissions
) -> Option<AsyncStorage>
Restricts an unauthenticated instance to having effective_permissions
.
Returns None
if a session has already been established.
Converts this instance into its blocking version, which is able to be used without async.
Converts this instance into its blocking version, which is able to be used without async.
Returns a reference to this instance’s blocking version, which is able to be used without async.
Trait Implementations
type Database = AsyncDatabase
type Database = AsyncDatabase
The type that represents a database for this implementation.
type Authenticated = AsyncStorage
type Authenticated = AsyncStorage
The StorageConnection
type returned from authentication calls.
pub fn admin<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = <AsyncStorage as AsyncStorageConnection>::Database> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
AsyncStorage: 'async_trait,
pub fn admin<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = <AsyncStorage as AsyncStorageConnection>::Database> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
AsyncStorage: 'async_trait,
Returns the currently authenticated session, if any.
pub fn create_database_with_schema<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
schema: SchemaName,
only_if_needed: bool
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
'life1: 'async_trait,
AsyncStorage: 'async_trait,
pub fn create_database_with_schema<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
schema: SchemaName,
only_if_needed: bool
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
'life1: 'async_trait,
AsyncStorage: 'async_trait,
Creates a database named name
using the SchemaName
schema
. Read more
pub fn database<'life0, 'life1, 'async_trait, DB>(
&'life0 self,
name: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<<AsyncStorage as AsyncStorageConnection>::Database, Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
'life1: 'async_trait,
DB: 'async_trait + Schema,
AsyncStorage: 'async_trait,
pub fn database<'life0, 'life1, 'async_trait, DB>(
&'life0 self,
name: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<<AsyncStorage as AsyncStorageConnection>::Database, Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
'life1: 'async_trait,
DB: 'async_trait + Schema,
AsyncStorage: 'async_trait,
Returns a reference to database name
with schema DB
.
Deletes a database named name
. Read more
Lists the databases in this storage.
pub fn list_available_schemas<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<SchemaName, Global>, Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
AsyncStorage: 'async_trait,
pub fn list_available_schemas<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<SchemaName, Global>, Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
AsyncStorage: 'async_trait,
Lists the SchemaName
s registered with this storage.
Creates a user.
Deletes a user.
pub fn set_user_password<'user, 'life0, 'async_trait, U>(
&'life0 self,
user: U,
password: SensitiveString
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
AsyncStorage: 'async_trait,
pub fn set_user_password<'user, 'life0, 'async_trait, U>(
&'life0 self,
user: U,
password: SensitiveString
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
AsyncStorage: 'async_trait,
Sets a user’s password.
pub fn authenticate<'user, 'life0, 'async_trait, U>(
&'life0 self,
user: U,
authentication: Authentication
) -> Pin<Box<dyn Future<Output = Result<AsyncStorage, Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
AsyncStorage: 'async_trait,
pub fn authenticate<'user, 'life0, 'async_trait, U>(
&'life0 self,
user: U,
authentication: Authentication
) -> Pin<Box<dyn Future<Output = Result<AsyncStorage, Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
AsyncStorage: 'async_trait,
Authenticates as a user with a authentication method.
pub fn assume_identity<'life0, 'life1, 'async_trait>(
&'life0 self,
identity: IdentityReference<'life1>
) -> Pin<Box<dyn Future<Output = Result<<AsyncStorage as AsyncStorageConnection>::Authenticated, Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
'life1: 'async_trait,
AsyncStorage: 'async_trait,
pub fn assume_identity<'life0, 'life1, 'async_trait>(
&'life0 self,
identity: IdentityReference<'life1>
) -> Pin<Box<dyn Future<Output = Result<<AsyncStorage as AsyncStorageConnection>::Authenticated, Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
'life1: 'async_trait,
AsyncStorage: 'async_trait,
Assumes the identity
. If successful, the returned instance will have
the merged permissions of the current authentication session and the
permissions from identity
. Read more
pub fn add_permission_group_to_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
permission_group: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'group: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
G: 'async_trait + Nameable<'group, u64> + Send + Sync,
AsyncStorage: 'async_trait,
pub fn add_permission_group_to_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
permission_group: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'group: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
G: 'async_trait + Nameable<'group, u64> + Send + Sync,
AsyncStorage: 'async_trait,
Adds a user to a permission group.
pub fn remove_permission_group_from_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
permission_group: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'group: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
G: 'async_trait + Nameable<'group, u64> + Send + Sync,
AsyncStorage: 'async_trait,
pub fn remove_permission_group_from_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
permission_group: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'group: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
G: 'async_trait + Nameable<'group, u64> + Send + Sync,
AsyncStorage: 'async_trait,
Removes a user from a permission group.
pub fn add_role_to_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
role: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'group: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
G: 'async_trait + Nameable<'group, u64> + Send + Sync,
AsyncStorage: 'async_trait,
pub fn add_role_to_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
role: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'group: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
G: 'async_trait + Nameable<'group, u64> + Send + Sync,
AsyncStorage: 'async_trait,
Adds a user to a permission group.
pub fn remove_role_from_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
role: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'group: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
G: 'async_trait + Nameable<'group, u64> + Send + Sync,
AsyncStorage: 'async_trait,
pub fn remove_role_from_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
role: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>> where
'user: 'async_trait,
'group: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
G: 'async_trait + Nameable<'group, u64> + Send + Sync,
AsyncStorage: 'async_trait,
Removes a user from a permission group.
Creates a database named name
with the Schema
provided. Read more
Performs the conversion.
Performs the conversion.
fn allowed_to<'a, R, P>(&self, resource_name: R, action: &P) -> bool where
R: AsRef<[Identifier<'a>]>,
P: Action,
fn allowed_to<'a, R, P>(&self, resource_name: R, action: &P) -> bool where
R: AsRef<[Identifier<'a>]>,
P: Action,
Checks if action
is permitted against resource_name
.
Checks if action
is permitted against resource_name
. If permission
is denied, returns a PermissionDenied
error. Read more
Auto Trait Implementations
impl !RefUnwindSafe for AsyncStorage
impl Send for AsyncStorage
impl Sync for AsyncStorage
impl Unpin for AsyncStorage
impl !UnwindSafe for AsyncStorage
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more