pub struct AsyncStorage { /* private fields */ }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;
use bonsaidb_core::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;
use bonsaidb_core::schema::{Collection, Schema};
use bonsaidb_local::config::{Builder, StorageConfiguration};
use bonsaidb_local::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§
Source§impl AsyncStorage
impl AsyncStorage
Sourcepub async fn open(configuration: StorageConfiguration) -> Result<Self, Error>
pub async fn open(configuration: StorageConfiguration) -> Result<Self, Error>
Creates or opens a multi-database AsyncStorage with its data stored in directory.
Sourcepub async fn restore<L: AnyBackupLocation + 'static>(
&self,
location: L,
) -> Result<(), Error>
pub async fn restore<L: AnyBackupLocation + 'static>( &self, location: L, ) -> Result<(), Error>
Restores all data from a previously stored backup location.
Sourcepub async fn backup<L: AnyBackupLocation + 'static>(
&self,
location: L,
) -> Result<(), Error>
pub async fn backup<L: AnyBackupLocation + 'static>( &self, location: L, ) -> Result<(), Error>
Stores a copy of all data in this instance to location.
Sourcepub fn with_effective_permissions(
&self,
effective_permissions: Permissions,
) -> Option<Self>
pub fn with_effective_permissions( &self, effective_permissions: Permissions, ) -> Option<Self>
Restricts an unauthenticated instance to having effective_permissions.
Returns None if a session has already been established.
Sourcepub fn into_blocking(self) -> Storage
pub fn into_blocking(self) -> Storage
Converts this instance into its blocking version, which is able to be used without async.
Sourcepub fn to_blocking(&self) -> Storage
pub fn to_blocking(&self) -> Storage
Converts this instance into its blocking version, which is able to be used without async.
Sourcepub fn as_blocking(&self) -> &Storage
pub fn as_blocking(&self) -> &Storage
Returns a reference to this instance’s blocking version, which is able to be used without async.
Trait Implementations§
Source§impl AsyncStorageConnection for AsyncStorage
impl AsyncStorageConnection for AsyncStorage
Source§type Authenticated = AsyncStorage
type Authenticated = AsyncStorage
StorageConnection type returned from authentication calls.Source§type Database = AsyncDatabase
type Database = AsyncDatabase
Source§fn admin<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Self::Database> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn admin<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Self::Database> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§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>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn database<'life0, 'life1, 'async_trait, DB>(
&'life0 self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Self::Database, Error>> + Send + 'async_trait>>where
DB: 'async_trait + Schema,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn database<'life0, 'life1, 'async_trait, DB>(
&'life0 self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Self::Database, Error>> + Send + 'async_trait>>where
DB: 'async_trait + Schema,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
name with schema DB.Source§fn delete_database<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete_database<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
name. Read moreSource§fn list_databases<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Database>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_databases<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Database>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn list_available_schemas<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<SchemaSummary>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_available_schemas<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<SchemaSummary>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
SchemaNames registered with this storage.Source§fn create_user<'life0, 'life1, 'async_trait>(
&'life0 self,
username: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn create_user<'life0, 'life1, 'async_trait>(
&'life0 self,
username: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn delete_user<'user, 'life0, 'async_trait, U>(
&'life0 self,
user: U,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
fn delete_user<'user, 'life0, 'async_trait, U>( &'life0 self, user: U, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
Source§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>>
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>>
Source§fn authenticate<'life0, 'async_trait>(
&'life0 self,
authentication: Authentication,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn authenticate<'life0, 'async_trait>(
&'life0 self,
authentication: Authentication,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
AuthenticationToken. If
successful, the returned instance will have the permissions from
identity.Source§fn assume_identity<'life0, 'life1, 'async_trait>(
&'life0 self,
identity: IdentityReference<'life1>,
) -> Pin<Box<dyn Future<Output = Result<Self::Authenticated, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn assume_identity<'life0, 'life1, 'async_trait>(
&'life0 self,
identity: IdentityReference<'life1>,
) -> Pin<Box<dyn Future<Output = Result<Self::Authenticated, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
identity. If successful, the returned instance will have
the merged permissions of the current authentication session and the
permissions from identity.Source§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>>
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>>
Source§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>>
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>>
Source§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>>
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>>
Source§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>>
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>>
Source§fn create_database<'life0, 'life1, 'async_trait, DB>(
&'life0 self,
name: &'life1 str,
only_if_needed: bool,
) -> Pin<Box<dyn Future<Output = Result<Self::Database, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DB: 'async_trait + Schema,
Self: 'async_trait,
fn create_database<'life0, 'life1, 'async_trait, DB>(
&'life0 self,
name: &'life1 str,
only_if_needed: bool,
) -> Pin<Box<dyn Future<Output = Result<Self::Database, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DB: 'async_trait + Schema,
Self: 'async_trait,
Source§fn authenticate_with_token<'life0, 'life1, 'async_trait>(
&'life0 self,
id: u64,
token: &'life1 SensitiveString,
) -> Pin<Box<dyn Future<Output = Result<<Self::Authenticated as AsyncStorageConnection>::Authenticated, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn authenticate_with_token<'life0, 'life1, 'async_trait>(
&'life0 self,
id: u64,
token: &'life1 SensitiveString,
) -> Pin<Box<dyn Future<Output = Result<<Self::Authenticated as AsyncStorageConnection>::Authenticated, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
AuthenticationToken. If
successful, the returned instance will have the permissions from
identity.Source§fn authenticate_with_password<'name, 'life0, 'async_trait, User>(
&'life0 self,
user: User,
password: SensitiveString,
) -> Pin<Box<dyn Future<Output = Result<Self::Authenticated, Error>> + Send + 'async_trait>>
fn authenticate_with_password<'name, 'life0, 'async_trait, User>( &'life0 self, user: User, password: SensitiveString, ) -> Pin<Box<dyn Future<Output = Result<Self::Authenticated, Error>> + Send + 'async_trait>>
User using a password. If
successful, the returned instance will have the permissions from
identity.Source§impl Clone for AsyncStorage
impl Clone for AsyncStorage
Source§fn clone(&self) -> AsyncStorage
fn clone(&self) -> AsyncStorage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AsyncStorage
impl Debug for AsyncStorage
Source§impl<'a> From<&'a AsyncStorage> for Storage
impl<'a> From<&'a AsyncStorage> for Storage
Source§fn from(storage: &'a AsyncStorage) -> Self
fn from(storage: &'a AsyncStorage) -> Self
Source§impl From<AsyncStorage> for Storage
impl From<AsyncStorage> for Storage
Source§fn from(storage: AsyncStorage) -> Self
fn from(storage: AsyncStorage) -> Self
Source§impl HasSession for AsyncStorage
impl HasSession for AsyncStorage
Source§fn allowed_to<'a, R, P>(&self, resource_name: R, action: &P) -> bool
fn allowed_to<'a, R, P>(&self, resource_name: R, action: &P) -> bool
action is permitted against resource_name.Source§fn check_permission<'a, R, P>(
&self,
resource_name: R,
action: &P,
) -> Result<(), Error>
fn check_permission<'a, R, P>( &self, resource_name: R, action: &P, ) -> Result<(), Error>
action is permitted against resource_name. If permission
is denied, returns a PermissionDenied
error.Source§impl StorageNonBlocking for AsyncStorage
impl StorageNonBlocking for AsyncStorage
Auto Trait Implementations§
impl !RefUnwindSafe for AsyncStorage
impl !UnwindSafe for AsyncStorage
impl Freeze for AsyncStorage
impl Send for AsyncStorage
impl Sync for AsyncStorage
impl Unpin for AsyncStorage
impl UnsafeUnpin for AsyncStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more