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 FilterCondition object, which you pass into:
$query->filterCondition($condition);
๐ฏ Types of Filters
ZTeraDB supports 4 categories:
- Comparison Filters
- Math Filters
- String Filters
- Logical Filters
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])โ
ZTEQUAL(ZTADD(['price', 50]), 150);
SQL Equivalent
(price + 50) = 150;
โ ZTSUB([a, b])โ
ZTSUB(['price', 'discount']);
SQL Equivalent
(price - discount);
โ ZTMUL([a, b])โ
ZTEQUAL(ZTMUL(['a', 'b']), 10);
SQL Equivalent
(a * b) = 10;
โ ZTDIV(a, b)โ
ZTDIV('price', 2);
SQL Equivalent
(price / 2);
๐ข ZTMOD(a, b)โ
ZTEQUAL(ZTMOD('id', 2), 0);
SQL Equivalent
(id % 2) = 0;
3๏ธโฃ String Filters
๐ ZTCONTAINS(field, value)โ
ZTCONTAINS('name', 'Tea');
SQL Equivalent
name LIKE '%Tea%';
๐ ZTICONTAINS(field, value)โ
ZTICONTAINS('name', 'john');
SQL Equivalent
LOWER(name) LIKE '%john%';
๐ฆ ZTSTARTSWITH(field, value)โ
ZTSTARTSWITH('product_name', 'A');
SQL Equivalent
product_name LIKE 'A%';
๐ฆ ZTISTARTSWITH(field, value)โ
ZTISTARTSWITH('product_name', 'a');
SQL Equivalent
LOWER(product_name) LIKE 'a%';
๐ฉ ZTENDSWITH(field, value)โ
ZTENDSWITH('tag', 'pro');
SQL Equivalent
tag LIKE '%pro';
๐ฉ ZTIENDSWITH(field, value)โ
ZTIENDSWITH('tag', 'PRO');
SQL Equivalent
LOWER(tag) LIKE '%pro';
4๏ธโฃ Logical Filters
๐ข ZTAND([condition1, condition2])โ
ZTAND([
ZTGTE(['age', 18]),
ZTLT(['age', 30])
]);
SQL Equivalent
(age >= 18) AND (age < 30);
๐ด ZTOR([condition1, condition2])โ
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".
$fc = ZTAND([
ZTGT([ZTMUL(['price', 'quantity']), 500]),
ZTICONTAINS('name', 'wire')
]);
$query = (new ZTeraDBQuery('product'))
->select()
->filterCondition($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 .filterCondition() |
| Incorrect casing in string filters | Use ZTICONTAINS |
| Empty conditions | Always include at least one condition |
๐ You now understand all ZTeraDB filters โ and their SQL equivalents!
Continue to:
๐ query-examples.md