vibesql_ast/operators.rs
1//! Operator enums for SQL expressions
2
3/// Binary operators for SQL expressions
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum BinaryOperator {
6 // Arithmetic
7 Plus,
8 Minus,
9 Multiply,
10 Divide,
11 IntegerDivide, // DIV (MySQL-specific integer division)
12 Modulo,
13
14 // Comparison
15 Equal,
16 NotEqual,
17 LessThan,
18 LessThanOrEqual,
19 GreaterThan,
20 GreaterThanOrEqual,
21
22 // Logical
23 And,
24 Or,
25
26 // String
27 Concat, /* || */
28
29 // Bitwise
30 BitwiseAnd, // &
31 BitwiseOr, // |
32 LeftShift, // <<
33 RightShift, // >>
34
35 // Vector distance operators (pgvector compatible)
36 CosineDistance, // <-> (1 - cosine_similarity)
37 NegativeInnerProduct, // <#> (negative dot product for MIPS)
38 L2Distance, // <=> (Euclidean distance)
39
40 // JSON operators (SQLite/PostgreSQL compatible)
41 JsonExtract, // -> (extract JSON value)
42 JsonExtractText, // ->> (extract as text)
43
44 /* Note: LIKE and IN are not simple binary operators. They are
45 * implemented as Expression variants in
46 * expression.rs due to their complex structure:
47 * - LIKE: Pattern matching with wildcards (%, _)
48 * - IN: Subquery or value list support */
49}
50
51impl BinaryOperator {
52 /// Returns true if this operator is represented as a word (AND, OR, DIV)
53 /// rather than a symbol (+, -, <, etc.)
54 ///
55 /// Word operators require spaces around them in SQL, while symbolic
56 /// operators do not (though spaces are optional).
57 pub fn is_word_operator(&self) -> bool {
58 matches!(self, BinaryOperator::And | BinaryOperator::Or | BinaryOperator::IntegerDivide)
59 }
60}
61
62/// Unary operators for SQL expressions
63#[derive(Debug, Clone, Copy, PartialEq, Eq)]
64pub enum UnaryOperator {
65 Not, // NOT
66 Minus, // - (negation)
67 Plus, // + (unary plus)
68 BitwiseNot, // ~ (bitwise NOT)
69 IsNull, // IS NULL
70 IsNotNull, // IS NOT NULL
71}