1mod capability;
2pub use capability::{Capability, StorageTypes};
3
4mod response;
5pub use response::{Response, Rows};
6
7pub mod operation;
8pub use operation::{IsolationLevel, Operation};
9
10use crate::{
11 async_trait,
12 schema::{
13 db::{AppliedMigration, Migration, SchemaDiff},
14 Schema,
15 },
16};
17
18use std::{borrow::Cow, fmt::Debug, sync::Arc};
19
20#[async_trait]
21pub trait Driver: Debug + Send + Sync + 'static {
22 fn url(&self) -> Cow<'_, str>;
24
25 fn capability(&self) -> &'static Capability;
27
28 async fn connect(&self) -> crate::Result<Box<dyn Connection>>;
33
34 fn max_connections(&self) -> Option<usize> {
37 None
38 }
39
40 fn generate_migration(&self, schema_diff: &SchemaDiff<'_>) -> Migration;
42
43 async fn reset_db(&self) -> crate::Result<()>;
45}
46
47#[async_trait]
48pub trait Connection: Debug + Send + 'static {
49 async fn exec(&mut self, schema: &Arc<Schema>, plan: Operation) -> crate::Result<Response>;
51
52 async fn push_schema(&mut self, _schema: &Schema) -> crate::Result<()>;
55
56 async fn applied_migrations(&mut self) -> crate::Result<Vec<AppliedMigration>>;
58
59 async fn apply_migration(
61 &mut self,
62 id: u64,
63 name: String,
64 migration: &Migration,
65 ) -> crate::Result<()>;
66}