From ae57359353cf31ff374a8932999742920878bf00 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Wed, 12 Oct 2022 22:52:15 +0200 Subject: upgrade to diesel 2.0 --- planetwars-server/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'planetwars-server/src/lib.rs') diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs index 1696f1a..316458c 100644 --- a/planetwars-server/src/lib.rs +++ b/planetwars-server/src/lib.rs @@ -8,7 +8,7 @@ pub mod routes; pub mod schema; pub mod util; -use std::ops::Deref; +use std::ops::{Deref, DerefMut}; use std::path::PathBuf; use std::sync::Arc; use std::{fs, net::SocketAddr}; @@ -70,9 +70,9 @@ pub struct GlobalConfig { const SIMPLEBOT_PATH: &str = "../simplebot/simplebot.py"; pub async fn seed_simplebot(config: &GlobalConfig, pool: &ConnectionPool) { - let conn = pool.get().await.expect("could not get database connection"); + let mut conn = pool.get().await.expect("could not get database connection"); // This transaction is expected to fail when simplebot already exists. - let _res = conn.transaction::<(), diesel::result::Error, _>(|| { + let _res = conn.transaction::<(), diesel::result::Error, _>(|conn| { use db::bots::NewBot; let new_bot = NewBot { @@ -80,12 +80,12 @@ pub async fn seed_simplebot(config: &GlobalConfig, pool: &ConnectionPool) { owner_id: None, }; - let simplebot = db::bots::create_bot(&new_bot, &conn)?; + let simplebot = db::bots::create_bot(&new_bot, conn)?; let simplebot_code = std::fs::read_to_string(SIMPLEBOT_PATH).expect("could not read simplebot code"); - modules::bots::save_code_string(&simplebot_code, Some(simplebot.id), &conn, config)?; + modules::bots::save_code_string(&simplebot_code, Some(simplebot.id), conn, config)?; println!("initialized simplebot"); @@ -209,6 +209,12 @@ impl Deref for DatabaseConnection { } } +impl DerefMut for DatabaseConnection { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + #[async_trait] impl FromRequest for DatabaseConnection where -- cgit v1.2.3