surrealdb_core/rpc/
response.rs1use crate::dbs;
2use crate::dbs::Notification;
3use crate::sql;
4use crate::sql::Value;
5use revision::revisioned;
6use serde::Serialize;
7
8#[revisioned(revision = 1)]
12#[derive(Debug, Serialize)]
13#[non_exhaustive]
14pub enum Data {
15 Other(Value),
17 Query(Vec<dbs::Response>),
19 Live(Notification),
21 }
23
24impl From<Value> for Data {
25 fn from(v: Value) -> Self {
26 Data::Other(v)
27 }
28}
29
30impl From<String> for Data {
31 fn from(v: String) -> Self {
32 Data::Other(Value::from(v))
33 }
34}
35
36impl From<Notification> for Data {
37 fn from(n: Notification) -> Self {
38 Data::Live(n)
39 }
40}
41
42impl From<Vec<dbs::Response>> for Data {
43 fn from(v: Vec<dbs::Response>) -> Self {
44 Data::Query(v)
45 }
46}
47
48impl TryFrom<Data> for Value {
49 type Error = crate::err::Error;
50
51 fn try_from(val: Data) -> Result<Self, Self::Error> {
52 match val {
53 Data::Query(v) => sql::to_value(v),
54 Data::Live(v) => sql::to_value(v),
55 Data::Other(v) => Ok(v),
56 }
57 }
58}