mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-19 01:24:20 +01:00
40 lines
1.0 KiB
Rust
40 lines
1.0 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
|
pub enum SortOrder {
|
|
Asc,
|
|
Desc,
|
|
}
|
|
|
|
impl std::fmt::Display for SortOrder {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
SortOrder::Asc => write!(f, "ASC"),
|
|
SortOrder::Desc => write!(f, "DESC"),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
|
pub(crate) struct CreateIndex {
|
|
pub(crate) index_name: String,
|
|
pub(crate) table_name: String,
|
|
pub(crate) columns: Vec<(String, SortOrder)>,
|
|
}
|
|
|
|
impl std::fmt::Display for CreateIndex {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(
|
|
f,
|
|
"CREATE INDEX {} ON {} ({})",
|
|
self.index_name,
|
|
self.table_name,
|
|
self.columns
|
|
.iter()
|
|
.map(|(name, order)| format!("{name} {order}"))
|
|
.collect::<Vec<String>>()
|
|
.join(", ")
|
|
)
|
|
}
|
|
}
|