| 47 | } |
| 48 | |
| 49 | fn sqlite_establish_connection( |
| 50 | url: &str, |
| 51 | ) -> BoxFuture<'_, ConnectionResult<SyncConnectionWrapper<SqliteConnection>>> { |
| 52 | let url = url.to_string(); |
| 53 | tokio::task::spawn_blocking( |
| 54 | move || -> ConnectionResult<SyncConnectionWrapper<SqliteConnection>> { |
| 55 | let mut conn = SqliteConnection::establish(&url)?; |
| 56 | |
| 57 | use diesel::connection::SimpleConnection; |
| 58 | let conf = config::get(); |
| 59 | let pragmas = &conf |
| 60 | .sqlite |
| 61 | .pragmas |
| 62 | .iter() |
| 63 | .map(|p| format!("PRAGMA {};", p)) |
| 64 | .collect::<Vec<String>>() |
| 65 | .join(""); |
| 66 | conn.batch_execute(pragmas) |
| 67 | .map_err(|err| ConnectionError::BadConnection(err.to_string()))?; |
| 68 | Ok(SyncConnectionWrapper::new(conn)) |
| 69 | }, |
| 70 | ) |
| 71 | .unwrap_or_else(|err| Err(ConnectionError::BadConnection(err.to_string()))) |
| 72 | .boxed() |
| 73 | } |
| 74 | |
| 75 | fn get_async_db_pool() -> Result<AsyncSqlitePool> { |
| 76 | let pool_r = ASYNC_SQLITE_POOL.read().unwrap(); |