use std::fmt;
use std::marker::PhantomData;
use crate::json::JsonPath;
#[derive(PartialEq, Eq)]
pub struct OrderBy<M> {
pub table: &'static str,
pub column: &'static str,
pub desc: bool,
pub json_path: Option<JsonPath>,
pub text: bool,
pub spatial_distance: Option<String>,
pub(crate) _marker: PhantomData<fn() -> M>,
}
impl<M> fmt::Debug for OrderBy<M> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OrderBy")
.field("table", &self.table)
.field("column", &self.column)
.field("desc", &self.desc)
.field("json_path", &self.json_path)
.field("text", &self.text)
.field("spatial_distance", &self.spatial_distance)
.finish()
}
}
impl<M> Clone for OrderBy<M> {
fn clone(&self) -> Self {
Self {
table: self.table,
column: self.column,
desc: self.desc,
json_path: self.json_path.clone(),
text: self.text,
spatial_distance: self.spatial_distance.clone(),
_marker: PhantomData,
}
}
}
impl<M> OrderBy<M> {
#[must_use]
pub const fn new(table: &'static str, column: &'static str, desc: bool) -> Self {
Self {
table,
column,
desc,
json_path: None,
text: false,
spatial_distance: None,
_marker: PhantomData,
}
}
#[must_use]
pub fn spatial_distance(
table: &'static str,
column: &'static str,
geometry_wkt: String,
desc: bool,
) -> Self {
Self {
table,
column,
desc,
json_path: None,
text: false,
spatial_distance: Some(geometry_wkt),
_marker: PhantomData,
}
}
}