58 lines
1.3 KiB
Rust
58 lines
1.3 KiB
Rust
//! Drivers
|
|
//!
|
|
//! Drivers represent a connection to a specific type of database engine
|
|
use std::fmt;
|
|
|
|
#[cfg(feature = "postgres")]
|
|
mod postgres;
|
|
|
|
#[cfg(feature = "sqlite")]
|
|
mod sqlite;
|
|
|
|
#[cfg(feature = "mysql")]
|
|
mod mysql;
|
|
|
|
#[derive(Debug)]
|
|
struct Connection;
|
|
|
|
/// Result for a db query
|
|
#[derive(Debug)]
|
|
struct QueryResult;
|
|
|
|
struct DriverBase {
|
|
escape_char_open: char,
|
|
escape_char_close: char,
|
|
has_truncate: bool,
|
|
}
|
|
|
|
/// Database Driver Trait
|
|
///
|
|
/// Interface between the database connection library and the query builder
|
|
pub trait DatabaseDriver: fmt::Debug {
|
|
/// Get which characters are used to delimit identifiers
|
|
/// such as tables, and columns
|
|
fn _quotes(&self) -> (char, char) {
|
|
('"','"')
|
|
}
|
|
|
|
/// Vector version of `quote_identifier`
|
|
fn quote_identifiers(&self, identifiers: Vec<String>) -> Vec<String> {
|
|
let mut output: Vec<String> = vec![];
|
|
|
|
for identifier in identifiers {
|
|
output.push(self.quote_identifier(&identifier));
|
|
}
|
|
|
|
output
|
|
}
|
|
|
|
/// Quote the identifiers passed, so the database does not
|
|
/// normalize the identifiers (eg, table, column, etc.)
|
|
fn quote_identifier(&self, identifier: &str) -> String {
|
|
identifier.to_string()
|
|
}
|
|
|
|
/// Runs a basic sql query on the database
|
|
fn query(&self, query: &str) -> Result<(), ()>;
|
|
}
|