about summary refs log tree commit diff stats
path: root/crates/rocie-server/src/storage/sql/mod.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-11-28 16:30:02 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-11-28 16:30:02 +0100
commita62ab5c6dacaddb67931d7ac160bc7faaa707737 (patch)
treea35fa3540fbb89f575ab1ea72f9b23ace399e01c /crates/rocie-server/src/storage/sql/mod.rs
parentchore(crates/rocie-client): Re-generate (diff)
downloadserver-a62ab5c6dacaddb67931d7ac160bc7faaa707737.zip
feat(crates/rocie-server): Get closer to feature parity between rocie and grocy
Diffstat (limited to 'crates/rocie-server/src/storage/sql/mod.rs')
-rw-r--r--crates/rocie-server/src/storage/sql/mod.rs35
1 files changed, 29 insertions, 6 deletions
diff --git a/crates/rocie-server/src/storage/sql/mod.rs b/crates/rocie-server/src/storage/sql/mod.rs
index a44fbad..dd46eab 100644
--- a/crates/rocie-server/src/storage/sql/mod.rs
+++ b/crates/rocie-server/src/storage/sql/mod.rs
@@ -5,14 +5,26 @@ pub(crate) mod insert;
 pub(crate) mod barcode;
 pub(crate) mod product;
 pub(crate) mod product_amount;
+pub(crate) mod product_parent;
+pub(crate) mod recipe;
 pub(crate) mod unit;
 pub(crate) mod unit_property;
 
 macro_rules! mk_id {
     ($name:ident and $stub_name:ident) => {
-        mk_id!($name and $stub_name with uuid::Uuid, "uuid::Uuid");
+        mk_id!(
+            $name and $stub_name,
+            with uuid::Uuid, "uuid::Uuid",
+            to_string {|val: &uuid::Uuid| val.to_string()},
+            copy Copy
+        );
     };
-    ($name:ident and $stub_name:ident with $inner:path, $inner_string:literal $($args:meta)*) => {
+    (
+        $name:ident and $stub_name:ident,
+        with $inner:path $(=> $($args:meta)* )?, $inner_string:literal,
+        to_string $to_string:expr,
+        $(copy $copy:path)?
+    ) => {
         #[derive(
             serde::Deserialize,
             serde::Serialize,
@@ -20,17 +32,28 @@ macro_rules! mk_id {
             Default,
             utoipa::ToSchema,
             Clone,
-            Copy,
             PartialEq,
             Eq,
             PartialOrd,
             Ord,
+            $($copy,)?
         )]
         pub(crate) struct $name {
+            $(
+                $(
+                    #[$args]
+                )*
+            )?
             value: $inner,
         }
 
-        #[derive(Deserialize, Serialize, Debug, Clone, Copy)]
+        #[derive(
+            Deserialize,
+            Serialize,
+            Debug,
+            Clone,
+            $($copy,)?
+        )]
         #[serde(from = $inner_string)]
         pub(crate) struct $stub_name {
             value: $inner,
@@ -55,7 +78,7 @@ macro_rules! mk_id {
 
         impl std::fmt::Display for $name {
             fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-                write!(f, "{}", self.value)
+                write!(f, "{}", $to_string(&self.value))
             }
         }
 
@@ -83,7 +106,7 @@ macro_rules! mk_id {
                 &self,
                 buf: &mut <DB as sqlx::Database>::ArgumentBuffer<'q>,
             ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
-                let inner = self.value.to_string();
+                let inner = $to_string(&self.value);
                 sqlx::Encode::<DB>::encode_by_ref(&inner, buf)
             }
         }