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:
AyushChothe 2023-07-19 21:11:50 +05:30 committed by GitHub
parent 53702c247a
commit b98ade2ca8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,17 +1,34 @@
use crate::sql::{Object, Value};
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt::Debug;
use serde::{ser::SerializeStruct, Deserialize, Serialize};
use std::fmt::{self, Debug, Display};
use uuid::Uuid;
#[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 id: Uuid,
pub action: Action,
pub result: Value,
}
impl fmt::Display for Notification {
impl Display for Notification {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let obj: Object = map! {
"id".to_string() => self.id.to_string().into(),
@ -23,20 +40,15 @@ impl fmt::Display for Notification {
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum Action {
Create,
Update,
Delete,
}
impl fmt::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"),
}
impl Serialize for Notification {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut val = serializer.serialize_struct("Notification", 3)?;
val.serialize_field("id", &self.id.to_string())?;
val.serialize_field("action", &self.action)?;
val.serialize_field("result", &self.result)?;
val.end()
}
}