add deployment configuration
This commit is contained in:
parent
523d965c09
commit
56a0cc8838
5 changed files with 66 additions and 14 deletions
28
src/db.rs
28
src/db.rs
|
@ -1,11 +1,13 @@
|
|||
use sqlx::{Pool, Postgres};
|
||||
use sqlx::{prelude::FromRow, Pool, Postgres};
|
||||
|
||||
use crate::AppError;
|
||||
|
||||
#[derive(FromRow)]
|
||||
pub struct Account {
|
||||
pub account_id: String,
|
||||
}
|
||||
|
||||
#[derive(FromRow)]
|
||||
pub struct CaughtFish {
|
||||
pub id: Option<i32>,
|
||||
pub account_id: String,
|
||||
|
@ -13,14 +15,16 @@ pub struct CaughtFish {
|
|||
}
|
||||
|
||||
pub async fn insert_account(id: &str, pool: &Pool<Postgres>) -> Result<(), AppError> {
|
||||
sqlx::query!("INSERT INTO accounts (account_id) VALUES ($1)", id)
|
||||
sqlx::query("INSERT INTO accounts (account_id) VALUES ($1)")
|
||||
.bind(id)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_account(id: &str, pool: &Pool<Postgres>) -> Result<bool, AppError> {
|
||||
let results = sqlx::query_as!(Account, "SELECT * FROM accounts WHERE account_id = $1", id)
|
||||
let results: Vec<Account> = sqlx::query_as("SELECT * FROM accounts WHERE account_id = $1")
|
||||
.bind(id)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
|
||||
|
@ -36,13 +40,13 @@ pub async fn insert_caught_fish(
|
|||
fish_id: &i32,
|
||||
pool: &Pool<Postgres>,
|
||||
) -> Result<(), AppError> {
|
||||
sqlx::query!(
|
||||
sqlx::query(
|
||||
"
|
||||
INSERT INTO caught_fish (account_id, fish_id) VALUES ($1, $2)
|
||||
",
|
||||
acc_id,
|
||||
fish_id
|
||||
)
|
||||
.bind(acc_id)
|
||||
.bind(fish_id)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
|
@ -50,13 +54,11 @@ pub async fn insert_caught_fish(
|
|||
}
|
||||
|
||||
pub async fn get_caught_fish(acc_id: &str, pool: &Pool<Postgres>) -> Result<Vec<i32>, AppError> {
|
||||
let results = sqlx::query_as!(
|
||||
CaughtFish,
|
||||
"SELECT * FROM caught_fish WHERE account_id = $1",
|
||||
acc_id
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
let results: Vec<CaughtFish> =
|
||||
sqlx::query_as("SELECT * FROM caught_fish WHERE account_id = $1")
|
||||
.bind(acc_id)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
|
||||
Ok(results.iter().map(|cf| cf.fish_id).collect())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue