diff --git a/common/src/models/article.rs b/common/src/models/article.rs index 4885fd9..4eb9ce6 100644 --- a/common/src/models/article.rs +++ b/common/src/models/article.rs @@ -33,7 +33,7 @@ fn from_postgres_row_small(row: PgRow) -> Article { } async fn from_postgres_row(row: PgRow, pool: PgPool) -> Article { - let variants_option = load_article_variants(row.get(0), pool).await; + let variants_option = load_article_variants(row.get(0), &pool).await; let variants = match variants_option { Some(variants_inner) => { diff --git a/common/src/models/label.rs b/common/src/models/label.rs new file mode 100644 index 0000000..b2b7aad --- /dev/null +++ b/common/src/models/label.rs @@ -0,0 +1,148 @@ +use log::{error, info}; +use serde::{Deserialize, Serialize}; +use sqlx::{Arguments, Decode, Encode, FromRow, PgPool, Row}; +use sqlx::postgres::{PgArguments, PgRow}; + +#[derive(Debug, Deserialize, Serialize, Clone, FromRow, Decode, Encode)] +pub struct Label { + pub id: i64, + pub name: String, +} + +fn from_postgres_row_small(row: PgRow) -> Label { + Label { + id: row.get(0), + name: row.get(1), + } +} + +pub async fn load_labels(pool: PgPool) -> Option> { + let statement = format!( + "SELECT * FROM {}", + "label", + ); + + let res = sqlx::query( + statement.as_str()) + .fetch_all(&pool).await; + + let mut labels: Vec