From 2654496f8c429bc084081dcf11fcc14e99933d71 Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 18 Feb 2023 15:07:31 -0700 Subject: [PATCH] update to sqlx 6.2 --- Cargo.toml | 2 +- src/entity/gateway/postgres/postgres.rs | 68 ++++++++++++------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d62e110..c2e511d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ async-recursion= "1.0.0" lazy_static = "1.4.0" barrel = { version = "0.6.5", features = ["pg"] } refinery = { version = "0.5.0", features = ["postgres"] } -sqlx = { version = "0.5.10", features = ["runtime-async-std-native-tls", "postgres", "json", "chrono"] } +sqlx = { version = "0.6.2", features = ["runtime-async-std-native-tls", "postgres", "json", "chrono"] } strum = "0.19.5" strum_macros = "0.19" anyhow = { version = "1.0.68", features = ["backtrace"] } diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index 9bb3be5..c31217f 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -179,7 +179,7 @@ async fn create_user(conn: &mut sqlx::PgConnection, user: NewUserAccountEntity) async fn get_user_by_id(conn: &mut sqlx::PgConnection, id: UserAccountId) -> Result { let user = sqlx::query_as::<_, PgUserAccount>("select * from user_accounts where id = $1") - .bind(id.0) + .bind(id.0 as i32) .fetch_one(conn).await?; Ok(user.into()) } @@ -200,8 +200,8 @@ async fn save_user(conn: &mut sqlx::PgConnection, user: &UserAccountEntity) -> R .bind(&user.password) .bind(user.banned_until) .bind(user.muted_until) - .bind(user.flags) - .bind(user.id.0) + .bind(user.flags as i32) + .bind(user.id.0 as i32) .execute(conn).await?; Ok(()) } @@ -210,7 +210,7 @@ async fn create_user_settings(conn: &mut sqlx::PgConnection, settings: NewUserSe { let new_settings = sqlx::query_as::<_, PgUserSettings>("insert into user_settings (user_account, blocked_users, key_config, joystick_config, option_flags, shortcuts, symbol_chats, team_name) values ($1, $2, $3, $4, $5, $6, $7, $8) returning *;") - .bind(settings.user_id.0) + .bind(settings.user_id.0 as i32) .bind(settings.settings.blocked_users.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::>()) .bind(settings.settings.keyboard_config.to_vec()) .bind(settings.settings.gamepad_config.to_vec()) @@ -225,7 +225,7 @@ async fn create_user_settings(conn: &mut sqlx::PgConnection, settings: NewUserSe async fn get_user_settings_by_user(conn: &mut sqlx::PgConnection, user: &UserAccountEntity) -> Result { let settings = sqlx::query_as::<_, PgUserSettings>("select * from user_settings where user_account = $1") - .bind(user.id.0) + .bind(user.id.0 as i32) .fetch_one(conn).await?; Ok(settings.into()) } @@ -236,11 +236,11 @@ async fn save_user_settings(conn: &mut sqlx::PgConnection, settings: &UserSettin .bind(settings.settings.blocked_users.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::>()) .bind(&settings.settings.keyboard_config.to_vec()) .bind(&settings.settings.gamepad_config.to_vec()) - .bind(settings.settings.option_flags) + .bind(settings.settings.option_flags as i32) .bind(&settings.settings.shortcuts.to_vec()) .bind(&settings.settings.symbol_chats.to_vec()) .bind(settings.settings.team_name.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::>()) - .bind(settings.id.0) + .bind(settings.id.0 as i32) .execute(conn).await?; Ok(()) } @@ -263,7 +263,7 @@ async fn create_character(conn: &mut sqlx::PgConnection, char: NewCharacterEntit $26, $27, $28, $29, $30) returning *;"#; let character = sqlx::query_as::<_, PgCharacter>(q) - .bind(char.user_id.0) + .bind(char.user_id.0 as i32) .bind(char.slot as i16) .bind(char.name) .bind(char.exp as i32) @@ -301,7 +301,7 @@ async fn create_character(conn: &mut sqlx::PgConnection, char: NewCharacterEntit async fn get_characters_by_user(conn: &mut sqlx::PgConnection, user: &UserAccountEntity) -> Result<[Option; 4], GatewayError> { let stream = sqlx::query_as::<_, PgCharacter>("select * from player_character where user_account = $1 and slot < 4 order by created_at;") - .bind(user.id.0) + .bind(user.id.0 as i32) .fetch(conn); Ok(stream.fold(core::array::from_fn(|_| None), |mut acc, char| async move { @@ -321,7 +321,7 @@ async fn save_character(conn: &mut sqlx::PgConnection, char: &CharacterEntity) - evade=$24, luck=$25, hp=$26, tp=$27, tech_menu=$28, option_flags=$29, playtime=$30 where id=$31;"#; sqlx::query(q) - .bind(char.user_id.0) // $1 + .bind(char.user_id.0 as i32) // $1 .bind(char.slot as i16) // $2 .bind(&char.name) // $3 .bind(char.exp as i32) // $4 @@ -371,7 +371,7 @@ async fn create_item(conn: &mut sqlx::PgConnection, item: NewItemEntity) -> Resu async fn add_item_note(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, item_note: ItemNote) -> Result<(), GatewayError> { sqlx::query("insert into item_note(item, note) values ($1, $2)") - .bind(item_id.0) + .bind(item_id.0 as i32) .bind(sqlx::types::Json(PgItemNoteDetail::from(item_note))) .execute(conn).await?; Ok(()) @@ -380,7 +380,7 @@ async fn add_item_note(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, it async fn feed_mag(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) -> Result<(), GatewayError> { sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);") - .bind(mag_item_id.0) + .bind(mag_item_id.0 as i32) .bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::FeedMag{food: *tool_item_id}))) .execute(conn).await?; Ok(()) @@ -389,7 +389,7 @@ async fn feed_mag(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, too async fn change_mag_owner(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, character: &CharacterEntity) -> Result<(), GatewayError> { sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);") - .bind(mag_item_id.0) + .bind(mag_item_id.0 as i32) .bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::OwnerChange(character.char_class, character.section_id)))) .execute(conn).await?; Ok(()) @@ -398,7 +398,7 @@ async fn change_mag_owner(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntit async fn use_mag_cell(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, mag_cell_id: &ItemEntityId) -> Result<(), GatewayError> { sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);") - .bind(mag_item_id.0) + .bind(mag_item_id.0 as i32) .bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::MagCell(*mag_cell_id)))) .execute(conn).await?; Ok(()) @@ -407,7 +407,7 @@ async fn use_mag_cell(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, async fn add_weapon_modifier(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { sqlx::query("insert into weapon_modifier (weapon, modifier) values ($1, $2);") - .bind(item_id.0) + .bind(item_id.0 as i32) .bind(sqlx::types::Json(modifier)) .execute(conn).await?; Ok(()) @@ -417,7 +417,7 @@ async fn get_character_inventory(conn: &mut sqlx::PgConnection, char_id: &Charac { let conn = Arc::new(Mutex::new(conn.begin().await?)); // this is some degen shit let inventory = sqlx::query_as::<_, PgInventoryEntity>("select * from inventory where pchar = $1") - .bind(char_id.0) + .bind(char_id.0 as i32) .fetch_one(&mut **conn.lock().await).await?; Ok(InventoryEntity::new( @@ -442,14 +442,14 @@ async fn get_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEn let bank = match bank_identifier { BankIdentifier::Character => { sqlx::query_as::<_, PgInventoryEntity>("select * from bank where pchar = $1") - .bind(char_id.0) + .bind(char_id.0 as i32) .fetch_one(&mut **conn.lock().await).await? }, BankIdentifier::Shared(bank_name) => { sqlx::query_as::<_, PgInventoryEntity>("select player_character.id as pchar, shared_bank.items as items from shared_bank join player_character on shared_bank.user_account = player_character.user_account where player_character.id = $1 and shared_bank.name = $2") - .bind(char_id.0) + .bind(char_id.0 as i32) .bind(&bank_name.0) .fetch_optional(&mut **conn.lock().await) .await? @@ -492,7 +492,7 @@ async fn set_character_inventory(conn: &mut sqlx::PgConnection, char_id: &Charac .collect::>(); sqlx::query("insert into inventory (pchar, items) values ($1, $2) on conflict (pchar) do update set items = $2") - .bind(char_id.0) + .bind(char_id.0 as i32) .bind(sqlx::types::Json(inventory)) .execute(conn) .await?; @@ -517,7 +517,7 @@ async fn set_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEn match bank_identifier { BankIdentifier::Character => { sqlx::query("insert into bank (pchar, items, name) values ($1, $2, '') on conflict (pchar, name) do update set items = $2") - .bind(char_id.0) + .bind(char_id.0 as i32) .bind(sqlx::types::Json(bank)) .execute(conn) .await?; @@ -527,7 +527,7 @@ async fn set_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEn select player_character.user_account, $2, $3 from player_character where player_character.id = $1 on conflict (user_account, name) do update set items = $2;") - .bind(char_id.0) + .bind(char_id.0 as i32) .bind(sqlx::types::Json(bank)) .bind(&bank_name.0) .execute(conn) @@ -540,7 +540,7 @@ async fn set_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEn async fn get_character_equips(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId) -> Result { let equips = sqlx::query_as::<_, PgEquipped>("select * from equipped where pchar = $1") - .bind(char_id.0) + .bind(char_id.0 as i32) .fetch_one(conn) .await?; @@ -551,7 +551,7 @@ async fn set_character_equips(conn: &mut sqlx::PgConnection, char_id: &Character { sqlx::query(r#"insert into equipped (pchar, weapon, armor, shield, unit0, unit1, unit2, unit3, mag) values ($1, $2, $3, $4, $5, $6, $7, $8, $9) on conflict (pchar) do update set weapon=$2, armor=$3, shield=$4, unit0=$5, unit1=$6, unit2=$7, unit3=$8, mag=$9"#) - .bind(char_id.0) + .bind(char_id.0 as i32) .bind(equips.weapon.map(|i| i.0 as i32)) .bind(equips.armor.map(|i| i.0 as i32)) .bind(equips.shield.map(|i| i.0 as i32)) @@ -569,7 +569,7 @@ async fn set_character_equips(conn: &mut sqlx::PgConnection, char_id: &Character async fn set_character_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, meseta: Meseta) -> Result<(), GatewayError> { sqlx::query("insert into character_meseta values ($1, $2) on conflict (pchar) do update set meseta = $2") - .bind(char_id.0) + .bind(char_id.0 as i32) .bind(meseta.0 as i32) .execute(conn) .await?; @@ -581,7 +581,7 @@ async fn get_character_meseta(conn: &mut sqlx::PgConnection, char_id: &Character #[derive(sqlx::FromRow)] struct PgMeseta(i32); let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where pchar = $1"#) - .bind(char_id.0) + .bind(char_id.0 as i32) .fetch_one(conn) .await?; Ok(Meseta(meseta.0 as u32)) @@ -592,7 +592,7 @@ async fn set_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit match bank_identifier { BankIdentifier::Character => { sqlx::query("insert into bank_meseta values ($1, '', $2) on conflict (pchar, bank) do update set meseta = $2") - .bind(char_id.0) + .bind(char_id.0 as i32) .bind(meseta.0 as i32) .execute(conn) .await?; @@ -602,7 +602,7 @@ async fn set_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit select player_character.user_account, $2, $3 from player_character where player_character.id = $1 on conflict (user_account, name) do update set meseta = $3") - .bind(char_id.0) + .bind(char_id.0 as i32) .bind(&bank_name.0) .bind(meseta.0 as i32) .execute(conn) @@ -621,7 +621,7 @@ async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit let meseta = match bank_identifier { BankIdentifier::Character => { sqlx::query_as::<_, PgMeseta>(r#"select meseta from bank_meseta where pchar = $1"#) - .bind(char_id.0) + .bind(char_id.0 as i32) .fetch_one(conn) .await? }, @@ -629,7 +629,7 @@ async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit sqlx::query_as::<_, PgMeseta>(r#"select shared_bank_meseta.meseta from shared_bank_meseta join player_character on shared_bank_meseta.user_account = player_character.user_account where player_character.id = $1 and shared_bank_meseta.name = $2"#) - .bind(char_id.0) + .bind(char_id.0 as i32) .bind(&bank_name.0) .fetch_optional(conn) .await? @@ -642,8 +642,8 @@ async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit async fn create_trade(conn: &mut sqlx::PgConnection, char_id1: &CharacterEntityId, char_id2: &CharacterEntityId) -> Result { let trade = sqlx::query_as::<_, PgTradeEntity>(r#"insert into trades (character1, character2) values ($1, $2) returning *;"#) - .bind(char_id1.0) - .bind(char_id2.0) + .bind(char_id1.0 as i32) + .bind(char_id2.0 as i32) .fetch_one(conn) .await?; Ok(trade.into()) @@ -652,8 +652,8 @@ async fn create_trade(conn: &mut sqlx::PgConnection, char_id1: &CharacterEntityI async fn set_character_playtime(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, playtime: u32) -> Result<(), GatewayError> { sqlx::query(r#"update player_character set playtime=$2 where id=$1;"#) - .bind(char_id.0) - .bind(playtime) + .bind(char_id.0 as i32) + .bind(playtime as i32) .execute(conn) .await?; Ok(()) @@ -674,7 +674,7 @@ async fn create_room(conn: &mut sqlx::PgConnection, room: NewRoomEntity) -> Resu async fn add_room_note(conn: &mut sqlx::PgConnection, room_id: RoomEntityId, note: RoomNote) -> Result<(), GatewayError> { sqlx::query("insert into room_note (room, note) values ($1, $2)") - .bind(room_id.0) + .bind(room_id.0 as i32) .bind(sqlx::types::Json(note)) .execute(conn) .await?;