@ -125,7 +125,7 @@ ORDER BY amount_seats DESC
|
||||
res
|
||||
}
|
||||
|
||||
pub async fn create(db: &SqlitePool, boat: BoatToAdd<'_>) -> bool {
|
||||
pub async fn create(db: &SqlitePool, boat: BoatToAdd<'_>) -> Result<(), String> {
|
||||
sqlx::query!(
|
||||
"INSERT INTO boat(name, amount_seats, year_built, boatbuilder, default_shipmaster_only_steering, skull, external, location_id, owner) VALUES (?,?,?,?,?,?,?,?,?)",
|
||||
boat.name,
|
||||
@ -139,7 +139,8 @@ ORDER BY amount_seats DESC
|
||||
boat.owner
|
||||
)
|
||||
.execute(db)
|
||||
.await.is_ok()
|
||||
.await.map_err(|e| e.to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn update(&self, db: &SqlitePool, boat: BoatToUpdate<'_>) -> Result<(), String> {
|
||||
@ -221,7 +222,7 @@ mod test {
|
||||
}
|
||||
)
|
||||
.await,
|
||||
true
|
||||
Ok(())
|
||||
);
|
||||
}
|
||||
|
||||
@ -245,7 +246,10 @@ mod test {
|
||||
}
|
||||
)
|
||||
.await,
|
||||
false
|
||||
Err(
|
||||
"error returned from database: (code: 2067) UNIQUE constraint failed: boat.name"
|
||||
.into()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,12 @@ use serde::{Deserialize, Serialize};
|
||||
use sqlx::{FromRow, SqlitePool};
|
||||
|
||||
#[derive(FromRow, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct LogType{
|
||||
pub struct LogType {
|
||||
pub id: i64,
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl LogType{
|
||||
impl LogType {
|
||||
pub async fn find_by_id(db: &SqlitePool, id: i64) -> Option<Self> {
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
@ -45,7 +45,7 @@ mod test {
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_find_true() {
|
||||
let pool = testdb!();
|
||||
let _ = testdb!();
|
||||
}
|
||||
|
||||
//TODO: write tests
|
||||
|
Reference in New Issue
Block a user