sql_builder/extension/postgres/mod.rs
1//! PostgreSQL's own operators, expressions and functions.
2
3pub use expr::*;
4pub use func::*;
5
6use crate::types::BinOper;
7
8pub(crate) mod expr;
9pub(crate) mod func;
10pub(crate) mod interval;
11
12binary_operators! {
13 /// The binary operators only PostgreSQL has; [`BinOper`] holds them alongside the
14 /// standard ones.
15 ///
16 /// The `pg_trgm` ones need that extension installed
17 /// (<https://www.postgresql.org/docs/current/pgtrgm.html>).
18 pub enum PgBinOper {
19 /// `LIKE` ignoring case.
20 ILike = "ILIKE",
21 /// `NOT LIKE` ignoring case.
22 NotILike = "NOT ILIKE",
23 /// a `tsvector` matches a `tsquery` (full-text search).
24 Matches = "@@",
25 /// the left array or `jsonb` value contains the right one.
26 Contains = "@>",
27 /// the left array or `jsonb` value is contained in the right one.
28 Contained = "<@",
29 /// joins two strings, arrays or `jsonb` values.
30 Concatenate = "||",
31 /// the two arrays share an element.
32 Overlap = "&&",
33 /// the strings' trigram similarity passes the threshold (`pg_trgm`).
34 Similarity = "%",
35 /// the left string's word similarity to the right one passes the threshold
36 /// (`pg_trgm`).
37 WordSimilarity = "<%",
38 /// as `WordSimilarity`, but counting whole words only (`pg_trgm`).
39 StrictWordSimilarity = "<<%",
40 /// one minus the strings' similarity (`pg_trgm`).
41 SimilarityDistance = "<->",
42 /// one minus their word similarity (`pg_trgm`).
43 WordSimilarityDistance = "<<->",
44 /// one minus their strict word similarity (`pg_trgm`).
45 StrictWordSimilarityDistance = "<<<->",
46 /// a JSON object member or array element, as JSON.
47 GetJsonField = "->",
48 /// a JSON object member or array element, as text.
49 CastJsonField = "->>",
50 /// matches a POSIX regular expression, case-sensitively.
51 Regex = "~",
52 /// matches a POSIX regular expression, ignoring case.
53 RegexCaseInsensitive = "~*",
54 }
55}
56
57impl From<PgBinOper> for BinOper {
58 fn from(o: PgBinOper) -> Self {
59 Self::PgOperator(o)
60 }
61}