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 From<Data> for Value {
49 fn from(val: Data) -> Self {
50 match val {
51 Data::Query(v) => sql::to_value(v).unwrap(),
52 Data::Live(v) => sql::to_value(v).unwrap(),
53 Data::Other(v) => v,
54 }
55 }
56}