surrealdb_core/rpc/
context.rs#[cfg(all(not(target_family = "wasm"), surrealdb_unstable))]
use crate::gql::SchemaCache;
use std::sync::Arc;
use tokio::sync::Semaphore;
use uuid::Uuid;
use super::Data;
use super::Method;
use super::RpcError;
use super::RpcProtocolV1;
use super::RpcProtocolV2;
use crate::dbs::Session;
use crate::kvs::Datastore;
use crate::sql::Array;
#[allow(async_fn_in_trait)]
pub trait RpcContext {
fn kvs(&self) -> &Datastore;
fn lock(&self) -> Arc<Semaphore>;
fn session(&self) -> Arc<Session>;
fn set_session(&self, session: Arc<Session>);
fn version_data(&self) -> Data;
const LQ_SUPPORT: bool = false;
fn handle_live(&self, _lqid: &Uuid) -> impl std::future::Future<Output = ()> + Send {
async { unimplemented!("handle_live function must be implemented if LQ_SUPPORT = true") }
}
fn handle_kill(&self, _lqid: &Uuid) -> impl std::future::Future<Output = ()> + Send {
async { unimplemented!("handle_kill function must be implemented if LQ_SUPPORT = true") }
}
fn cleanup_lqs(&self) -> impl std::future::Future<Output = ()> + Send {
async { unimplemented!("cleanup_lqs function must be implemented if LQ_SUPPORT = true") }
}
#[cfg(all(not(target_family = "wasm"), surrealdb_unstable))]
const GQL_SUPPORT: bool = false;
#[cfg(all(not(target_family = "wasm"), surrealdb_unstable))]
fn graphql_schema_cache(&self) -> &SchemaCache {
unimplemented!("graphql_schema_cache function must be implemented if GQL_SUPPORT = true")
}
async fn execute(
&self,
version: Option<u8>,
method: Method,
params: Array,
) -> Result<Data, RpcError>
where
Self: RpcProtocolV1,
Self: RpcProtocolV2,
{
match version {
Some(1) => RpcProtocolV1::execute(self, method, params).await,
Some(2) => RpcProtocolV2::execute(self, method, params).await,
_ => RpcProtocolV1::execute(self, method, params).await,
}
}
}