//! Database Driver for SQLite //! //! Use of this driver requires enabling the `sqlite` feature. //! //! Contains database-specific query data use super::*; use slite::{params, Connection, Result}; use slite::NO_PARAMS; use std::cell::RefCell; /// The struct implementing the `DatabaseDriver` trait #[derive(Debug)] pub struct SQLiteDriver { connection: RefCell> } impl SQLiteDriver { /// Create an SQLiteDriver driver pub fn new(dsn: &str) -> Self { let mut driver = SQLiteDriver { connection: RefCell::new(None) }; driver.connect(dsn); driver } fn connect(&mut self, dsn: &str) { let connection = if dsn == ":memory:" { Connection::open_in_memory().unwrap() } else { Connection::open(dsn).unwrap() }; self.connection = RefCell::new(Some(connection)); } // pub fn query(&self, sql: &str) -> Result { // // } } impl DatabaseDriver for SQLiteDriver { // fn query(&self, sql: &str) -> Result<(), ()> { // unimplemented!(); // } fn explain(&self, sql: &str) -> String { format!("EXPLAIN QUERY PLAN {}", sql) } fn random(&self) -> String { String::from(" RANDOM()") } }