rowt/src/model/logtype.rs

53 lines
899 B
Rust
Raw Normal View History

2023-07-23 12:17:57 +02:00
use serde::{Deserialize, Serialize};
use sqlx::{FromRow, SqlitePool};
#[derive(FromRow, Debug, Serialize, Deserialize, Clone)]
pub struct LogType {
2023-07-23 12:17:57 +02:00
pub id: i64,
name: String,
}
impl LogType {
2023-07-23 12:17:57 +02:00
pub async fn find_by_id(db: &SqlitePool, id: i64) -> Option<Self> {
sqlx::query_as!(
Self,
"
SELECT id, name
FROM logbook_type
WHERE id like ?
",
id
)
.fetch_one(db)
.await
.ok()
}
pub async fn all(db: &SqlitePool) -> Vec<Self> {
sqlx::query_as!(
Self,
"
SELECT id, name
FROM logbook_type
"
)
.fetch_all(db)
.await
.unwrap() //TODO: fixme
}
}
#[cfg(test)]
mod test {
use crate::testdb;
use sqlx::SqlitePool;
#[sqlx::test]
fn test_find_true() {
let _ = testdb!();
2023-07-23 12:17:57 +02:00
}
//TODO: write tests
}