ZTeraDB Filter Conditions
This guide explains all filter functions in ZTeraDB in the simplest possible way.
Filters allow you to build powerful conditions like:
- a = b
- a > b
- price * quantity > 100
- name contains "abc"
- age in [20, 30]
Every filter returns a FilterConditions object, which you pass into:
query.filterConditions(condition);
π― Types of Filters
ZTeraDB supports 4 categories:
- Comparison Filters
- Math Filters
- String Filters
- Logical Filters
All examples include the SQL equivalent of the condition.
1οΈβ£ Comparison Filters
π© ZTEQUAL(a, b)β
Checks if a = b.
ZTEQUAL("age", 25)
ZTEQUAL(ZTMUL(["price", 2]), 100)
SQL Equivalent
age = 25;
(price * 2) = 100;
π¦ ZTGT([a, b])β
Checks if a > b.
ZTGT(["age", 18])
ZTGT(["price", ZTMUL(["discount", 2])])
SQL Equivalent
age > 18;
price > (discount * 2);
πͺ ZTGTE([a, b])β
Checks if a β₯ b.
ZTGTE(["salary", 40000])
SQL Equivalent
salary >= 40000;
π§ ZTLT([a, b])β
Checks if a < b.
ZTLT(["age", 65])
SQL Equivalent
age < 65;
π« ZTLTE([a, b])β
Checks if a β€ b.
ZTLTE(["rating", 5])
SQL Equivalent
rating <= 5;
π¨ ZTIN(field, [values])β
Checks if field IN (values).
ZTIN("age", [20, 25, 30])
SQL Equivalent
age IN (20, 25, 30);
2οΈβ£ Math Filters
These allow calculations inside filters.
β ZTADD([a, b, c])β
a + b + c
ZTEQUAL(ZTADD(["price", 50]), 150)
SQL Equivalent
(price + 50) = 150;
β ZTSUB([a, b])β
a - b
ZTSUB(["price", "discount"])
SQL Equivalent
(price - discount);
β ZTMUL([a, b])β
a * b
ZTEQUAL(ZTMUL(["a", "b"]), 10)
SQL Equivalent
(a * b) = 10;
β ZTDIV(a, b)β
a Γ· b
ZTDIV("price", 2)
SQL Equivalent
(price / 2);
π’ ZTMOD(a, b)β
a % b
ZTEQUAL(ZTMOD("id", 2), 0) // even numbers
SQL Equivalent
(id % 2) = 0;
3οΈβ£ String Filters
π ZTCONTAINS(field, value)β
Case-sensitive search.
ZTCONTAINS("name", "Tea")
SQL Equivalent
name LIKE '%Tea%';
π ZTICONTAINS(field, value)β
Case-insensitive.
ZTICONTAINS("name", "john")
SQL Equivalent
LOWER(name) LIKE '%john%';
π¦ ZTSTARTSWITH(field, value)β
Case-sensitive βstarts withβ.
ZTSTARTSWITH("product_name", "A")
SQL Equivalent
product_name LIKE 'A%';
π¦ ZTISTARTSWITH(field, value)β
Case-insensitive.
ZTISTARTSWITH("product_name", "a")
SQL Equivalent
LOWER(product_name) LIKE 'a%';
π© ZTENDSWITH(field, value)β
Case-sensitive βends withβ.
ZTENDSWITH("tag", "pro")
SQL Equivalent
tag LIKE '%pro';
π© ZTIENDSWITH(field, value)β
Case-insensitive.
ZTIENDSWITH("tag", "PRO")
SQL Equivalent
LOWER(tag) LIKE '%pro';
4οΈβ£ Logical Filters
Combines multiple conditions.
π’ ZTAND([condition1, condition2])β
All conditions must be true.
ZTAND([
ZTGTE(["age", 18]),
ZTLT(["age", 30])
])
SQL Equivalent
(age >= 18) AND (age < 30);
π΄ ZTOR([condition1, condition2])β
At least one condition must be true.
ZTOR([
ZTEQUAL("status", "A"),
ZTEQUAL("status", "D")
])
SQL Equivalent
(status = 'A') OR (status = 'D');
π§ͺ Full Practical Example
Get all products where price * quantity > 500 AND name contains "wire".
const fc = ZTAND([
ZTGT([ZTMUL(["price", "quantity"]), 500]),
ZTICONTAINS("name", "wire")
]);
const query = new ZTeraDBQuery("product")
.select()
.filterConditions(fc);
SQL Equivalent
SELECT *
FROM product
WHERE (price * quantity) > 500
AND LOWER(name) LIKE '%wire%';
β Common Mistakes (and fixes)
| Mistake | Fix |
|---|---|
| Passing single value instead of array in math filters | Always pass arrays like ["a", "b"] |
Using .filter() for advanced logic | Use .filterConditions() |
| Incorrect casing in string filters | Use ZTICONTAINS for safer matching |
| Passing empty conditions | Ensure at least one filter is present |
π You now understand all ZTeraDB filters β and their SQL equivalents!
Continue to:
π query-examples.md