Skip to main content

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:

  1. Comparison Filters
  2. Math Filters
  3. String Filters
  4. 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)

MistakeFix
Passing single value instead of array in math filtersAlways pass arrays like ['a', 'b']
Using .filter() for advanced logicUse .filterCondition()
Incorrect casing in string filtersUse ZTICONTAINS
Empty conditionsAlways include at least one condition

๐ŸŽ‰ You now understand all ZTeraDB filters โ€” and their SQL equivalents!

Continue to:
๐Ÿ‘‰ query-examples.md