1use common::fmt::{EscapeKwFreeIdent, Fmt};
2use surrealdb_types::{SqlFormat, ToSql, write_sql};
3
4#[derive(Clone, Debug, Eq, PartialEq, Hash)]
5#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
6pub enum With {
7 NoIndex,
8 Index(
9 #[cfg_attr(feature = "arbitrary", arbitrary(with = crate::arbitrary::atleast_one))]
10 Vec<String>,
11 ),
12}
13
14impl ToSql for With {
15 fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
16 f.push_str("WITH");
17 match self {
18 With::NoIndex => f.push_str(" NOINDEX"),
19 With::Index(i) => {
20 f.push_str(" INDEX ");
21 write_sql!(
22 f,
23 fmt,
24 "{}",
25 Fmt::comma_separated(i.iter().map(|x| EscapeKwFreeIdent(x)))
26 );
27 }
28 }
29 }
30}