Live queries Response and Notifications Uuid serialization fixed (#2232)
Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com> Co-authored-by: Przemyslaw Hugh Kaznowski <hugh@surrealdb.com>
This commit is contained in:
parent
53702c247a
commit
b98ade2ca8
1 changed files with 31 additions and 19 deletions
|
@ -1,17 +1,34 @@
|
||||||
use crate::sql::{Object, Value};
|
use crate::sql::{Object, Value};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{ser::SerializeStruct, Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt::{self, Debug, Display};
|
||||||
use std::fmt::Debug;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "UPPERCASE")]
|
||||||
|
pub enum Action {
|
||||||
|
Create,
|
||||||
|
Update,
|
||||||
|
Delete,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Action {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match *self {
|
||||||
|
Action::Create => write!(f, "CREATE"),
|
||||||
|
Action::Update => write!(f, "UPDATE"),
|
||||||
|
Action::Delete => write!(f, "DELETE"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Deserialize)]
|
||||||
pub struct Notification {
|
pub struct Notification {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub action: Action,
|
pub action: Action,
|
||||||
pub result: Value,
|
pub result: Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Notification {
|
impl Display for Notification {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let obj: Object = map! {
|
let obj: Object = map! {
|
||||||
"id".to_string() => self.id.to_string().into(),
|
"id".to_string() => self.id.to_string().into(),
|
||||||
|
@ -23,20 +40,15 @@ impl fmt::Display for Notification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
impl Serialize for Notification {
|
||||||
#[serde(rename_all = "UPPERCASE")]
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
pub enum Action {
|
where
|
||||||
Create,
|
S: serde::Serializer,
|
||||||
Update,
|
{
|
||||||
Delete,
|
let mut val = serializer.serialize_struct("Notification", 3)?;
|
||||||
}
|
val.serialize_field("id", &self.id.to_string())?;
|
||||||
|
val.serialize_field("action", &self.action)?;
|
||||||
impl fmt::Display for Action {
|
val.serialize_field("result", &self.result)?;
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
val.end()
|
||||||
match *self {
|
|
||||||
Action::Create => write!(f, "CREATE"),
|
|
||||||
Action::Update => write!(f, "UPDATE"),
|
|
||||||
Action::Delete => write!(f, "DELETE"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue