Skip to main content

vantage_sql/sqlite/
operation.rs

1//! SqliteOperation trait — vendor-specific comparison operations producing
2//! `SqliteCondition`. Generated by `define_sql_operation!` in `condition.rs`.
3
4use crate::condition::SqliteCondition;
5use crate::define_sql_operation;
6
7define_sql_operation!(
8    SqliteOperation,
9    SqliteCondition,
10    crate::sqlite::types::AnySqliteType
11);
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16    use crate::sqlite::types::AnySqliteType;
17    use vantage_table::column::core::Column;
18
19    #[test]
20    fn test_column_eq() {
21        let name = Column::<AnySqliteType>::new("name");
22        let cond = name.eq(AnySqliteType::from("Alice".to_string()));
23        assert_eq!(cond.into_expr().preview(), "name = 'Alice'");
24    }
25
26    #[test]
27    fn test_typed_column_gt() {
28        let price = Column::<i64>::new("price");
29        let cond = price.gt(150i64);
30        assert_eq!(cond.into_expr().preview(), "price > 150");
31    }
32
33    #[test]
34    fn test_chaining_gt_eq_false() {
35        let price = Column::<i64>::new("price");
36        let cond = price.gt(10i64).eq(false);
37        assert_eq!(cond.into_expr().preview(), "price > 10 = 0");
38    }
39
40    #[test]
41    fn test_chaining_gt_eq_true() {
42        let price = Column::<i64>::new("price");
43        let cond = price.gt(10i64).eq(true);
44        assert_eq!(cond.into_expr().preview(), "price > 10 = 1");
45    }
46
47    #[test]
48    fn test_typed_bool_column() {
49        let is_deleted = Column::<bool>::new("is_deleted");
50        let cond = is_deleted.eq(false);
51        assert_eq!(cond.into_expr().preview(), "is_deleted = 0");
52    }
53
54    #[test]
55    fn test_cross_type_rejected() {
56        // price.gt(false) should NOT compile — bool isn't Expressive<i64>
57        // This is a compile-time guarantee, not a runtime test.
58        let price = Column::<i64>::new("price");
59        let _: SqliteCondition = price.gt(150i64);
60    }
61}