surrealdb_expr/expr/
index_kind.rs1use surrealdb_types::{SqlFormat, ToSql};
8
9use crate::expr::Cond;
10use crate::sql;
11use crate::sql::index::{DiskAnnParams, FullTextParams, HnswParams};
12
13#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
14pub enum Index {
15 #[default]
17 Idx,
18 Uniq,
20 Hnsw(HnswParams),
22 FullText(FullTextParams),
24 Count(Option<Cond>),
26 DiskAnn(DiskAnnParams),
28}
29
30impl From<sql::index::Index> for Index {
31 fn from(v: sql::index::Index) -> Self {
32 match v {
33 sql::index::Index::Idx => Self::Idx,
34 sql::index::Index::Uniq => Self::Uniq,
35 sql::index::Index::Hnsw(p) => Self::Hnsw(p),
36 sql::index::Index::FullText(p) => Self::FullText(p),
37 sql::index::Index::Count(c) => Self::Count(c.map(Into::into)),
38 sql::index::Index::DiskAnn(p) => Self::DiskAnn(p),
39 }
40 }
41}
42
43impl From<Index> for sql::index::Index {
44 fn from(v: Index) -> Self {
45 match v {
46 Index::Idx => Self::Idx,
47 Index::Uniq => Self::Uniq,
48 Index::Hnsw(p) => Self::Hnsw(p),
49 Index::FullText(p) => Self::FullText(p),
50 Index::Count(c) => Self::Count(c.map(Into::into)),
51 Index::DiskAnn(p) => Self::DiskAnn(p),
52 }
53 }
54}
55
56impl ToSql for Index {
57 fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
58 let stmt: sql::index::Index = self.clone().into();
59 stmt.fmt_sql(f, fmt);
60 }
61}