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
//! Utility functions for the SDK

/// debug print queries generated by diesel for the postgres backend
///
/// # Example
///
/// ```ignore
/// use diesel::prelude::*;
///
/// diesel::table! {
///     use diesel::sql_types::*;
///
///     user (id) {
///         id -> Int8,
///         name -> Text,
///     }
/// }
///
/// let conn = ft_sdk::default_pg().unwrap();
///
/// let query = user::table
///     .select(user::name)
///     .filter(user::id.eq(9))
///     .limit(1);
///
/// ft_sdk::utils::dbg_query(&query);
/// ```
pub fn dbg_query<T: diesel::query_builder::QueryFragment<B>, B: diesel::backend::Backend>(
    _query: &T,
) {
    #[cfg(feature = "debug")]
    ft_sdk::println!("{:?}", diesel::debug_query::<B, _>(_query));
}

/// Generate a new uuid v8 using the uuid crate
pub fn uuid_v8() -> String {
    use rand_core::RngCore;

    let mut rand_buf: [u8; 16] = Default::default();
    ft_sdk::Rng::fill_bytes(&mut ft_sdk::Rng {}, &mut rand_buf);
    uuid::Uuid::new_v8(rand_buf).to_string()
}