|
@@ -1,7 +1,7 @@
|
|
use serde::de::Visitor;
|
|
use serde::de::Visitor;
|
|
|
|
|
|
-use std::rc::Rc;
|
|
|
|
use std::cell::Cell;
|
|
use std::cell::Cell;
|
|
|
|
+use std::rc::Rc;
|
|
|
|
|
|
#[derive(Debug)]
|
|
#[derive(Debug)]
|
|
pub struct CreateDeserializer<'de> {
|
|
pub struct CreateDeserializer<'de> {
|
|
@@ -16,7 +16,8 @@ pub struct CreateDeserializer<'de> {
|
|
impl<'de> CreateDeserializer<'de> {
|
|
impl<'de> CreateDeserializer<'de> {
|
|
fn integral_type(&mut self) {
|
|
fn integral_type(&mut self) {
|
|
self.column_types.push("integer");
|
|
self.column_types.push("integer");
|
|
- self.column_names.push(self.column_name_stack.pop().unwrap());
|
|
|
|
|
|
+ self.column_names
|
|
|
|
+ .push(self.column_name_stack.pop().unwrap());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -71,25 +72,26 @@ impl<'de, 'a> serde::de::Deserializer<'de> for &'a mut CreateDeserializer<'de> {
|
|
|
|
|
|
fn deserialize_string<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
|
|
fn deserialize_string<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
|
|
self.column_types.push("text");
|
|
self.column_types.push("text");
|
|
- self.column_names.push(self.column_name_stack.pop().unwrap());
|
|
|
|
|
|
+ self.column_names
|
|
|
|
+ .push(self.column_name_stack.pop().unwrap());
|
|
v.visit_string("".to_owned())
|
|
v.visit_string("".to_owned())
|
|
}
|
|
}
|
|
|
|
|
|
fn deserialize_bytes<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
|
|
fn deserialize_bytes<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
|
|
self.column_types.push("blob");
|
|
self.column_types.push("blob");
|
|
- self.column_names.push(self.column_name_stack.pop().unwrap());
|
|
|
|
|
|
+ self.column_names
|
|
|
|
+ .push(self.column_name_stack.pop().unwrap());
|
|
v.visit_bytes(&[])
|
|
v.visit_bytes(&[])
|
|
}
|
|
}
|
|
|
|
|
|
fn deserialize_byte_buf<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
|
|
fn deserialize_byte_buf<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
|
|
self.column_types.push("blob");
|
|
self.column_types.push("blob");
|
|
- self.column_names.push(self.column_name_stack.pop().unwrap());
|
|
|
|
|
|
+ self.column_names
|
|
|
|
+ .push(self.column_name_stack.pop().unwrap());
|
|
v.visit_bytes(&[])
|
|
v.visit_bytes(&[])
|
|
}
|
|
}
|
|
|
|
|
|
- fn deserialize_seq<V: Visitor<'de>>(
|
|
|
|
- self, v: V) -> Result<V::Value, Self::Error> {
|
|
|
|
-
|
|
|
|
|
|
+ fn deserialize_seq<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
|
|
v.visit_seq(self)
|
|
v.visit_seq(self)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -104,8 +106,7 @@ impl<'de, 'a> serde::de::Deserializer<'de> for &'a mut CreateDeserializer<'de> {
|
|
let old_elength = elength.get();
|
|
let old_elength = elength.get();
|
|
println!("nested deserialize_struct invoked!");
|
|
println!("nested deserialize_struct invoked!");
|
|
todo!();
|
|
todo!();
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
self.column_name_stack.extend(fields.iter().rev());
|
|
self.column_name_stack.extend(fields.iter().rev());
|
|
self.expected_length.set(fields.len());
|
|
self.expected_length.set(fields.len());
|
|
let ret = v.visit_seq(self);
|
|
let ret = v.visit_seq(self);
|
|
@@ -116,7 +117,7 @@ impl<'de, 'a> serde::de::Deserializer<'de> for &'a mut CreateDeserializer<'de> {
|
|
fn deserialize_newtype_struct<V: Visitor<'de>>(
|
|
fn deserialize_newtype_struct<V: Visitor<'de>>(
|
|
self,
|
|
self,
|
|
name: &'static str,
|
|
name: &'static str,
|
|
- v: V
|
|
|
|
|
|
+ v: V,
|
|
) -> Result<V::Value, Self::Error> {
|
|
) -> Result<V::Value, Self::Error> {
|
|
let elength = self.expected_length.clone();
|
|
let elength = self.expected_length.clone();
|
|
let old_elength = elength.get();
|
|
let old_elength = elength.get();
|
|
@@ -137,7 +138,7 @@ impl<'de> serde::de::SeqAccess<'de> for CreateDeserializer<'de> {
|
|
seed: T,
|
|
seed: T,
|
|
) -> Result<Option<T::Value>, Self::Error> {
|
|
) -> Result<Option<T::Value>, Self::Error> {
|
|
if self.expected_length.get() == 0 {
|
|
if self.expected_length.get() == 0 {
|
|
- return Err(Self::Error::CreateError)
|
|
|
|
|
|
+ return Err(Self::Error::CreateError);
|
|
}
|
|
}
|
|
|
|
|
|
self.expected_length.set(self.expected_length.get() - 1);
|
|
self.expected_length.set(self.expected_length.get() - 1);
|
|
@@ -147,7 +148,6 @@ impl<'de> serde::de::SeqAccess<'de> for CreateDeserializer<'de> {
|
|
}
|
|
}
|
|
|
|
|
|
pub fn sql_for<T: crate::model::Entity>() -> (String, String) {
|
|
pub fn sql_for<T: crate::model::Entity>() -> (String, String) {
|
|
-
|
|
|
|
let mut elength = Rc::new(Cell::new(0));
|
|
let mut elength = Rc::new(Cell::new(0));
|
|
|
|
|
|
let mut cd = CreateDeserializer {
|
|
let mut cd = CreateDeserializer {
|
|
@@ -247,7 +247,7 @@ mod test {
|
|
|
|
|
|
#[derive(serde::Serialize, serde::Deserialize, crate::Modelable)]
|
|
#[derive(serde::Serialize, serde::Deserialize, crate::Modelable)]
|
|
#[microrm_internal]
|
|
#[microrm_internal]
|
|
- pub struct NonUnit(u8,u8);
|
|
|
|
|
|
+ pub struct NonUnit(u8, u8);
|
|
#[derive(serde::Serialize, serde::Deserialize, crate::Entity)]
|
|
#[derive(serde::Serialize, serde::Deserialize, crate::Entity)]
|
|
#[microrm_internal]
|
|
#[microrm_internal]
|
|
pub struct NonUnitNewtype {
|
|
pub struct NonUnitNewtype {
|