Federated blogging application, thanks to ActivityPub https://joinplu.me
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.5 KiB

use crate::Connection;
use diesel::r2d2::{ConnectionManager, CustomizeConnection, Error as ConnError, Pool};
#[cfg(feature = "sqlite")]
use diesel::{dsl::sql_query, ConnectionError, RunQueryDsl};
use rocket_contrib::databases::diesel;
pub type DbPool = Pool<ConnectionManager<Connection>>;
// From rocket documentation
// Connection request guard type: a wrapper around an r2d2 pooled connection.
pub struct DbConn(pub Connection);
// Execute a pragma for every new sqlite connection
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;")
.map(|_| ())
.map_err(|_| {
"PRAGMA foreign_keys = on failed",
pub(crate) mod tests {
use super::*;
use diesel::Connection as _;
pub struct TestConnectionCustomizer;
impl CustomizeConnection<Connection, ConnError> for TestConnectionCustomizer {
fn on_acquire(&self, conn: &mut Connection) -> Result<(), ConnError> {