1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#[cfg(any(
  feature = "with-diesel-mysql",
  feature = "with-diesel-postgres",
  feature = "with-diesel-sqlite",
))]
pub(crate) mod diesel;
#[cfg(feature = "with-mysql_async")]
pub(crate) mod mysql_async;
#[cfg(feature = "with-rusqlite")]
pub(crate) mod rusqlite;
#[cfg(any(
  feature = "with-sqlx-mssql",
  feature = "with-sqlx-mysql",
  feature = "with-sqlx-postgres",
  feature = "with-sqlx-sqlite",
))]
pub(crate) mod sqlx;
#[cfg(feature = "tiberius")]
pub(crate) mod tiberius;
#[cfg(feature = "with-tokio-postgres")]
pub(crate) mod tokio_postgres;
pub(crate) mod unit;

use crate::{BoxFut, DbMigration, Migration, MigrationGroup};
use alloc::vec::Vec;

/// A back end is the bridge between Rust and a database.
pub trait Backend {
  /// Creates the necessary internal tables
  fn create_oapth_tables<'a>(&'a mut self) -> BoxFut<'a, crate::Result<()>>;

  /// Removes every migration of a given group `mg` that is greater than `version`.
  fn delete_migrations<'a>(
    &'a mut self,
    version: i32,
    mg: &'a MigrationGroup,
  ) -> BoxFut<'a, crate::Result<()>>;

  /// Executes arbitrary DDL or DML
  fn execute<'a>(&'a mut self, command: &'a str) -> BoxFut<'a, crate::Result<()>>;

  /// Inserts a stream of migrations of a given group.
  fn insert_migrations<'a, I>(
    &'a mut self,
    migrations: I,
    mg: &'a MigrationGroup,
  ) -> BoxFut<'a, crate::Result<()>>
  where
    I: Clone + Iterator<Item = &'a Migration> + 'a;

  /// Returns a vector with all migrations of a group within the database.
  fn migrations<'a>(
    &'a mut self,
    mg: &'a MigrationGroup,
  ) -> BoxFut<'a, crate::Result<Vec<DbMigration>>>;

  /// Executes a stream of arbitrary DDL or DML inside a transaction.
  fn transaction<'a, I, S>(&'a mut self, commands: I) -> BoxFut<'a, crate::Result<()>>
  where
    I: Iterator<Item = S> + 'a,
    S: AsRef<str>;
}