surrealdb_server/rpc/
http.rs1use std::sync::Arc;
2
3use surrealdb_core::dbs::Session;
4use surrealdb_core::kvs::Datastore;
5use surrealdb_core::rpc::{DbResult, Method, RpcProtocol, method_not_found};
6use surrealdb_types::{Array, Error as TypesError, HashMap, Value};
7use tokio::sync::RwLock;
8use uuid::Uuid;
9
10use crate::cnf::{PKG_NAME, PKG_VERSION};
11
12pub struct Http {
13 pub kvs: Arc<Datastore>,
14 pub sessions: HashMap<Option<Uuid>, Arc<RwLock<Session>>>,
15}
16
17impl Http {
18 pub fn new(kvs: Arc<Datastore>, session: Session) -> Self {
19 let http = Self {
20 kvs,
21 sessions: HashMap::new(),
22 };
23 http.sessions.insert(None, Arc::new(RwLock::new(session)));
25 http
26 }
27}
28
29impl RpcProtocol for Http {
30 fn kvs(&self) -> &Datastore {
32 &self.kvs
33 }
34
35 fn version_data(&self) -> DbResult {
37 let value = Value::String(format!("{PKG_NAME}-{}", *PKG_VERSION));
38 DbResult::Other(value)
39 }
40
41 fn session_map(&self) -> &HashMap<Option<Uuid>, Arc<RwLock<Session>>> {
43 &self.sessions
44 }
45
46 const LQ_SUPPORT: bool = false;
52
53 async fn cleanup_lqs(&self, _session_id: Option<&Uuid>) {
55 }
57
58 async fn cleanup_all_lqs(&self) {
60 }
62
63 async fn begin(
69 &self,
70 _txn: Option<Uuid>,
71 _session_id: Option<Uuid>,
72 ) -> Result<DbResult, TypesError> {
73 Err(method_not_found(Method::Begin.to_string()))
74 }
75
76 async fn commit(
78 &self,
79 _txn: Option<Uuid>,
80 _session_id: Option<Uuid>,
81 _params: Array,
82 ) -> Result<DbResult, TypesError> {
83 Err(method_not_found(Method::Commit.to_string()))
84 }
85
86 async fn cancel(
88 &self,
89 _txn: Option<Uuid>,
90 _session_id: Option<Uuid>,
91 _params: Array,
92 ) -> Result<DbResult, TypesError> {
93 Err(method_not_found(Method::Cancel.to_string()))
94 }
95}