|
12 | 12 |
|
13 | 13 | use core::fmt;
|
14 | 14 |
|
| 15 | +#[cfg(not(feature = "std"))] |
| 16 | +use alloc::{string::String, vec::Vec}; |
15 | 17 | #[cfg(feature = "serde")]
|
16 | 18 | use serde::{Deserialize, Serialize};
|
17 | 19 |
|
| 20 | +use super::display_separated; |
| 21 | + |
18 | 22 | /// Unary operators
|
19 | 23 | #[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
20 | 24 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
@@ -86,41 +90,49 @@ pub enum BinaryOperator {
|
86 | 90 | PGRegexIMatch,
|
87 | 91 | PGRegexNotMatch,
|
88 | 92 | PGRegexNotIMatch,
|
| 93 | + /// PostgreSQL-specific custom operator. |
| 94 | + /// |
| 95 | + /// See [CREATE OPERATOR](https://www.postgresql.org/docs/current/sql-createoperator.html) |
| 96 | + /// for more information. |
| 97 | + PGCustomBinaryOperator(Vec<String>), |
89 | 98 | }
|
90 | 99 |
|
91 | 100 | impl fmt::Display for BinaryOperator {
|
92 | 101 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
93 |
| - f.write_str(match self { |
94 |
| - BinaryOperator::Plus => "+", |
95 |
| - BinaryOperator::Minus => "-", |
96 |
| - BinaryOperator::Multiply => "*", |
97 |
| - BinaryOperator::Divide => "/", |
98 |
| - BinaryOperator::Modulo => "%", |
99 |
| - BinaryOperator::StringConcat => "||", |
100 |
| - BinaryOperator::Gt => ">", |
101 |
| - BinaryOperator::Lt => "<", |
102 |
| - BinaryOperator::GtEq => ">=", |
103 |
| - BinaryOperator::LtEq => "<=", |
104 |
| - BinaryOperator::Spaceship => "<=>", |
105 |
| - BinaryOperator::Eq => "=", |
106 |
| - BinaryOperator::NotEq => "<>", |
107 |
| - BinaryOperator::And => "AND", |
108 |
| - BinaryOperator::Or => "OR", |
109 |
| - BinaryOperator::Xor => "XOR", |
110 |
| - BinaryOperator::Like => "LIKE", |
111 |
| - BinaryOperator::NotLike => "NOT LIKE", |
112 |
| - BinaryOperator::ILike => "ILIKE", |
113 |
| - BinaryOperator::NotILike => "NOT ILIKE", |
114 |
| - BinaryOperator::BitwiseOr => "|", |
115 |
| - BinaryOperator::BitwiseAnd => "&", |
116 |
| - BinaryOperator::BitwiseXor => "^", |
117 |
| - BinaryOperator::PGBitwiseXor => "#", |
118 |
| - BinaryOperator::PGBitwiseShiftLeft => "<<", |
119 |
| - BinaryOperator::PGBitwiseShiftRight => ">>", |
120 |
| - BinaryOperator::PGRegexMatch => "~", |
121 |
| - BinaryOperator::PGRegexIMatch => "~*", |
122 |
| - BinaryOperator::PGRegexNotMatch => "!~", |
123 |
| - BinaryOperator::PGRegexNotIMatch => "!~*", |
124 |
| - }) |
| 102 | + match self { |
| 103 | + BinaryOperator::Plus => f.write_str("+"), |
| 104 | + BinaryOperator::Minus => f.write_str("-"), |
| 105 | + BinaryOperator::Multiply => f.write_str("*"), |
| 106 | + BinaryOperator::Divide => f.write_str("/"), |
| 107 | + BinaryOperator::Modulo => f.write_str("%"), |
| 108 | + BinaryOperator::StringConcat => f.write_str("||"), |
| 109 | + BinaryOperator::Gt => f.write_str(">"), |
| 110 | + BinaryOperator::Lt => f.write_str("<"), |
| 111 | + BinaryOperator::GtEq => f.write_str(">="), |
| 112 | + BinaryOperator::LtEq => f.write_str("<="), |
| 113 | + BinaryOperator::Spaceship => f.write_str("<=>"), |
| 114 | + BinaryOperator::Eq => f.write_str("="), |
| 115 | + BinaryOperator::NotEq => f.write_str("<>"), |
| 116 | + BinaryOperator::And => f.write_str("AND"), |
| 117 | + BinaryOperator::Or => f.write_str("OR"), |
| 118 | + BinaryOperator::Xor => f.write_str("XOR"), |
| 119 | + BinaryOperator::Like => f.write_str("LIKE"), |
| 120 | + BinaryOperator::NotLike => f.write_str("NOT LIKE"), |
| 121 | + BinaryOperator::ILike => f.write_str("ILIKE"), |
| 122 | + BinaryOperator::NotILike => f.write_str("NOT ILIKE"), |
| 123 | + BinaryOperator::BitwiseOr => f.write_str("|"), |
| 124 | + BinaryOperator::BitwiseAnd => f.write_str("&"), |
| 125 | + BinaryOperator::BitwiseXor => f.write_str("^"), |
| 126 | + BinaryOperator::PGBitwiseXor => f.write_str("#"), |
| 127 | + BinaryOperator::PGBitwiseShiftLeft => f.write_str("<<"), |
| 128 | + BinaryOperator::PGBitwiseShiftRight => f.write_str(">>"), |
| 129 | + BinaryOperator::PGRegexMatch => f.write_str("~"), |
| 130 | + BinaryOperator::PGRegexIMatch => f.write_str("~*"), |
| 131 | + BinaryOperator::PGRegexNotMatch => f.write_str("!~"), |
| 132 | + BinaryOperator::PGRegexNotIMatch => f.write_str("!~*"), |
| 133 | + BinaryOperator::PGCustomBinaryOperator(idents) => { |
| 134 | + write!(f, "OPERATOR({})", display_separated(idents, ".")) |
| 135 | + } |
| 136 | + } |
125 | 137 | }
|
126 | 138 | }
|
0 commit comments