Added functionality to added article.

This commit is contained in:
matthias committed 2026-01-17 04:18:20 +01:00
1 parent 5f36b535a2
commit 098972d000
10 files changed
+140 -15

No files matched your search

+26 -1
View File
@@ -1,7 +1,10 @@
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use sqlx::{FromRow, PgPool};
use crate::models::origin::Origin;
use crate::models::variant::Variant;
use sqlx::{Arguments, Pool, Row, Postgres, Error};
use sqlx::postgres::{PgArguments, PgQueryResult, PgRow};
use log::{debug, info};
#[derive(Debug, Deserialize, Serialize, Clone, FromRow)]
pub struct Article {
@@ -13,3 +16,25 @@ pub struct Article {
pub ingredients: Option<String>,
pub variants: Vec<Variant>,
}
pub async fn insert_article(article: &Article, pool: PgPool) {
let mut args = PgArguments::default();
args.add(&article.name);
args.add(&article.bio);
args.add(&article.origin);
args.add(&article.description);
args.add(&article.ingredients);
// Add to price history:
let statement = format!(
"INSERT INTO {} (name, bio, origin, description, ingredients) VALUES ($1, $2, $3, $4, $5)",
"article",
);
let res = sqlx::query_with(
statement.as_str(),
args)
.execute(&pool).await.unwrap();
info!("{:#?}", res);
}