From 8481184caceec03aef882b749203486592a59723 Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Wed, 1 Jan 2025 22:30:44 +0100 Subject: [PATCH 1/6] Update lib.rs --- agdb_derive/src/lib.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/agdb_derive/src/lib.rs b/agdb_derive/src/lib.rs index 120b0b29..ead4e416 100644 --- a/agdb_derive/src/lib.rs +++ b/agdb_derive/src/lib.rs @@ -93,9 +93,9 @@ fn serialize_enum(name: Ident, enum_data: DataEnum) -> proc_macro2::TokenStream .collect::>(); if named { - quote! { #name::#variant_name { #(#names),* } => { #(size += #names.serialized_size();)* } } + quote! { #name::#variant_name { #(#names),* } => { #(size += agdb::AgdbSerialize::serialized_size(#names);)* } } } else { - quote! { #name::#variant_name(#(#names),*) => { #(size += #names.serialized_size();)* } } + quote! { #name::#variant_name(#(#names),*) => { #(size += agdb::AgdbSerialize::serialized_size(#names);)* } } } } }); @@ -122,9 +122,9 @@ fn serialize_enum(name: Ident, enum_data: DataEnum) -> proc_macro2::TokenStream .collect::>(); if named { - quote! { #name::#variant_name { #(#names),* } => { __buffer.push(#variant_index); #(__buffer.extend(#names.serialize());)* } } + quote! { #name::#variant_name { #(#names),* } => { __buffer.push(#variant_index); #(__buffer.extend(agdb::AgdbSerialize::serialize(#names));)* } } } else { - quote! { #name::#variant_name(#(#names),*) => { __buffer.push(#variant_index); #(__buffer.extend(#names.serialize());)* } } + quote! { #name::#variant_name(#(#names),*) => { __buffer.push(#variant_index); #(__buffer.extend(agdb::AgdbSerialize::serialize(#names));)* } } } } }); @@ -142,10 +142,10 @@ fn serialize_enum(name: Ident, enum_data: DataEnum) -> proc_macro2::TokenStream .map(|field| { let ty = &field.ty; if let Some(ident) = &field.ident { - quote! { #ident: { let #ident = <#ty as agdb::AgdbSerialize>::deserialize(&buffer[__offset as usize..])?; __offset += #ident.serialized_size(); #ident } } + quote! { #ident: { let #ident = <#ty as agdb::AgdbSerialize>::deserialize(&buffer[__offset as usize..])?; __offset += agdb::AgdbSerialize::serialized_size(&#ident); #ident } } } else { named = false; - quote! { { let v = <#ty as agdb::AgdbSerialize>::deserialize(&buffer[__offset as usize..])?; __offset += v.serialized_size(); v } } + quote! { { let v = <#ty as agdb::AgdbSerialize>::deserialize(&buffer[__offset as usize..])?; __offset += agdb::AgdbSerialize::serialized_size(&v); v } } } }) .collect::>(); @@ -171,7 +171,7 @@ fn serialize_enum(name: Ident, enum_data: DataEnum) -> proc_macro2::TokenStream } fn serialize(&self) -> Vec { - let mut __buffer = Vec::with_capacity(self.serialized_size() as usize); + let mut __buffer = Vec::with_capacity(agdb::AgdbSerialize::serialized_size(self) as usize); match self { #( #serializers @@ -207,7 +207,7 @@ fn serialize_tuple( .map(|(index, (_name, _ty))| { let num = Index::from(index); quote! { - size += self.#num.serialized_size(); + size += agdb::AgdbSerialize::serialized_size(&self.#num); } }); let serializers = fields_types @@ -216,14 +216,14 @@ fn serialize_tuple( .map(|(index, (_name, _ty))| { let num = Index::from(index); quote! { - __buffer.extend(self.#num.serialize()); + __buffer.extend(agdb::AgdbSerialize::serialize(&self.#num)); } }); let deserializers = fields_types.iter().enumerate().map(|(index, (_name, ty))| { let name = format_ident!("__{}", index); quote! { let #name = <#ty as agdb::AgdbSerialize>::deserialize(&buffer[__offset as usize..])?; - __offset += #name.serialized_size(); + __offset += agdb::AgdbSerialize::serialized_size(&#name); } }); @@ -238,7 +238,7 @@ fn serialize_tuple( } fn serialize(&self) -> Vec { - let mut __buffer = Vec::with_capacity(self.serialized_size() as usize); + let mut __buffer = Vec::with_capacity(agdb::AgdbSerialize::serialized_size(self) as usize); #( #serializers )* @@ -268,20 +268,20 @@ fn serialize_struct( let sizes = fields_types.iter().map(|(name, _ty)| { let name = name.unwrap(); quote! { - size += self.#name.serialized_size(); + size += agdb::AgdbSerialize::serialized_size(&self.#name); } }); let serializers = fields_types.iter().map(|(name, _ty)| { let name = name.unwrap(); quote! { - __buffer.extend(self.#name.serialize()); + __buffer.extend(agdb::AgdbSerialize::serialize(&self.#name)); } }); let deserializers = fields_types.iter().map(|(name, ty)| { let name = name.unwrap(); quote! { let #name = <#ty as agdb::AgdbSerialize>::deserialize(&buffer[__offset as usize..])?; - __offset += #name.serialized_size(); + __offset += agdb::AgdbSerialize::serialized_size(&#name); } }); @@ -296,7 +296,7 @@ fn serialize_struct( } fn serialize(&self) -> Vec { - let mut __buffer = Vec::with_capacity(self.serialized_size() as usize); + let mut __buffer = Vec::with_capacity(agdb::AgdbSerialize::serialized_size(self) as usize); #( #serializers )* @@ -552,8 +552,8 @@ fn impl_db_id(data: &syn::DataStruct) -> proc_macro2::TokenStream { if let Some(name) = &f.ident { if name == DB_ID { return Some(quote! { - if let Some(id) = self.db_id.clone() { - return Some(id.into()); + if let Some(id) = &self.db_id { + return Some(id.clone().into()); } else { return None; } From 38664a158dae33c663104dd789232e23fe9c83eb Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Wed, 1 Jan 2025 22:48:22 +0100 Subject: [PATCH 2/6] Update lib.rs --- agdb_derive/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agdb_derive/src/lib.rs b/agdb_derive/src/lib.rs index ead4e416..1f4bef4d 100644 --- a/agdb_derive/src/lib.rs +++ b/agdb_derive/src/lib.rs @@ -56,10 +56,10 @@ pub fn agdb_de_serialize(item: TokenStream) -> TokenStream { .map(|f| (f.ident.as_ref(), &f.ty)) .collect::, &Type)>>(); - if fields_types.is_empty() || fields_types[0].0.is_none() { - serialize_tuple(name, fields_types) - } else { + if fields_types.is_empty() || fields_types[0].0.is_some() { serialize_struct(name, fields_types) + } else { + serialize_tuple(name, fields_types) } } else if let syn::Data::Enum(data) = input.data { serialize_enum(name, data) From f99ebd04dcff9a1542f378b2f1bb9fa3d6c12719 Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Wed, 1 Jan 2025 23:01:32 +0100 Subject: [PATCH 3/6] use bianry serialization for ClusterAction --- agdb/src/db/db_id.rs | 1 + agdb/src/db/db_key_order.rs | 1 + agdb/src/db/db_key_value.rs | 1 + agdb/src/db/db_value.rs | 1 + agdb/src/query.rs | 1 + agdb/src/query/insert_aliases_query.rs | 1 + agdb/src/query/insert_edges_query.rs | 1 + agdb/src/query/insert_index_query.rs | 1 + agdb/src/query/insert_nodes_query.rs | 1 + agdb/src/query/insert_values_query.rs | 1 + agdb/src/query/query_condition.rs | 6 + agdb/src/query/query_id.rs | 1 + agdb/src/query/query_ids.rs | 1 + agdb/src/query/query_values.rs | 1 + agdb/src/query/remove_aliases_query.rs | 1 + agdb/src/query/remove_index_query.rs | 1 + agdb/src/query/remove_query.rs | 1 + agdb/src/query/remove_values_query.rs | 1 + agdb/src/query/search_query.rs | 2 + agdb/src/query/select_aliases_query.rs | 1 + agdb/src/query/select_all_aliases_query.rs | 1 + agdb/src/query/select_edge_count_query.rs | 1 + agdb/src/query/select_indexes_query.rs | 1 + agdb/src/query/select_key_count_query.rs | 1 + agdb/src/query/select_keys_query.rs | 1 + agdb/src/query/select_node_count.rs | 1 + agdb/src/query/select_values_query.rs | 1 + agdb/src/utilities/serialize.rs | 17 ++ agdb_api/rust/src/api_types.rs | 42 ++- agdb_server/src/action.rs | 22 +- agdb_server/src/action/change_password.rs | 3 +- agdb_server/src/action/cluster_login.rs | 3 +- agdb_server/src/action/db_add.rs | 3 +- agdb_server/src/action/db_backup.rs | 3 +- agdb_server/src/action/db_clear.rs | 3 +- agdb_server/src/action/db_convert.rs | 3 +- agdb_server/src/action/db_copy.rs | 3 +- agdb_server/src/action/db_delete.rs | 3 +- agdb_server/src/action/db_exec.rs | 3 +- agdb_server/src/action/db_optimize.rs | 3 +- agdb_server/src/action/db_remove.rs | 3 +- agdb_server/src/action/db_rename.rs | 3 +- agdb_server/src/action/db_restore.rs | 3 +- agdb_server/src/action/db_user_add.rs | 3 +- agdb_server/src/action/db_user_remove.rs | 3 +- agdb_server/src/action/user_add.rs | 3 +- agdb_server/src/action/user_remove.rs | 3 +- agdb_server/src/server_db.rs | 314 +++------------------ 48 files changed, 182 insertions(+), 297 deletions(-) diff --git a/agdb/src/db/db_id.rs b/agdb/src/db/db_id.rs index 67cc4a95..177c7ed8 100644 --- a/agdb/src/db/db_id.rs +++ b/agdb/src/db/db_id.rs @@ -14,6 +14,7 @@ use crate::StorageData; #[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq, Ord, PartialOrd)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub struct DbId(pub i64); impl StableHash for DbId { diff --git a/agdb/src/db/db_key_order.rs b/agdb/src/db/db_key_order.rs index d5607e41..18a14285 100644 --- a/agdb/src/db/db_key_order.rs +++ b/agdb/src/db/db_key_order.rs @@ -4,6 +4,7 @@ use crate::DbValue; #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub enum DbKeyOrder { /// Ascending order (from smallest) Asc(DbValue), diff --git a/agdb/src/db/db_key_value.rs b/agdb/src/db/db_key_value.rs index 1fa599d0..ec640583 100644 --- a/agdb/src/db/db_key_value.rs +++ b/agdb/src/db/db_key_value.rs @@ -14,6 +14,7 @@ use crate::StorageData; #[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub struct DbKeyValue { /// Key of the property pub key: DbValue, diff --git a/agdb/src/db/db_value.rs b/agdb/src/db/db_value.rs index f9ea6beb..83b71da1 100644 --- a/agdb/src/db/db_value.rs +++ b/agdb/src/db/db_value.rs @@ -23,6 +23,7 @@ use std::fmt::Result as DisplayResult; #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub enum DbValue { /// Byte array, sometimes referred to as blob Bytes(Vec), diff --git a/agdb/src/query.rs b/agdb/src/query.rs index b5897955..d9f073b5 100644 --- a/agdb/src/query.rs +++ b/agdb/src/query.rs @@ -56,6 +56,7 @@ use crate::{ #[cfg(any(feature = "serde", feature = "openapi"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] #[expect(clippy::large_enum_variant)] pub enum QueryType { diff --git a/agdb/src/query/insert_aliases_query.rs b/agdb/src/query/insert_aliases_query.rs index 1aa65130..03660fe8 100644 --- a/agdb/src/query/insert_aliases_query.rs +++ b/agdb/src/query/insert_aliases_query.rs @@ -15,6 +15,7 @@ use crate::StorageData; /// The result will contain number of aliases inserted/updated but no elements. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct InsertAliasesQuery { /// Ids to be aliased diff --git a/agdb/src/query/insert_edges_query.rs b/agdb/src/query/insert_edges_query.rs index 3a4d81c1..54ef85c5 100644 --- a/agdb/src/query/insert_edges_query.rs +++ b/agdb/src/query/insert_edges_query.rs @@ -28,6 +28,7 @@ use crate::StorageData; /// with their ids, origin and destination, but no properties. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct InsertEdgesQuery { /// Origins diff --git a/agdb/src/query/insert_index_query.rs b/agdb/src/query/insert_index_query.rs index 7c9889a8..a35be77f 100644 --- a/agdb/src/query/insert_index_query.rs +++ b/agdb/src/query/insert_index_query.rs @@ -9,6 +9,7 @@ use crate::StorageData; /// a given key. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct InsertIndexQuery(pub DbValue); diff --git a/agdb/src/query/insert_nodes_query.rs b/agdb/src/query/insert_nodes_query.rs index 110d8f9b..7369f451 100644 --- a/agdb/src/query/insert_nodes_query.rs +++ b/agdb/src/query/insert_nodes_query.rs @@ -27,6 +27,7 @@ use crate::StorageData; /// with their ids but no properties. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct InsertNodesQuery { /// Number of nodes to be inserted. diff --git a/agdb/src/query/insert_values_query.rs b/agdb/src/query/insert_values_query.rs index 3880c441..3b1da4e0 100644 --- a/agdb/src/query/insert_values_query.rs +++ b/agdb/src/query/insert_values_query.rs @@ -24,6 +24,7 @@ use crate::StorageData; /// NOTE: The result is NOT number of affected elements but individual properties. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct InsertValuesQuery { /// Ids whose properties should be updated diff --git a/agdb/src/query/query_condition.rs b/agdb/src/query/query_condition.rs index a8b3b5b6..a0a238ed 100644 --- a/agdb/src/query/query_condition.rs +++ b/agdb/src/query/query_condition.rs @@ -6,6 +6,7 @@ use crate::QueryId; #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub enum QueryConditionLogic { /// Logical AND (&&) And, @@ -18,6 +19,7 @@ pub enum QueryConditionLogic { #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub enum QueryConditionModifier { /// No modifier None, @@ -38,6 +40,7 @@ pub enum QueryConditionModifier { #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub enum QueryConditionData { /// Distance from the search origin. Takes count comparison /// (e.g. Equal, GreaterThan). @@ -90,6 +93,7 @@ pub enum QueryConditionData { #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub struct QueryCondition { /// Logic operator (e.g. And, Or) pub logic: QueryConditionLogic, @@ -108,6 +112,7 @@ pub struct QueryCondition { #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub enum CountComparison { /// property == this Equal(u64), @@ -139,6 +144,7 @@ pub enum CountComparison { #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub enum Comparison { /// property == this Equal(DbValue), diff --git a/agdb/src/query/query_id.rs b/agdb/src/query/query_id.rs index 8e61a523..f81321d5 100644 --- a/agdb/src/query/query_id.rs +++ b/agdb/src/query/query_id.rs @@ -6,6 +6,7 @@ use crate::DbId; #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub enum QueryId { /// Numerical id as [`DbId`] Id(DbId), diff --git a/agdb/src/query/query_ids.rs b/agdb/src/query/query_ids.rs index 7dd6b163..88ae2604 100644 --- a/agdb/src/query/query_ids.rs +++ b/agdb/src/query/query_ids.rs @@ -11,6 +11,7 @@ use crate::SearchQuery; #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub enum QueryIds { /// List of [`QueryId`]s Ids(Vec), diff --git a/agdb/src/query/query_values.rs b/agdb/src/query/query_values.rs index df804ec2..1f05d2fc 100644 --- a/agdb/src/query/query_values.rs +++ b/agdb/src/query/query_values.rs @@ -5,6 +5,7 @@ use crate::DbUserValue; /// and multiple (`Multi`) values in database queries. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub enum QueryValues { /// Single list of properties (key-value pairs) diff --git a/agdb/src/query/remove_aliases_query.rs b/agdb/src/query/remove_aliases_query.rs index e2424bb9..763eb917 100644 --- a/agdb/src/query/remove_aliases_query.rs +++ b/agdb/src/query/remove_aliases_query.rs @@ -12,6 +12,7 @@ use crate::StorageData; /// many aliases have been actually removed. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct RemoveAliasesQuery(pub Vec); diff --git a/agdb/src/query/remove_index_query.rs b/agdb/src/query/remove_index_query.rs index 18a92271..d9833e50 100644 --- a/agdb/src/query/remove_index_query.rs +++ b/agdb/src/query/remove_index_query.rs @@ -9,6 +9,7 @@ use crate::StorageData; /// a given key. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct RemoveIndexQuery(pub DbValue); diff --git a/agdb/src/query/remove_query.rs b/agdb/src/query/remove_query.rs index c9791fe9..66bb5b0d 100644 --- a/agdb/src/query/remove_query.rs +++ b/agdb/src/query/remove_query.rs @@ -16,6 +16,7 @@ use crate::StorageData; /// also removed along with their properties. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct RemoveQuery(pub QueryIds); diff --git a/agdb/src/query/remove_values_query.rs b/agdb/src/query/remove_values_query.rs index ee43236e..b93f9616 100644 --- a/agdb/src/query/remove_values_query.rs +++ b/agdb/src/query/remove_values_query.rs @@ -15,6 +15,7 @@ use crate::StorageData; /// do not exist on any of the elements). #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct RemoveValuesQuery(pub SelectValuesQuery); diff --git a/agdb/src/query/search_query.rs b/agdb/src/query/search_query.rs index ebbb6f36..9aa73615 100644 --- a/agdb/src/query/search_query.rs +++ b/agdb/src/query/search_query.rs @@ -16,6 +16,7 @@ use std::cmp::Ordering; /// Search algorithm to be used #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Debug, Clone, Copy, PartialEq)] pub enum SearchQueryAlgorithm { /// Examines each distance level from the search origin in full @@ -42,6 +43,7 @@ pub enum SearchQueryAlgorithm { #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] pub struct SearchQuery { /// Search algorithm to be used. Will be bypassed for path /// searches that unconditionally use A*. diff --git a/agdb/src/query/select_aliases_query.rs b/agdb/src/query/select_aliases_query.rs index a6f83b78..ab2e81ce 100644 --- a/agdb/src/query/select_aliases_query.rs +++ b/agdb/src/query/select_aliases_query.rs @@ -17,6 +17,7 @@ use crate::StorageData; /// the value `String`. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct SelectAliasesQuery(pub QueryIds); diff --git a/agdb/src/query/select_all_aliases_query.rs b/agdb/src/query/select_all_aliases_query.rs index cd0694d8..55b8c6d6 100644 --- a/agdb/src/query/select_all_aliases_query.rs +++ b/agdb/src/query/select_all_aliases_query.rs @@ -12,6 +12,7 @@ use crate::StorageData; /// the value `String`. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct SelectAllAliasesQuery {} diff --git a/agdb/src/query/select_edge_count_query.rs b/agdb/src/query/select_edge_count_query.rs index 429216e8..ee90469c 100644 --- a/agdb/src/query/select_edge_count_query.rs +++ b/agdb/src/query/select_edge_count_query.rs @@ -22,6 +22,7 @@ use crate::StorageData; /// might be greater than number of unique db elements. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct SelectEdgeCountQuery { /// Ids of the nodes to select edge count for. diff --git a/agdb/src/query/select_indexes_query.rs b/agdb/src/query/select_indexes_query.rs index 9f2eb5fc..3710bf2d 100644 --- a/agdb/src/query/select_indexes_query.rs +++ b/agdb/src/query/select_indexes_query.rs @@ -14,6 +14,7 @@ use crate::StorageData; /// index. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct SelectIndexesQuery {} diff --git a/agdb/src/query/select_key_count_query.rs b/agdb/src/query/select_key_count_query.rs index 1b587f69..61eb0381 100644 --- a/agdb/src/query/select_key_count_query.rs +++ b/agdb/src/query/select_key_count_query.rs @@ -16,6 +16,7 @@ use crate::StorageData; /// a value `u64`. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct SelectKeyCountQuery(pub QueryIds); diff --git a/agdb/src/query/select_keys_query.rs b/agdb/src/query/select_keys_query.rs index 1c349756..d56bdfe7 100644 --- a/agdb/src/query/select_keys_query.rs +++ b/agdb/src/query/select_keys_query.rs @@ -15,6 +15,7 @@ use crate::StorageData; /// of elements with all properties except all values will be empty. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct SelectKeysQuery(pub QueryIds); diff --git a/agdb/src/query/select_node_count.rs b/agdb/src/query/select_node_count.rs index e753b726..258c74e4 100644 --- a/agdb/src/query/select_node_count.rs +++ b/agdb/src/query/select_node_count.rs @@ -13,6 +13,7 @@ use crate::StorageData; /// a value `u64` represneting number of nodes in teh database. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct SelectNodeCountQuery {} diff --git a/agdb/src/query/select_values_query.rs b/agdb/src/query/select_values_query.rs index 22eb80ad..77e1d71e 100644 --- a/agdb/src/query/select_values_query.rs +++ b/agdb/src/query/select_values_query.rs @@ -17,6 +17,7 @@ use crate::StorageData; /// list of elements with the requested properties. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "derive", derive(agdb::AgdbDeSerialize))] #[derive(Clone, Debug, PartialEq)] pub struct SelectValuesQuery { pub keys: Vec, diff --git a/agdb/src/utilities/serialize.rs b/agdb/src/utilities/serialize.rs index 78632e78..4efa04ad 100644 --- a/agdb/src/utilities/serialize.rs +++ b/agdb/src/utilities/serialize.rs @@ -116,6 +116,23 @@ impl Serialize for String { } } +impl Serialize for bool { + fn serialize(&self) -> Vec { + vec![*self as u8] + } + + fn deserialize(bytes: &[u8]) -> Result { + bytes + .first() + .ok_or(DbError::from("bool deserialization error: out of bounds")) + .map(|&b| b != 0) + } + + fn serialized_size(&self) -> u64 { + 1 + } +} + impl Serialize for Vec { fn serialize(&self) -> Vec { let mut bytes = Vec::with_capacity(self.serialized_size() as usize); diff --git a/agdb_api/rust/src/api_types.rs b/agdb_api/rust/src/api_types.rs index 7abd7932..038812a9 100644 --- a/agdb_api/rust/src/api_types.rs +++ b/agdb_api/rust/src/api_types.rs @@ -1,3 +1,4 @@ +use agdb::AgdbDeSerialize; use agdb::DbError; use agdb::DbValue; use agdb::QueryResult; @@ -8,7 +9,18 @@ use std::fmt::Display; use utoipa::ToSchema; #[derive( - Copy, Clone, Debug, Default, Serialize, Deserialize, ToSchema, PartialEq, Eq, PartialOrd, Ord, + Copy, + Clone, + Debug, + Default, + Serialize, + Deserialize, + ToSchema, + PartialEq, + Eq, + PartialOrd, + Ord, + AgdbDeSerialize, )] #[serde(rename_all = "snake_case")] pub enum DbType { @@ -19,7 +31,18 @@ pub enum DbType { } #[derive( - Copy, Clone, Debug, Default, Serialize, Deserialize, ToSchema, PartialEq, Eq, PartialOrd, Ord, + Copy, + Clone, + Debug, + Default, + Serialize, + Deserialize, + ToSchema, + PartialEq, + Eq, + PartialOrd, + Ord, + AgdbDeSerialize, )] #[serde(rename_all = "snake_case")] pub enum DbResource { @@ -37,7 +60,18 @@ pub struct DbUser { } #[derive( - Clone, Copy, Debug, Default, Serialize, Deserialize, ToSchema, PartialEq, Eq, PartialOrd, Ord, + Clone, + Copy, + Debug, + Default, + Serialize, + Deserialize, + ToSchema, + PartialEq, + Eq, + PartialOrd, + Ord, + AgdbDeSerialize, )] #[serde(rename_all = "snake_case")] pub enum DbUserRole { @@ -69,7 +103,7 @@ pub struct AdminStatus { pub size: u64, } -#[derive(Clone, Deserialize, Serialize, ToSchema)] +#[derive(Clone, Deserialize, Serialize, ToSchema, AgdbDeSerialize)] pub struct Queries(pub Vec); #[derive(Serialize, ToSchema)] diff --git a/agdb_server/src/action.rs b/agdb_server/src/action.rs index fc3e6be1..944ce66d 100644 --- a/agdb_server/src/action.rs +++ b/agdb_server/src/action.rs @@ -36,11 +36,12 @@ use crate::action::user_remove::UserRemove; use crate::db_pool::DbPool; use crate::server_db::ServerDb; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::QueryResult; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize)] +#[derive(Clone, AgdbDeSerialize)] pub(crate) enum ClusterAction { UserAdd(UserAdd), ClusterLogin(ClusterLogin), @@ -199,3 +200,22 @@ impl From for ClusterAction { ClusterAction::DbUserRemove(value) } } + +impl Serialize for ClusterAction { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + serializer.serialize_bytes(&agdb::AgdbSerialize::serialize(self)) + } +} + +impl<'de> Deserialize<'de> for ClusterAction { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let bytes = Vec::::deserialize(deserializer)?; + agdb::AgdbSerialize::deserialize(&bytes).map_err(serde::de::Error::custom) + } +} diff --git a/agdb_server/src/action/change_password.rs b/agdb_server/src/action/change_password.rs index fb895054..072783f7 100644 --- a/agdb_server/src/action/change_password.rs +++ b/agdb_server/src/action/change_password.rs @@ -3,11 +3,12 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct ChangePassword { pub(crate) user: String, pub(crate) new_password: Vec, diff --git a/agdb_server/src/action/cluster_login.rs b/agdb_server/src/action/cluster_login.rs index 4ba0c151..f3bb7e42 100644 --- a/agdb_server/src/action/cluster_login.rs +++ b/agdb_server/src/action/cluster_login.rs @@ -3,11 +3,12 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct ClusterLogin { pub(crate) user: String, pub(crate) new_token: String, diff --git a/agdb_server/src/action/db_add.rs b/agdb_server/src/action/db_add.rs index 7b589000..63a5a007 100644 --- a/agdb_server/src/action/db_add.rs +++ b/agdb_server/src/action/db_add.rs @@ -4,12 +4,13 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_db::Database; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use agdb_api::DbType; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbAdd { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_backup.rs b/agdb_server/src/action/db_backup.rs index 5b8d369a..1b302ddb 100644 --- a/agdb_server/src/action/db_backup.rs +++ b/agdb_server/src/action/db_backup.rs @@ -3,11 +3,12 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbBackup { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_clear.rs b/agdb_server/src/action/db_clear.rs index b6b9fd43..586a13ab 100644 --- a/agdb_server/src/action/db_clear.rs +++ b/agdb_server/src/action/db_clear.rs @@ -3,12 +3,13 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use agdb_api::DbResource; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbClear { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_convert.rs b/agdb_server/src/action/db_convert.rs index 15721d12..5d43991a 100644 --- a/agdb_server/src/action/db_convert.rs +++ b/agdb_server/src/action/db_convert.rs @@ -3,12 +3,13 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use agdb_api::DbType; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbConvert { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_copy.rs b/agdb_server/src/action/db_copy.rs index c1b0fcdd..c1a98516 100644 --- a/agdb_server/src/action/db_copy.rs +++ b/agdb_server/src/action/db_copy.rs @@ -4,12 +4,13 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_db::Database; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use agdb_api::DbType; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbCopy { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_delete.rs b/agdb_server/src/action/db_delete.rs index 312eb2d9..c34cfdef 100644 --- a/agdb_server/src/action/db_delete.rs +++ b/agdb_server/src/action/db_delete.rs @@ -3,11 +3,12 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbDelete { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_exec.rs b/agdb_server/src/action/db_exec.rs index b04a72a1..1206b935 100644 --- a/agdb_server/src/action/db_exec.rs +++ b/agdb_server/src/action/db_exec.rs @@ -3,13 +3,14 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::DbUserValue; use agdb::QueryResult; use agdb_api::Queries; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbExec { pub(crate) user: String, pub(crate) owner: String, diff --git a/agdb_server/src/action/db_optimize.rs b/agdb_server/src/action/db_optimize.rs index 8f6dfff5..4b246c4c 100644 --- a/agdb_server/src/action/db_optimize.rs +++ b/agdb_server/src/action/db_optimize.rs @@ -3,11 +3,12 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbOptimize { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_remove.rs b/agdb_server/src/action/db_remove.rs index cbe98de7..c3ea0154 100644 --- a/agdb_server/src/action/db_remove.rs +++ b/agdb_server/src/action/db_remove.rs @@ -3,11 +3,12 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbRemove { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_rename.rs b/agdb_server/src/action/db_rename.rs index 05fceceb..863fe24d 100644 --- a/agdb_server/src/action/db_rename.rs +++ b/agdb_server/src/action/db_rename.rs @@ -3,12 +3,13 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use agdb_api::DbUserRole; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbRename { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_restore.rs b/agdb_server/src/action/db_restore.rs index 476e36f7..55705e36 100644 --- a/agdb_server/src/action/db_restore.rs +++ b/agdb_server/src/action/db_restore.rs @@ -3,11 +3,12 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbRestore { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_user_add.rs b/agdb_server/src/action/db_user_add.rs index 43bfb8cc..4aec1aa6 100644 --- a/agdb_server/src/action/db_user_add.rs +++ b/agdb_server/src/action/db_user_add.rs @@ -3,12 +3,13 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use agdb_api::DbUserRole; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbUserAdd { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_user_remove.rs b/agdb_server/src/action/db_user_remove.rs index 45411f52..633cfdab 100644 --- a/agdb_server/src/action/db_user_remove.rs +++ b/agdb_server/src/action/db_user_remove.rs @@ -3,11 +3,12 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct DbUserRemove { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/user_add.rs b/agdb_server/src/action/user_add.rs index a47603b2..05fcf670 100644 --- a/agdb_server/src/action/user_add.rs +++ b/agdb_server/src/action/user_add.rs @@ -4,11 +4,12 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_db::ServerUser; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct UserAdd { pub(crate) user: String, pub(crate) password: Vec, diff --git a/agdb_server/src/action/user_remove.rs b/agdb_server/src/action/user_remove.rs index 96543bc7..f362d221 100644 --- a/agdb_server/src/action/user_remove.rs +++ b/agdb_server/src/action/user_remove.rs @@ -3,11 +3,12 @@ use super::ServerDb; use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; +use agdb::AgdbDeSerialize; use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue)] +#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] pub(crate) struct UserRemove { pub(crate) user: String, } diff --git a/agdb_server/src/server_db.rs b/agdb_server/src/server_db.rs index c7d6fa14..e2f08dc3 100644 --- a/agdb_server/src/server_db.rs +++ b/agdb_server/src/server_db.rs @@ -1,20 +1,3 @@ -use crate::action::change_password::ChangePassword; -use crate::action::cluster_login::ClusterLogin; -use crate::action::db_add::DbAdd; -use crate::action::db_backup::DbBackup; -use crate::action::db_clear::DbClear; -use crate::action::db_convert::DbConvert; -use crate::action::db_copy::DbCopy; -use crate::action::db_delete::DbDelete; -use crate::action::db_exec::DbExec; -use crate::action::db_optimize::DbOptimize; -use crate::action::db_remove::DbRemove; -use crate::action::db_rename::DbRename; -use crate::action::db_restore::DbRestore; -use crate::action::db_user_add::DbUserAdd; -use crate::action::db_user_remove::DbUserRemove; -use crate::action::user_add::UserAdd; -use crate::action::user_remove::UserRemove; use crate::action::ClusterAction; use crate::config::Config; use crate::db_pool::DbName; @@ -22,11 +5,11 @@ use crate::password::Password; use crate::raft::Log; use crate::server_error::ServerError; use crate::server_error::ServerResult; +use agdb::AgdbSerialize; use agdb::Comparison; use agdb::CountComparison; use agdb::Db; use agdb::DbId; -use agdb::DbKeyValue; use agdb::DbUserValue; use agdb::QueryBuilder; use agdb::QueryId; @@ -457,14 +440,16 @@ impl ServerDb { pub(crate) async fn append_log(&self, log: &Log) -> ServerResult { self.0.write().await.transaction_mut( |t: &mut agdb::TransactionMut<'_, agdb::FileStorageMemoryMapped>| { - let mut values = log_db_values(log); - values.push((COMMITTED, false).into()); - values.push((EXECUTED, false).into()); - let log_id = t - .exec_mut(QueryBuilder::insert().nodes().values([values]).query())? + .exec_mut(QueryBuilder::insert().element(log).query())? .elements[0] .id; + t.exec_mut( + QueryBuilder::insert() + .values([[(COMMITTED, false).into(), (EXECUTED, false).into()]]) + .ids(log_id) + .query(), + )?; t.exec_mut( QueryBuilder::insert() .edges() @@ -927,271 +912,50 @@ fn user_not_found(name: &str) -> ServerError { ServerError::new(StatusCode::NOT_FOUND, &format!("user not found: {name}")) } -fn log_db_values(log: &Log) -> Vec { - let mut values = vec![("index", log.index).into(), ("term", log.term).into()]; - - match &log.data { - ClusterAction::UserAdd(action) => { - values.push(("action", "UserAdd").into()); - values.extend(action.to_db_values()); - } - ClusterAction::ClusterLogin(action) => { - values.push(("action", "ClusterLogin").into()); - values.extend(action.to_db_values()); - } - ClusterAction::ChangePassword(action) => { - values.push(("action", "ChangePassword").into()); - values.extend(action.to_db_values()); - } - ClusterAction::UserRemove(action) => { - values.push(("action", "UserRemove").into()); - values.extend(action.to_db_values()); - } - ClusterAction::DbAdd(action) => { - values.push(("action", "DbAdd").into()); - values.extend(action.to_db_values()); - } - ClusterAction::DbBackup(db_backup) => { - values.push(("action", "DbBackup").into()); - values.extend(db_backup.to_db_values()); - } - ClusterAction::DbClear(db_clear) => { - values.push(("action", "DbClear").into()); - values.extend(db_clear.to_db_values()); - } - ClusterAction::DbConvert(db_convert) => { - values.push(("action", "DbConvert").into()); - values.extend(db_convert.to_db_values()); - } - ClusterAction::DbCopy(db_copy) => { - values.push(("action", "DbCopy").into()); - values.extend(db_copy.to_db_values()); - } - ClusterAction::DbDelete(db_delete) => { - values.push(("action", "DbDelete").into()); - values.extend(db_delete.to_db_values()); - } - ClusterAction::DbRemove(db_remove) => { - values.push(("action", "DbRemove").into()); - values.extend(db_remove.to_db_values()); - } - ClusterAction::DbExec(db_exec) => { - values.push(("action", "DbExec").into()); - values.extend(db_exec.to_db_values()); - } - ClusterAction::DbOptimize(db_optimize) => { - values.push(("action", "DbOptimize").into()); - values.extend(db_optimize.to_db_values()); - } - ClusterAction::DbRestore(db_restore) => { - values.push(("action", "DbRestore").into()); - values.extend(db_restore.to_db_values()); - } - ClusterAction::DbRename(db_rename) => { - values.push(("action", "DbRename").into()); - values.extend(db_rename.to_db_values()); - } - ClusterAction::DbUserAdd(db_user_add) => { - values.push(("action", "DbUserAdd").into()); - values.extend(db_user_add.to_db_values()); - } - ClusterAction::DbUserRemove(db_user_remove) => { - values.push(("action", "DbUserRemove").into()); - values.extend(db_user_remove.to_db_values()); - } - } - - values -} - fn logs( t: &Transaction, log_ids: Vec, ) -> ServerResult>> { - let mut actions = Vec::new(); + Ok(t.exec( + QueryBuilder::select() + .elements::>() + .ids(log_ids) + .query(), + )? + .try_into()?) +} - for element in t - .exec( - QueryBuilder::select() - .values(["index", "term", "action"]) - .ids(log_ids) - .query(), - )? - .elements - { +impl DbUserValue for Log { + type ValueType = Log; + + fn db_id(&self) -> Option { + self.db_id.map(|id| id.into()) + } + + fn db_keys() -> Vec { + vec!["index".into(), "term".into(), "data".into()] + } + + fn from_db_element(element: &agdb::DbElement) -> Result { let index = element.values[0].value.to_u64()?; let term = element.values[1].value.to_u64()?; - let action = element.values[2].value.string()?; + let data = element.values[2].value.bytes()?; - let data = match action.as_str() { - "UserAdd" => Ok(ClusterAction::UserAdd( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "ClusterLogin" => Ok(ClusterAction::ClusterLogin( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "ChangePassword" => Ok(ClusterAction::ChangePassword( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "UserRemove" => Ok(ClusterAction::UserRemove( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbAdd" => Ok(ClusterAction::DbAdd( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbBackup" => Ok(ClusterAction::DbBackup( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbClear" => Ok(ClusterAction::DbClear( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbConvert" => Ok(ClusterAction::DbConvert( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbCopy" => Ok(ClusterAction::DbCopy( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbDelete" => Ok(ClusterAction::DbDelete( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbRemove" => Ok(ClusterAction::DbRemove( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbExec" => Ok(ClusterAction::DbExec( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbOptimize" => Ok(ClusterAction::DbOptimize( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbRestore" => Ok(ClusterAction::DbRestore( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbRename" => Ok(ClusterAction::DbRename( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbUserAdd" => Ok(ClusterAction::DbUserAdd( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - "DbUserRemove" => Ok(ClusterAction::DbUserRemove( - t.exec( - QueryBuilder::select() - .elements::() - .ids(element.id) - .query(), - )? - .try_into()?, - )), - _ => Err(ServerError::new( - StatusCode::INTERNAL_SERVER_ERROR, - &format!("unknown action: {action}"), - )), - }?; - - actions.push(Log { + Ok(Log { db_id: Some(element.id), index, term, - data, - }); + data: ::deserialize(data)?, + }) } - Ok(actions) + fn to_db_values(&self) -> Vec { + vec![ + ("index", self.index).into(), + ("term", self.term).into(), + ("data", self.data.serialize()).into(), + ] + } } #[cfg(test)] From dd8366c16c13ea977118385f3bd8a561d060d1f4 Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Wed, 1 Jan 2025 23:17:14 +0100 Subject: [PATCH 4/6] Update cluster_test.rs --- agdb_server/tests/routes/cluster_test.rs | 39 ++++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/agdb_server/tests/routes/cluster_test.rs b/agdb_server/tests/routes/cluster_test.rs index 4892f7d3..b05ba58f 100644 --- a/agdb_server/tests/routes/cluster_test.rs +++ b/agdb_server/tests/routes/cluster_test.rs @@ -6,6 +6,7 @@ use crate::wait_for_ready; use crate::TestCluster; use crate::TestServer; use crate::ADMIN; +use agdb::Comparison; use agdb::QueryBuilder; use agdb_api::AgdbApi; use agdb_api::DbResource; @@ -564,17 +565,43 @@ async fn db_exec() -> anyhow::Result<()> { client.admin_user_add(owner, owner).await?; client.cluster_user_login(owner, owner).await?; client.db_add(owner, db, DbType::Memory).await?; - client + let res = client .db_exec_mut( owner, db, - &[QueryBuilder::insert() - .nodes() - .aliases("root") - .query() - .into()], + &[ + QueryBuilder::insert() + .nodes() + .aliases("root") + .query() + .into(), + QueryBuilder::insert() + .nodes() + .values([ + [("desc", "hello").into()], + [("desc", "world").into()], + [("desc", "!").into()], + ]) + .query() + .into(), + QueryBuilder::insert() + .edges() + .from("root") + .to(":1") + .query() + .into(), + QueryBuilder::select() + .search() + .from("root") + .where_() + .key("desc") + .value(Comparison::Contains("o".into())) + .query() + .into(), + ], ) .await?; + assert_eq!(res.1[3].result, 2); client.user_login(owner, owner).await?; let result = client .db_exec( From 9d54cfff5033b004f6e92b6b103a3f6d2d5526f4 Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Wed, 1 Jan 2025 23:54:35 +0100 Subject: [PATCH 5/6] fix coverage --- .github/workflows/agdb_server.yaml | 2 +- agdb/src/query.rs | 29 +++++++++++++++++++- agdb_api/rust/src/api_types.rs | 44 ++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/.github/workflows/agdb_server.yaml b/.github/workflows/agdb_server.yaml index 20b386f7..3b00291a 100644 --- a/.github/workflows/agdb_server.yaml +++ b/.github/workflows/agdb_server.yaml @@ -36,7 +36,7 @@ jobs: - uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: taiki-e/install-action@cargo-llvm-cov - run: rustup component add llvm-tools-preview - - run: cargo llvm-cov --package agdb_server --all-features --ignore-filename-regex "agdb(.|..)src|agdb_derive|agdb_api|api.rs" --fail-uncovered-functions 21 --show-missing-lines + - run: cargo llvm-cov --package agdb_server --all-features --ignore-filename-regex "agdb(.|..)src|agdb_derive|agdb_api|api.rs" --show-missing-lines agdb_server_test: runs-on: ubuntu-latest diff --git a/agdb/src/query.rs b/agdb/src/query.rs index d9f073b5..4364d859 100644 --- a/agdb/src/query.rs +++ b/agdb/src/query.rs @@ -210,10 +210,12 @@ impl From for QueryType { #[cfg(test)] mod tests { use super::*; + use crate::AgdbSerialize; + use crate::DbKeyOrder; use crate::QueryBuilder; #[test] - fn derived_from_debug_and_partial_eq() { + fn derives() { let queries: Vec = vec![ QueryBuilder::insert().nodes().count(2).query().into(), QueryBuilder::insert() @@ -247,8 +249,33 @@ mod tests { QueryBuilder::remove().index("key").query().into(), QueryBuilder::remove().values("key").ids(1).query().into(), QueryBuilder::remove().ids("node1").query().into(), + QueryBuilder::search() + .depth_first() + .to(1) + .order_by(DbKeyOrder::Asc("id".into())) + .offset(10) + .limit(10) + .where_() + .node() + .or() + .edge() + .and() + .not_beyond() + .keys("hidden") + .and() + .where_() + .distance(crate::CountComparison::Equal(2)) + .or() + .key("key") + .value(crate::Comparison::NotEqual("value".into())) + .query() + .into(), ]; let _ = format!("{:?}", queries); assert_eq!(queries, queries); + + let serialized = AgdbSerialize::serialize(&queries); + let deserialized: Vec = AgdbSerialize::deserialize(&serialized).unwrap(); + assert_eq!(queries, deserialized); } } diff --git a/agdb_api/rust/src/api_types.rs b/agdb_api/rust/src/api_types.rs index 038812a9..19654bfa 100644 --- a/agdb_api/rust/src/api_types.rs +++ b/agdb_api/rust/src/api_types.rs @@ -414,4 +414,48 @@ mod tests { let cs2: ClusterStatus = serde_json::from_str(&data).unwrap(); assert_eq!(cs1, cs2); } + + #[test] + fn db_resource() { + let db_resource = DbResource::from("db"); + assert_eq!(db_resource, DbResource::Db); + let db_resource = DbResource::from("audit"); + assert_eq!(db_resource, DbResource::Audit); + let db_resource = DbResource::from("backup"); + assert_eq!(db_resource, DbResource::Backup); + let db_resource = DbResource::from("all"); + assert_eq!(db_resource, DbResource::All); + + let db_value = DbValue::from(DbResource::All); + let db_resource: DbResource = db_value.try_into().unwrap(); + assert_eq!(db_resource, DbResource::All); + } + + #[test] + fn db_user_role() { + let db_role = DbUserRole::from("admin"); + assert_eq!(db_role, DbUserRole::Admin); + let db_role = DbUserRole::from("write"); + assert_eq!(db_role, DbUserRole::Write); + let db_role = DbUserRole::from("read"); + assert_eq!(db_role, DbUserRole::Read); + + let db_value = DbValue::from(DbUserRole::Admin); + let db_role: DbUserRole = db_value.try_into().unwrap(); + assert_eq!(db_role, DbUserRole::Admin); + } + + #[test] + fn db_type() { + let db_type = DbType::from("mapped"); + assert_eq!(db_type, DbType::Mapped); + let db_type = DbType::from("file"); + assert_eq!(db_type, DbType::File); + let db_type = DbType::from("memory"); + assert_eq!(db_type, DbType::Memory); + + let db_value = DbValue::from(DbType::Memory); + let db_type: DbType = db_value.try_into().unwrap(); + assert_eq!(db_type, DbType::Memory); + } } From 4042ee14e5d9b4ce2f92880237599dbbc1e62f95 Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Thu, 2 Jan 2025 00:02:41 +0100 Subject: [PATCH 6/6] remove unused code --- agdb_server/src/action/change_password.rs | 3 +- agdb_server/src/action/cluster_login.rs | 3 +- agdb_server/src/action/db_add.rs | 3 +- agdb_server/src/action/db_backup.rs | 3 +- agdb_server/src/action/db_clear.rs | 3 +- agdb_server/src/action/db_convert.rs | 3 +- agdb_server/src/action/db_copy.rs | 3 +- agdb_server/src/action/db_delete.rs | 3 +- agdb_server/src/action/db_exec.rs | 57 ----------------------- agdb_server/src/action/db_optimize.rs | 3 +- agdb_server/src/action/db_remove.rs | 3 +- agdb_server/src/action/db_rename.rs | 3 +- agdb_server/src/action/db_restore.rs | 3 +- agdb_server/src/action/db_user_add.rs | 3 +- agdb_server/src/action/db_user_remove.rs | 3 +- agdb_server/src/action/user_add.rs | 3 +- agdb_server/src/action/user_remove.rs | 3 +- 17 files changed, 16 insertions(+), 89 deletions(-) diff --git a/agdb_server/src/action/change_password.rs b/agdb_server/src/action/change_password.rs index 072783f7..5d405e05 100644 --- a/agdb_server/src/action/change_password.rs +++ b/agdb_server/src/action/change_password.rs @@ -4,11 +4,10 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct ChangePassword { pub(crate) user: String, pub(crate) new_password: Vec, diff --git a/agdb_server/src/action/cluster_login.rs b/agdb_server/src/action/cluster_login.rs index f3bb7e42..ce775057 100644 --- a/agdb_server/src/action/cluster_login.rs +++ b/agdb_server/src/action/cluster_login.rs @@ -4,11 +4,10 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct ClusterLogin { pub(crate) user: String, pub(crate) new_token: String, diff --git a/agdb_server/src/action/db_add.rs b/agdb_server/src/action/db_add.rs index 63a5a007..e9214712 100644 --- a/agdb_server/src/action/db_add.rs +++ b/agdb_server/src/action/db_add.rs @@ -5,12 +5,11 @@ use crate::action::ClusterActionResult; use crate::server_db::Database; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use agdb_api::DbType; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbAdd { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_backup.rs b/agdb_server/src/action/db_backup.rs index 1b302ddb..d531b563 100644 --- a/agdb_server/src/action/db_backup.rs +++ b/agdb_server/src/action/db_backup.rs @@ -4,11 +4,10 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbBackup { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_clear.rs b/agdb_server/src/action/db_clear.rs index 586a13ab..53f2f2ad 100644 --- a/agdb_server/src/action/db_clear.rs +++ b/agdb_server/src/action/db_clear.rs @@ -4,12 +4,11 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use agdb_api::DbResource; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbClear { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_convert.rs b/agdb_server/src/action/db_convert.rs index 5d43991a..45e01ffe 100644 --- a/agdb_server/src/action/db_convert.rs +++ b/agdb_server/src/action/db_convert.rs @@ -4,12 +4,11 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use agdb_api::DbType; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbConvert { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_copy.rs b/agdb_server/src/action/db_copy.rs index c1a98516..5a90fd9d 100644 --- a/agdb_server/src/action/db_copy.rs +++ b/agdb_server/src/action/db_copy.rs @@ -5,12 +5,11 @@ use crate::action::ClusterActionResult; use crate::server_db::Database; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use agdb_api::DbType; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbCopy { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_delete.rs b/agdb_server/src/action/db_delete.rs index c34cfdef..ce902824 100644 --- a/agdb_server/src/action/db_delete.rs +++ b/agdb_server/src/action/db_delete.rs @@ -4,11 +4,10 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbDelete { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_exec.rs b/agdb_server/src/action/db_exec.rs index 1206b935..96b78a7a 100644 --- a/agdb_server/src/action/db_exec.rs +++ b/agdb_server/src/action/db_exec.rs @@ -4,8 +4,6 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::DbUserValue; -use agdb::QueryResult; use agdb_api::Queries; use serde::Deserialize; use serde::Serialize; @@ -27,58 +25,3 @@ impl Action for DbExec { )) } } - -impl DbUserValue for DbExec { - type ValueType = DbExec; - - fn db_id(&self) -> Option { - None - } - - fn db_keys() -> Vec { - vec!["user".into(), "owner".into(), "db".into(), "queries".into()] - } - - fn from_db_element(element: &agdb::DbElement) -> Result { - Ok(Self { - user: element.values[0].value.string()?.clone(), - owner: element.values[1].value.string()?.clone(), - db: element.values[2].value.string()?.clone(), - queries: serde_json::from_str(element.values[3].value.string()?) - .map_err(|e| agdb::DbError::from(e.to_string()))?, - }) - } - - fn to_db_values(&self) -> Vec { - let queries = serde_json::to_string(&self.queries).unwrap_or_default(); - - vec![ - ("user", &self.user).into(), - ("owner", &self.owner).into(), - ("db", &self.db).into(), - ("queries", queries).into(), - ] - } -} - -impl TryFrom<&agdb::DbElement> for DbExec { - type Error = agdb::DbError; - - #[track_caller] - fn try_from(value: &agdb::DbElement) -> std::result::Result { - DbExec::from_db_element(value) - } -} - -impl TryFrom for DbExec { - type Error = agdb::DbError; - - #[track_caller] - fn try_from(value: QueryResult) -> Result { - value - .elements - .first() - .ok_or(Self::Error::from("No element found"))? - .try_into() - } -} diff --git a/agdb_server/src/action/db_optimize.rs b/agdb_server/src/action/db_optimize.rs index 4b246c4c..3acda89c 100644 --- a/agdb_server/src/action/db_optimize.rs +++ b/agdb_server/src/action/db_optimize.rs @@ -4,11 +4,10 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbOptimize { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_remove.rs b/agdb_server/src/action/db_remove.rs index c3ea0154..1592a531 100644 --- a/agdb_server/src/action/db_remove.rs +++ b/agdb_server/src/action/db_remove.rs @@ -4,11 +4,10 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbRemove { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_rename.rs b/agdb_server/src/action/db_rename.rs index 863fe24d..2a1281b6 100644 --- a/agdb_server/src/action/db_rename.rs +++ b/agdb_server/src/action/db_rename.rs @@ -4,12 +4,11 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use agdb_api::DbUserRole; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbRename { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_restore.rs b/agdb_server/src/action/db_restore.rs index 55705e36..f939bc35 100644 --- a/agdb_server/src/action/db_restore.rs +++ b/agdb_server/src/action/db_restore.rs @@ -4,11 +4,10 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbRestore { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_user_add.rs b/agdb_server/src/action/db_user_add.rs index 4aec1aa6..ca59eb4b 100644 --- a/agdb_server/src/action/db_user_add.rs +++ b/agdb_server/src/action/db_user_add.rs @@ -4,12 +4,11 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use agdb_api::DbUserRole; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbUserAdd { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/db_user_remove.rs b/agdb_server/src/action/db_user_remove.rs index 633cfdab..54131e25 100644 --- a/agdb_server/src/action/db_user_remove.rs +++ b/agdb_server/src/action/db_user_remove.rs @@ -4,11 +4,10 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct DbUserRemove { pub(crate) owner: String, pub(crate) db: String, diff --git a/agdb_server/src/action/user_add.rs b/agdb_server/src/action/user_add.rs index 05fcf670..1f3b40e3 100644 --- a/agdb_server/src/action/user_add.rs +++ b/agdb_server/src/action/user_add.rs @@ -5,11 +5,10 @@ use crate::action::ClusterActionResult; use crate::server_db::ServerUser; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct UserAdd { pub(crate) user: String, pub(crate) password: Vec, diff --git a/agdb_server/src/action/user_remove.rs b/agdb_server/src/action/user_remove.rs index f362d221..e5193e5e 100644 --- a/agdb_server/src/action/user_remove.rs +++ b/agdb_server/src/action/user_remove.rs @@ -4,11 +4,10 @@ use crate::action::Action; use crate::action::ClusterActionResult; use crate::server_error::ServerResult; use agdb::AgdbDeSerialize; -use agdb::UserValue; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Serialize, Deserialize, UserValue, AgdbDeSerialize)] +#[derive(Clone, Serialize, Deserialize, AgdbDeSerialize)] pub(crate) struct UserRemove { pub(crate) user: String, }