Skip to main content

Puri Query Builder

Yes, Puri directly implements the Promise interface.
Usage:
Note:
  • Methods like .getMany(), .getOne(), .getScalar() do not exist
  • Always returns an array (Expand<TResult>[])
  • Use .first() for single object
Use static methods like Puri.count(), Puri.sum(), Puri.avg().
INNER JOIN:
LEFT JOIN:
Complex JOIN conditions (callback approach):
WHERE IN subquery:
FROM subquery:

Migrations

1. Modify EntityEdit Entity in Sonamu UI2. Generate migration
Or via CLI:
3. Run migration
Use Shadow DB for testing:
Shadow DB configuration:
Use a temporary column to transform data, then replace the original column.Example: string → integer conversion
Entity auto-generation creates DROP/ADD, so manually use RENAME:
Drop FK constraint, modify column, recreate FK:

PostgreSQL Specific

Use the type-safe .whereJsonSupersetOf() for the JSONB containment operator @>. For other JSONB operators, use Puri.rawString() and parameterized .whereRaw().JSONB property query (->>, ->):
JSONB containment operator (@>):
The value is serialized and bound internally, so do not call JSON.stringify() yourself. For an OR condition inside parentheses, use orWhereJsonSupersetOf() on a whereGroup().JSONB key existence (?):
Nested JSONB properties:
Notes:
  • ->> returns text, -> returns JSONB
  • Use parameter binding to prevent SQL Injection
  • GIN index recommended: CREATE INDEX ON products USING gin(metadata);
Create ts_vector column:
Search query:
Highlighting:

Transactions

Method 1: Manual transaction (getPuri("w").transaction())
Method 2: @transactional() decorator
Auto-rollback on error. See Manual Transactions and @transactional Decorator for details.