drizzle_core/
schema.rs

1use crate::{ToSQL, sql::SQL, traits::SQLParam};
2
3/// The type of SQLite database object
4#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord)]
5pub enum SQLSchemaType {
6    /// A regular table
7    Table,
8    /// A view
9    View,
10    /// An index
11    Index,
12    /// A trigger
13    Trigger,
14}
15
16/// Sort direction for ORDER BY clauses
17#[derive(Clone, Copy, Debug, PartialEq, Eq)]
18pub enum OrderBy {
19    Asc,
20    Desc,
21}
22
23impl OrderBy {
24    /// Creates an ascending ORDER BY clause: "column ASC"
25    pub fn asc<'a, V, T>(column: T) -> SQL<'a, V>
26    where
27        V: SQLParam + 'a,
28        T: ToSQL<'a, V>,
29    {
30        column.to_sql().append(Self::Asc.to_sql())
31    }
32
33    /// Creates a descending ORDER BY clause: "column DESC"
34    pub fn desc<'a, V, T>(column: T) -> SQL<'a, V>
35    where
36        V: SQLParam + 'a,
37        T: ToSQL<'a, V>,
38    {
39        column.to_sql().append(Self::Desc.to_sql())
40    }
41}
42
43impl<'a, V: SQLParam + 'a> ToSQL<'a, V> for OrderBy {
44    fn to_sql(&self) -> SQL<'a, V> {
45        let sql_str = match self {
46            OrderBy::Asc => "ASC",
47            OrderBy::Desc => "DESC",
48        };
49        SQL::raw(sql_str)
50    }
51}