Browse Source

remote postgres dep and fix save_user function

pbs
jake 4 years ago
parent
commit
19e30f34e6
  1. 1
      Cargo.toml
  2. 3
      src/entity/gateway/postgres/models.rs
  3. 7
      src/entity/gateway/postgres/postgres.rs

1
Cargo.toml

@ -30,7 +30,6 @@ ages-prs = "0.1"
async-trait = "0.1.31" async-trait = "0.1.31"
lazy_static = "1.4.0" lazy_static = "1.4.0"
barrel = { version = "0.6.5", features = ["pg"] } barrel = { version = "0.6.5", features = ["pg"] }
postgres = "0.17.5"
refinery = { version = "0.3.0", features = ["postgres"] } refinery = { version = "0.3.0", features = ["postgres"] }
sqlx = { version = "0.4.0-beta.1", features = ["postgres", "json", "chrono"] } sqlx = { version = "0.4.0-beta.1", features = ["postgres", "json", "chrono"] }

3
src/entity/gateway/postgres/models.rs

@ -13,9 +13,6 @@ use crate::ship::map::MapArea;
use sqlx::postgres::PgPoolOptions; use sqlx::postgres::PgPoolOptions;
use sqlx::Row; use sqlx::Row;
use sqlx::Execute; use sqlx::Execute;
use postgres::{Client, NoTls};
#[derive(Debug, sqlx::FromRow)] #[derive(Debug, sqlx::FromRow)]
pub struct PgUserAccount { pub struct PgUserAccount {
id: i32, id: i32,

7
src/entity/gateway/postgres/postgres.rs

@ -14,9 +14,6 @@ use crate::entity::item::*;
use super::models::*; use super::models::*;
use sqlx::postgres::PgPoolOptions; use sqlx::postgres::PgPoolOptions;
use sqlx::Row;
use sqlx::Execute;
use postgres::{Client, NoTls};
mod embedded { mod embedded {
use refinery::embed_migrations; use refinery::embed_migrations;
@ -123,14 +120,14 @@ impl EntityGateway for PostgresGateway {
} }
async fn save_user(&mut self, user: &UserAccountEntity) -> Result<(), GatewayError> { async fn save_user(&mut self, user: &UserAccountEntity) -> Result<(), GatewayError> {
sqlx::query("UPDATE user_accounts set name=$1, password=$2, banned=$3, muted=$4, flags=$5 where id=$6")
sqlx::query("UPDATE user_accounts set username=$1, password=$2, banned=$3, muted=$4, flags=$5 where id=$6")
.bind(&user.username) .bind(&user.username)
.bind(&user.password) .bind(&user.password)
.bind(&user.banned_until) .bind(&user.banned_until)
.bind(&user.muted_until) .bind(&user.muted_until)
.bind(&user.flags) .bind(&user.flags)
.bind(&user.id.0) .bind(&user.id.0)
.fetch_one(&self.pool).await?;
.execute(&self.pool).await?;
Ok(()) Ok(())
} }

Loading…
Cancel
Save