1use std::borrow::Cow;
10
11use serde::{Deserialize, Serialize};
12
13use super::Expr;
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct RenameIndexStmt {
17 pub name: String,
18 pub new_name: String,
19 pub if_exists: bool,
20}
21
22#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum IndexKey {
25 Column(String),
26 Expression(Box<Expr>),
27}
28
29impl IndexKey {
30 #[must_use]
31 pub fn from_expression(expression: Expr) -> Self {
32 match expression {
33 Expr::Column(column) => Self::Column(column),
34 other => Self::Expression(Box::new(other)),
35 }
36 }
37
38 #[must_use]
39 pub fn column(&self) -> Option<&str> {
40 match self {
41 Self::Column(column) => Some(column),
42 Self::Expression(_) => None,
43 }
44 }
45
46 #[must_use]
47 pub fn expression(&self) -> Cow<'_, Expr> {
48 match self {
49 Self::Column(column) => Cow::Owned(Expr::Column(column.clone())),
50 Self::Expression(expression) => Cow::Borrowed(expression),
51 }
52 }
53}
54
55impl From<String> for IndexKey {
56 fn from(column: String) -> Self {
57 Self::Column(column)
58 }
59}
60
61impl From<&str> for IndexKey {
62 fn from(column: &str) -> Self {
63 Self::Column(column.into())
64 }
65}