#[cfg(feature = "schema-manager-dev")]
mod clear;
mod migrate;
#[cfg(all(feature = "schema-manager-dev", feature = "std"))]
mod multi;
mod rollback;
#[cfg(feature = "schema-manager-dev")]
mod seed;
mod validate;
use crate::{
codec::CodecController,
collection::Vector,
database::{
Database, DatabaseTy, Identifier,
executor::Executor,
schema_manager::{DEFAULT_BATCH_SIZE, SchemaManagement, UserMigration},
},
misc::Lease,
};
use alloc::string::String;
#[derive(Debug)]
pub struct Commands<E> {
batch_size: usize,
executor: E,
}
impl<E> Commands<E>
where
E: Executor,
{
#[inline]
pub const fn new(batch_size: usize, executor: E) -> Self {
Self { batch_size, executor }
}
#[inline]
pub const fn with_executor(database: E) -> Self {
Self { batch_size: DEFAULT_BATCH_SIZE, executor: database }
}
#[inline]
pub const fn batch_size(&self) -> usize {
self.batch_size
}
#[cfg(test)]
#[cfg(any(feature = "mysql", feature = "postgres"))]
pub(crate) fn executor_mut(&mut self) -> &mut E {
&mut self.executor
}
fn filter_by_db<'migration, DBS, I, S>(
migrations: I,
) -> impl Clone + Iterator<Item = &'migration UserMigration<DBS, S>>
where
DBS: Lease<[DatabaseTy]> + 'migration,
I: Clone + Iterator<Item = &'migration UserMigration<DBS, S>>,
S: Lease<str> + 'migration,
{
migrations.filter(move |m| {
if m.dbs().is_empty() { true } else { m.dbs().contains(&<E::Database as Database>::TY) }
})
}
}
impl<E> Commands<E>
where
E: SchemaManagement,
{
pub async fn all_elements(
&mut self,
) -> Result<Vector<Identifier>, <E::Database as CodecController>::Error> {
let mut buffer = Vector::new();
self.executor.all_elements((&mut String::new(), &mut buffer)).await?;
Ok(buffer)
}
}