finish backend tests of new db layout

This commit is contained in:
2023-10-29 20:41:30 +01:00
parent 09075989e3
commit 1d7f95e522
5 changed files with 216 additions and 106 deletions

View File

@ -1,6 +1,6 @@
use rocket::serde::{Deserialize, Serialize};
use rocket::FromForm;
use sqlx::{FromRow, SqlitePool};
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
use super::user::User;
@ -70,6 +70,12 @@ impl Boat {
.await
.ok()
}
pub async fn find_by_id_tx(db: &mut Transaction<'_, Sqlite>, id: i32) -> Option<Self> {
sqlx::query_as!(Self, "SELECT * FROM boat WHERE id like ?", id)
.fetch_one(db)
.await
.ok()
}
pub async fn find_by_name(db: &SqlitePool, name: String) -> Option<Self> {
sqlx::query_as!(Self, "SELECT * FROM boat WHERE name like ?", name)