surrealdb/sql/
model.rs

1use crate::{
2	ctx::Context,
3	dbs::{Options, Transaction},
4	doc::CursorDoc,
5	err::Error,
6	sql::value::Value,
7};
8use async_recursion::async_recursion;
9use derive::Store;
10use revision::revisioned;
11use serde::{Deserialize, Serialize};
12use std::fmt;
13
14#[derive(Clone, Debug, Default, PartialEq, PartialOrd, Serialize, Deserialize, Store, Hash)]
15#[revisioned(revision = 1)]
16pub struct Model {
17	pub name: String,
18	pub version: String,
19	pub args: Vec<Value>,
20}
21
22impl fmt::Display for Model {
23	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24		write!(f, "ml::{}<{}>(", self.name, self.version)?;
25		for (idx, p) in self.args.iter().enumerate() {
26			if idx != 0 {
27				write!(f, ",")?;
28			}
29			write!(f, "{}", p)?;
30		}
31		write!(f, ")")
32	}
33}
34
35impl Model {
36	#[cfg_attr(not(target_arch = "wasm32"), async_recursion)]
37	#[cfg_attr(target_arch = "wasm32", async_recursion(?Send))]
38	pub(crate) async fn compute(
39		&self,
40		_ctx: &Context<'_>,
41		_opt: &Options,
42		_txn: &Transaction,
43		_doc: Option<&'async_recursion CursorDoc<'_>>,
44	) -> Result<Value, Error> {
45		Err(Error::Unimplemented("ML model evaluation not yet implemented".to_string()))
46	}
47}