Skip to main content

vantage_sql/
lib.rs

1pub mod condition;
2pub mod prelude;
3pub mod primitives;
4
5// Re-export so that macros (sqlite_expr!, sql_expr!, etc.) resolve
6// without downstream crates needing a direct vantage-expressions dependency.
7pub use vantage_expressions;
8pub(crate) mod types;
9
10#[cfg(any(feature = "sqlite", feature = "postgres", feature = "mysql"))]
11mod set_writes;
12#[cfg(any(feature = "sqlite", feature = "postgres", feature = "mysql"))]
13mod sql_exec;
14#[cfg(any(feature = "sqlite", feature = "postgres", feature = "mysql"))]
15mod sql_tx;
16#[cfg(all(
17    feature = "vista",
18    any(feature = "sqlite", feature = "postgres", feature = "mysql")
19))]
20mod sql_vista;
21#[cfg(any(feature = "sqlite", feature = "postgres", feature = "mysql"))]
22mod table_writes;
23
24#[cfg(feature = "sqlite")]
25pub mod sqlite;
26
27#[cfg(feature = "postgres")]
28pub mod postgres;
29
30#[cfg(feature = "mysql")]
31pub mod mysql;
32
33#[cfg(feature = "rhai")]
34pub mod rhai_engine;
35
36/// The `LIKE` operand for a substring match: `%text%` with the wildcards and
37/// the escape itself escaped, so a `_` or `%` in what the user typed matches
38/// itself. Shared by quicksearch and by the vista `FilterOp::Like`, which is
39/// what keeps the two spelling the same pattern.
40pub(crate) fn like_pattern_str(text: &str) -> String {
41    let escaped = text
42        .replace('$', "$$")
43        .replace('%', "$%")
44        .replace('_', "$_");
45    format!("%{escaped}%")
46}
47
48/// [`like_pattern_str`] over a filter operand, which may be any scalar.
49#[cfg(feature = "vista")]
50pub(crate) fn like_pattern(value: &ciborium::Value) -> String {
51    like_pattern_str(&vantage_vista::operand_text(value))
52}