ft_sdk/
utils.rs

1//! Utility functions for the SDK
2
3/// debug print queries generated by diesel for the postgres backend
4///
5/// # Example
6///
7/// ```ignore
8/// use diesel::prelude::*;
9///
10/// diesel::table! {
11///     use diesel::sql_types::*;
12///
13///     user (id) {
14///         id -> Int8,
15///         name -> Text,
16///     }
17/// }
18///
19/// let conn = ft_sdk::default_pg().unwrap();
20///
21/// let query = user::table
22///     .select(user::name)
23///     .filter(user::id.eq(9))
24///     .limit(1);
25///
26/// ft_sdk::utils::dbg_query(&query);
27/// ```
28pub fn dbg_query<T: diesel::query_builder::QueryFragment<B>, B: diesel::backend::Backend>(
29    _query: &T,
30) {
31    #[cfg(feature = "debug")]
32    ft_sdk::println!("{:?}", diesel::debug_query::<B, _>(_query));
33}
34
35/// Generate a new uuid v8 using the uuid crate
36pub fn uuid_v8() -> String {
37    use rand_core::RngCore;
38
39    let mut rand_buf: [u8; 16] = Default::default();
40    ft_sdk::Rng::fill_bytes(&mut ft_sdk::Rng {}, &mut rand_buf);
41    uuid::Uuid::new_v8(rand_buf).to_string()
42}