aboutsummaryrefslogtreecommitdiff
path: root/database/src/query_ser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'database/src/query_ser.rs')
-rw-r--r--database/src/query_ser.rs88
1 files changed, 0 insertions, 88 deletions
diff --git a/database/src/query_ser.rs b/database/src/query_ser.rs
deleted file mode 100644
index 78eee09..0000000
--- a/database/src/query_ser.rs
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- This file is part of jellything (https://codeberg.org/metamuffin/jellything)
- which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
- Copyright (C) 2026 metamuffin <metamuffin.org>
-*/
-
-use jellyobject::Value;
-
-use crate::{Filter, MultiBehaviour, Query, Sort, SortOrder, ValueSort};
-
-impl Query<'_> {
- pub fn show(&self) -> String {
- let mut o = String::new();
- if !matches!(self.filter, Filter::True) {
- o += &format!("FILTER {} ", self.filter.show())
- }
- if !matches!(self.sort, Sort::None) {
- o += &format!("SORT {} ", self.sort.show())
- }
- o
- }
-}
-impl Filter<'_> {
- pub fn show(&self) -> String {
- match self {
- Filter::True => "TRUE".to_string(),
- Filter::All(filters) => format!(
- "({})",
- filters
- .iter()
- .map(|f| f.show())
- .collect::<Vec<_>>()
- .join(" AND ")
- ),
- Filter::Any(filters) => format!(
- "({})",
- filters
- .iter()
- .map(|f| f.show())
- .collect::<Vec<_>>()
- .join(" OR ")
- ),
- Filter::Match(path, value) => {
- format!("{path} = {}", show_value(value))
- }
- Filter::Has(path) => format!("{path}"),
- }
- }
-}
-impl Sort {
- pub fn show(&self) -> String {
- match self {
- Sort::None => "NONE".to_string(),
- Sort::Value(ValueSort {
- multi, order, path, ..
- }) => {
- format!(
- "{} BY {} {path}",
- match order {
- SortOrder::Ascending => "ASCENDING",
- SortOrder::Descending => "DESCENDING",
- },
- match multi {
- MultiBehaviour::Count => "COUNT",
- MultiBehaviour::First => "FIRST",
- MultiBehaviour::ForEach => "EACH",
- MultiBehaviour::Max => "MAX",
- MultiBehaviour::Min => "MIN",
- },
- )
- }
- Sort::TextSearch(path, value) => {
- format!("TEXT SEARCH {path} = {value:?}")
- }
- }
- }
-}
-
-fn show_value(value: &Value) -> String {
- match value {
- Value::Tag(tag) => format!("{tag}"),
- Value::U32(x) => format!("{x}"),
- Value::U64(x) => format!("{x}"),
- Value::I64(x) => format!("{x}"),
- Value::String(x) => format!("{x:?}"),
- Value::Binary(x) => format!("{x:?}"),
- }
-}