aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/lib.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-10-12 22:52:15 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-10-12 22:52:15 +0200
commitae57359353cf31ff374a8932999742920878bf00 (patch)
tree0db27d394a2a61a5cc94e73014c82954829c1338 /planetwars-server/src/lib.rs
parented016773b112460ebbf0ff023b0915545229ed41 (diff)
downloadplanetwars.dev-ae57359353cf31ff374a8932999742920878bf00.tar.xz
planetwars.dev-ae57359353cf31ff374a8932999742920878bf00.zip
upgrade to diesel 2.0
Diffstat (limited to 'planetwars-server/src/lib.rs')
-rw-r--r--planetwars-server/src/lib.rs16
1 files changed, 11 insertions, 5 deletions
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<B> FromRequest<B> for DatabaseConnection
where