Archived
1
0
Fork 0
This repository has been archived on 2024-07-25. You can view files and clone it, but cannot push or open issues or pull requests.
migra/migra-cli/src/database.rs

32 lines
704 B
Rust
Raw Normal View History

2021-02-13 23:44:41 +03:00
use crate::StdResult;
2021-01-31 13:39:00 +03:00
2021-02-15 13:06:09 +03:00
pub trait ToSql {
fn to_sql(&self) -> String;
}
impl ToSql for &str {
fn to_sql(&self) -> String {
format!("'{}'", self)
2021-02-15 13:06:09 +03:00
}
}
pub trait TryFromSql<QueryResultRow>: Sized {
fn try_from_sql(row: QueryResultRow) -> StdResult<Self>;
}
pub trait OpenDatabaseConnection: Sized {
2021-02-15 13:06:09 +03:00
fn open(connection_string: &str) -> StdResult<Self>;
}
2021-02-15 13:06:09 +03:00
pub trait DatabaseConnection {
2021-02-15 13:06:09 +03:00
fn batch_execute(&mut self, query: &str) -> StdResult<()>;
fn execute<'b>(&mut self, query: &str, params: &'b [&'b dyn ToSql]) -> StdResult<u64>;
fn query<'b>(
2021-02-15 13:06:09 +03:00
&mut self,
query: &str,
params: &'b [&'b dyn ToSql],
) -> StdResult<Vec<Vec<String>>>;
2021-02-15 13:06:09 +03:00
}