surrealdb_core/rpc/
context.rs1#[cfg(all(not(target_family = "wasm"), surrealdb_unstable))]
2use crate::gql::SchemaCache;
3use std::sync::Arc;
4use tokio::sync::Semaphore;
5use uuid::Uuid;
6
7use super::Data;
8use super::Method;
9use super::RpcError;
10use super::RpcProtocolV1;
11use super::RpcProtocolV2;
12use crate::dbs::Session;
13use crate::kvs::Datastore;
14use crate::sql::Array;
15
16#[allow(async_fn_in_trait)]
17pub trait RpcContext {
18 fn kvs(&self) -> &Datastore;
20 fn lock(&self) -> Arc<Semaphore>;
22 fn session(&self) -> Arc<Session>;
24 fn set_session(&self, session: Arc<Session>);
26 fn version_data(&self) -> Data;
28
29 const LQ_SUPPORT: bool = false;
35
36 fn handle_live(&self, _lqid: &Uuid) -> impl std::future::Future<Output = ()> + Send {
38 async { unimplemented!("handle_live function must be implemented if LQ_SUPPORT = true") }
39 }
40 fn handle_kill(&self, _lqid: &Uuid) -> impl std::future::Future<Output = ()> + Send {
42 async { unimplemented!("handle_kill function must be implemented if LQ_SUPPORT = true") }
43 }
44 fn cleanup_lqs(&self) -> impl std::future::Future<Output = ()> + Send {
46 async { unimplemented!("cleanup_lqs function must be implemented if LQ_SUPPORT = true") }
47 }
48
49 #[cfg(all(not(target_family = "wasm"), surrealdb_unstable))]
55 const GQL_SUPPORT: bool = false;
56
57 #[cfg(all(not(target_family = "wasm"), surrealdb_unstable))]
59 fn graphql_schema_cache(&self) -> &SchemaCache {
60 unimplemented!("graphql_schema_cache function must be implemented if GQL_SUPPORT = true")
61 }
62
63 async fn execute(
69 &self,
70 version: Option<u8>,
71 method: Method,
72 params: Array,
73 ) -> Result<Data, RpcError>
74 where
75 Self: RpcProtocolV1,
76 Self: RpcProtocolV2,
77 {
78 match version {
79 Some(1) => RpcProtocolV1::execute(self, method, params).await,
80 Some(2) => RpcProtocolV2::execute(self, method, params).await,
81 _ => RpcProtocolV1::execute(self, method, params).await,
82 }
83 }
84}