surrealdb_expr/expr/record_id/
range.rs1use std::ops::Bound;
2
3use surrealdb_types::{SqlFormat, ToSql};
4
5use super::RecordIdKeyLit;
6
7#[derive(Clone, Debug, Eq, PartialEq, Hash)]
8pub struct RecordIdKeyRangeLit {
9 pub start: Bound<RecordIdKeyLit>,
10 pub end: Bound<RecordIdKeyLit>,
11}
12
13impl RecordIdKeyRangeLit {
14 pub fn is_static(&self) -> bool {
15 let res = match &self.start {
16 Bound::Included(x) => x.is_static(),
17 Bound::Excluded(x) => x.is_static(),
18 Bound::Unbounded => true,
19 };
20
21 if !res {
22 return false;
23 }
24
25 match &self.end {
26 Bound::Included(x) => x.is_static(),
27 Bound::Excluded(x) => x.is_static(),
28 Bound::Unbounded => true,
29 }
30 }
31
32 pub fn read_only(&self) -> bool {
34 let bound_read_only = |bound: &Bound<RecordIdKeyLit>| match bound {
35 Bound::Included(x) | Bound::Excluded(x) => x.read_only(),
36 Bound::Unbounded => true,
37 };
38 bound_read_only(&self.start) && bound_read_only(&self.end)
39 }
40}
41
42impl ToSql for RecordIdKeyRangeLit {
43 fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
44 let range: crate::sql::record_id::range::RecordIdKeyRangeLit = self.clone().into();
45 range.fmt_sql(f, fmt);
46 }
47}