Skip to main content

easy_sql/traits/
to_default.rs

1use crate::Driver;
2
3/// Converts a Rust value into a SQL default expression.
4///
5/// Used by table/insert macros when emitting `DEFAULT` or default expressions.
6pub trait ToDefault<D: Driver> {
7    /// Returns a raw SQL string representing the default value for the type.
8    fn to_default(self) -> String;
9}
10#[macro_export]
11#[doc(hidden)]
12/// Support auto implement because I'm lazy
13macro_rules! impl_to_default_to_string_with_ref {
14    ($t:ty) => {
15        impl ToDefault<D> for $t {
16            fn to_default(self) -> String {
17                self.to_string()
18            }
19        }
20
21        impl<'a> ToDefault<D> for &'a $t {
22            fn to_default(self) -> String {
23                self.to_string()
24            }
25        }
26    };
27}