pub trait StorageConnection:
Sized
+ HasSession
+ Send
+ Sync {
type Database: Connection;
type Authenticated: StorageConnection;
Show 18 methods
// Required methods
fn admin(&self) -> Self::Database;
fn database<DB>(&self, name: &str) -> Result<Self::Database, Error>
where DB: Schema;
fn create_database_with_schema(
&self,
name: &str,
schema: SchemaName,
only_if_needed: bool,
) -> Result<(), Error>;
fn delete_database(&self, name: &str) -> Result<(), Error>;
fn list_databases(&self) -> Result<Vec<Database>, Error>;
fn list_available_schemas(&self) -> Result<Vec<SchemaSummary>, Error>;
fn create_user(&self, username: &str) -> Result<u64, Error>;
fn delete_user<'user, U>(&self, user: U) -> Result<(), Error>
where U: Nameable<'user, u64> + Send + Sync;
fn set_user_password<'user, U>(
&self,
user: U,
password: SensitiveString,
) -> Result<(), Error>
where U: Nameable<'user, u64> + Send + Sync;
fn authenticate(
&self,
authentication: Authentication,
) -> Result<Self::Authenticated, Error>;
fn assume_identity(
&self,
identity: IdentityReference<'_>,
) -> Result<Self::Authenticated, Error>;
fn add_permission_group_to_user<'user, 'group, U, G>(
&self,
user: U,
permission_group: G,
) -> Result<(), Error>
where U: Nameable<'user, u64> + Send + Sync,
G: Nameable<'group, u64> + Send + Sync;
fn remove_permission_group_from_user<'user, 'group, U, G>(
&self,
user: U,
permission_group: G,
) -> Result<(), Error>
where U: Nameable<'user, u64> + Send + Sync,
G: Nameable<'group, u64> + Send + Sync;
fn add_role_to_user<'user, 'role, U, R>(
&self,
user: U,
role: R,
) -> Result<(), Error>
where U: Nameable<'user, u64> + Send + Sync,
R: Nameable<'role, u64> + Send + Sync;
fn remove_role_from_user<'user, 'role, U, R>(
&self,
user: U,
role: R,
) -> Result<(), Error>
where U: Nameable<'user, u64> + Send + Sync,
R: Nameable<'role, u64> + Send + Sync;
// Provided methods
fn create_database<DB>(
&self,
name: &str,
only_if_needed: bool,
) -> Result<Self::Database, Error>
where DB: Schema { ... }
fn authenticate_with_token(
&self,
id: u64,
token: &SensitiveString,
) -> Result<<Self::Authenticated as StorageConnection>::Authenticated, Error> { ... }
fn authenticate_with_password<'name, User>(
&self,
user: User,
password: SensitiveString,
) -> Result<Self::Authenticated, Error>
where User: Nameable<'name, u64> { ... }
}Expand description
Functions for interacting with a multi-database BonsaiDb instance.
Required Associated Types§
Sourcetype Database: Connection
type Database: Connection
The type that represents a database for this implementation.
Sourcetype Authenticated: StorageConnection
type Authenticated: StorageConnection
The StorageConnection type returned from authentication calls.
Required Methods§
Sourcefn database<DB>(&self, name: &str) -> Result<Self::Database, Error>where
DB: Schema,
fn database<DB>(&self, name: &str) -> Result<Self::Database, Error>where
DB: Schema,
Returns a reference to database name with schema DB.
Sourcefn create_database_with_schema(
&self,
name: &str,
schema: SchemaName,
only_if_needed: bool,
) -> Result<(), Error>
fn create_database_with_schema( &self, name: &str, schema: SchemaName, only_if_needed: bool, ) -> Result<(), Error>
Creates a database named name using the SchemaName schema.
§Errors
Error::InvalidDatabaseName:namemust begin with an alphanumeric character ([a-zA-Z0-9]), and all remaining characters must be alphanumeric, a period (.), or a hyphen (-).Error::DatabaseNameAlreadyTaken:namewas already used for a previous database name. Returned ifonly_if_neededis false.
Sourcefn delete_database(&self, name: &str) -> Result<(), Error>
fn delete_database(&self, name: &str) -> Result<(), Error>
Deletes a database named name.
§Errors
Error::DatabaseNotFound: databasenamedoes not exist.Error::Other: an error occurred while deleting files.
Sourcefn list_available_schemas(&self) -> Result<Vec<SchemaSummary>, Error>
fn list_available_schemas(&self) -> Result<Vec<SchemaSummary>, Error>
Lists the SchemaNames registered with this storage.
Sourcefn delete_user<'user, U>(&self, user: U) -> Result<(), Error>
fn delete_user<'user, U>(&self, user: U) -> Result<(), Error>
Deletes a user.
Sourcefn set_user_password<'user, U>(
&self,
user: U,
password: SensitiveString,
) -> Result<(), Error>
fn set_user_password<'user, U>( &self, user: U, password: SensitiveString, ) -> Result<(), Error>
Sets a user’s password.
Sourcefn authenticate(
&self,
authentication: Authentication,
) -> Result<Self::Authenticated, Error>
fn authenticate( &self, authentication: Authentication, ) -> Result<Self::Authenticated, Error>
Authenticates using the active session, returning a connection with a new session upon success. The existing connection will remain usable with the existing authentication, if any.
Sourcefn assume_identity(
&self,
identity: IdentityReference<'_>,
) -> Result<Self::Authenticated, Error>
fn assume_identity( &self, identity: IdentityReference<'_>, ) -> Result<Self::Authenticated, Error>
Assumes the identity. If successful, the returned instance will have
the permissions from identity.
Sourcefn add_permission_group_to_user<'user, 'group, U, G>(
&self,
user: U,
permission_group: G,
) -> Result<(), Error>
fn add_permission_group_to_user<'user, 'group, U, G>( &self, user: U, permission_group: G, ) -> Result<(), Error>
Adds a user to a permission group.
Sourcefn remove_permission_group_from_user<'user, 'group, U, G>(
&self,
user: U,
permission_group: G,
) -> Result<(), Error>
fn remove_permission_group_from_user<'user, 'group, U, G>( &self, user: U, permission_group: G, ) -> Result<(), Error>
Removes a user from a permission group.
Sourcefn add_role_to_user<'user, 'role, U, R>(
&self,
user: U,
role: R,
) -> Result<(), Error>
fn add_role_to_user<'user, 'role, U, R>( &self, user: U, role: R, ) -> Result<(), Error>
Adds a user to a permission group.
Provided Methods§
Sourcefn create_database<DB>(
&self,
name: &str,
only_if_needed: bool,
) -> Result<Self::Database, Error>where
DB: Schema,
fn create_database<DB>(
&self,
name: &str,
only_if_needed: bool,
) -> Result<Self::Database, Error>where
DB: Schema,
Creates a database named name with the Schema provided.
§Errors
Error::InvalidDatabaseName:namemust begin with an alphanumeric character ([a-zA-Z0-9]), and all remaining characters must be alphanumeric, a period (.), or a hyphen (-).Error::DatabaseNameAlreadyTaken:namewas already used for a previous database name. Returned ifonly_if_neededis false.
Sourcefn authenticate_with_token(
&self,
id: u64,
token: &SensitiveString,
) -> Result<<Self::Authenticated as StorageConnection>::Authenticated, Error>
fn authenticate_with_token( &self, id: u64, token: &SensitiveString, ) -> Result<<Self::Authenticated as StorageConnection>::Authenticated, Error>
Authenticates using an
AuthenticationToken. If
successful, the returned instance will have the permissions from
identity.
Sourcefn authenticate_with_password<'name, User>(
&self,
user: User,
password: SensitiveString,
) -> Result<Self::Authenticated, Error>
fn authenticate_with_password<'name, User>( &self, user: User, password: SensitiveString, ) -> Result<Self::Authenticated, Error>
Authenticates a User using a password. If
successful, the returned instance will have the permissions from
identity.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".