1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use super::{Function, FunctionType};
use crate::ast::Expression;

/// Generates the function uuid_to_bin(uuid()) returning a binary uuid in MySQL
/// ```rust
/// # use quaint::{ast::*, visitor::{Visitor, Mysql}};
/// # fn main() -> Result<(), quaint::error::Error> {

/// let query = Select::default().value(uuid_to_bin());
/// let (sql, _) = Mysql::build(query)?;
///
/// assert_eq!("SELECT uuid_to_bin(uuid())", sql);
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "mysql")]
pub fn uuid_to_bin() -> Expression<'static> {
    let func = Function {
        typ_: FunctionType::UuidToBin,
        alias: None,
    };

    func.into()
}

/// Generates an optimized swapped UUID in MySQL 8
/// see `<https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_uuid-to-bin>`
/// ```rust
/// # use quaint::{ast::*, visitor::{Visitor, Mysql}};
/// # fn main() -> Result<(), quaint::error::Error> {
/// let query = Select::default().value(uuid_to_bin_swapped());
/// let (sql, _) = Mysql::build(query)?;
///
/// assert_eq!("SELECT uuid_to_bin(uuid(), 1)", sql);
/// # Ok(())
/// # }
/// ```
pub fn uuid_to_bin_swapped() -> Expression<'static> {
    let func = Function {
        typ_: FunctionType::UuidToBinSwapped,
        alias: None,
    };

    func.into()
}

/// Generates the function uuid_to_bin(uuid()) returning a binary uuid in MySQL
/// ```rust
/// # use quaint::{ast::*, visitor::{Visitor, Mysql}};
/// # fn main() -> Result<(), quaint::error::Error> {

/// let query = Select::default().value(native_uuid());
/// let (sql, _) = Mysql::build(query)?;
///
/// assert_eq!("SELECT uuid()", sql);
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "mysql")]
pub fn native_uuid() -> Expression<'static> {
    let func = Function {
        typ_: FunctionType::Uuid,
        alias: None,
    };

    func.into()
}