Count items in database as much as possible (#344)
* Count items in database as much as possible * Fix the tests * Remove two useless queries * Run pragma directive before each sqlite connection * Pragma for tests too * Remove debug messages
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use diesel::r2d2::{ConnectionManager, Pool, PooledConnection};
|
||||
use diesel::{dsl::sql_query, r2d2::{ConnectionManager, CustomizeConnection, Error as ConnError, Pool, PooledConnection}, ConnectionError, RunQueryDsl};
|
||||
use rocket::{
|
||||
http::Status,
|
||||
request::{self, FromRequest},
|
||||
@@ -38,3 +38,15 @@ impl Deref for DbConn {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
// Execute a pragma for every new sqlite connection
|
||||
#[derive(Debug)]
|
||||
pub struct PragmaForeignKey;
|
||||
impl CustomizeConnection<Connection, ConnError> for PragmaForeignKey {
|
||||
#[cfg(feature = "sqlite")] // will default to an empty function for postgres
|
||||
fn on_acquire(&self, conn: &mut Connection) -> Result<(), ConnError> {
|
||||
sql_query("PRAGMA foreign_keys = on;").execute(conn)
|
||||
.map(|_| ())
|
||||
.map_err(|_| ConnError::ConnectionError(ConnectionError::BadConnection(String::from("PRAGMA foreign_keys = on failed"))))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user