Crates.io | suchbar |
lib.rs | suchbar |
version | 1.0.0 |
source | src |
created_at | 2023-04-27 13:55:22.292869 |
updated_at | 2023-12-07 20:29:50.71266 |
description | suchbar - enduser-learnable-language for database queries. |
homepage | |
repository | https://github.com/NORICS-net/suchbar |
max_upload_size | |
id | 850398 |
size | 47,180 |
A query language that can be learned by normal users, similar to an internet search engine.
A query like "plz=26440-26452 OR (Eisen AND sn!=Hammer*)
" could generate such a SQL:
SELECT
pa.shortname, pa.description, pa.taxnumber, pb.longname, pb.postcode, pb.city, pb.street
FROM partner_partner pa, partner_branchstore pb
WHERE
pa.id = pb.cmrpartner AND
(
( pb.postcode>='26440' AND
pb.postcode<='26452'
) OR
( pa.shortname LIKE '%Eisen%' OR
pa.description LIKE '%Eisen%' OR
pa.taxnumber LIKE '%Eisen%' OR
pb.city LIKE '%Eisen%' OR
pb.street LIKE '%Eisen%'
) AND
NOT pa.shortname LIKE 'Hammer%'
)
LIMIT 20;
Boolean Operator | Alternative Symbol | Description |
---|---|---|
AND | && | Requires both terms on either side of the Boolean operator to be present for a match. |
NOT | ! | Requires that the following term not be present. |
OR | || | Requires that either term (or both terms) be present for a match. |
The fields available for searching are registered:
DbField::new("db-fieldname", db-type, "permission", &["name", "alternative_name", "abbr"]),
const SUCHBAR: Suchbar = Suchbar::new(&[
DbField::new("pa.shortname", TEXT, "STD", &["sname", "sn"]),
DbField::new("pa.description", TEXT, "STD", &["desc", "d"]),
DbField::new("pa.taxnumber", VARCHAR(15), "STD", &["ust_id", "tax", "ustid"]),
DbField::new("pb.city", VARCHAR(35), "STD", &["city"]),
DbField::new("pb.street", VARCHAR(55), "STD", &["street", "st"]),
DbField::new("pb.postcode", VARCHAR(5), "STD", &["plz", "zip"]),
]);
fn main() {
let suche = "plz=26440-26452 OR (Eisen AND sn!=Hammer*)";
match SUCHBAR.exec(suche) {
Err(c) => println!("\n{c}"),
Ok(sr) => {
let query = format ! (
"SELECT pa.shortname, pa.description, pa.taxnumber, \
pb.longname, pb.postcode AS INTEGER, pb.city, pb.street \
FROM partner_partner pa, partner_branchstore pb \
WHERE pa.id = pb.cmrpartner{} LIMIT 20",
sr.to_sql("AND")
);
}
}
}