Puri Query Builder
Does Puri directly implement Promise?
Does Puri directly implement Promise?
Yes, Puri directly implements the Usage:Note:
Promise interface.- Methods like
.getMany(),.getOne(),.getScalar()do not exist - Always returns an array (
Expand<TResult>[]) - Use
.first()for single object
How do I use aggregate functions in Puri?
How do I use aggregate functions in Puri?
Use static methods like
Puri.count(), Puri.sum(), Puri.avg().How do I use JOIN in Puri?
How do I use JOIN in Puri?
INNER JOIN:LEFT JOIN:Complex JOIN conditions (callback approach):
How do I use subqueries in Puri?
How do I use subqueries in Puri?
WHERE IN subquery:FROM subquery:
Migrations
How do I create and run migrations?
How do I create and run migrations?
1. Modify EntityEdit Entity in Sonamu UI2. Generate migrationOr via CLI:3. Run migration
How do I safely test migrations?
How do I safely test migrations?
Use Shadow DB for testing:Shadow DB configuration:
How do I safely migrate existing data when changing column types?
How do I safely migrate existing data when changing column types?
Use a temporary column to transform data, then replace the original column.Example: string → integer conversion
How do I preserve data when renaming columns?
How do I preserve data when renaming columns?
Entity auto-generation creates DROP/ADD, so manually use RENAME:
How do I modify columns with FK constraints?
How do I modify columns with FK constraints?
Drop FK constraint, modify column, recreate FK:
PostgreSQL Specific
How do I use PostgreSQL JSONB operators in Puri?
How do I use PostgreSQL JSONB operators in Puri?
Use The value is serialized and bound internally, so do not call Notes:
jsonText() for text extraction, .whereJsonSupersetOf() for containment, and
.whereJsonKeyExists() for top-level key existence. Use Puri.rawString() and parameterized
.whereRaw() only for JSONB operations that these helpers do not support.JSONB text extraction (->>):jsonText() also accepts multiple path segments for nested text. A missing path or JSON null
produces SQL NULL, so a direct selection is string | null; Puri.coalesce() provides a
non-null fallback.JSONB containment operator (@>):JSON.stringify() yourself. For an
OR condition inside parentheses, use orWhereJsonSupersetOf() on a whereGroup().JSONB key existence (?):whereJsonKeyExists() checks only top-level keys. A key still exists when its JSON value is
null.Nested JSONB properties:->>returns text,->returns JSONB- For unsupported operations, use raw expressions with parameter binding to prevent SQL injection
- GIN index recommended:
CREATE INDEX ON products USING gin(metadata);
How do I use PostgreSQL Full-Text Search?
How do I use PostgreSQL Full-Text Search?
Create ts_vector column:Search query:Highlighting:
Transactions
How do I use transactions?
How do I use transactions?
Method 1: Manual transaction (Method 2: Auto-rollback on error. See Manual Transactions and @transactional Decorator for details.
getPuri("w").transaction())@transactional() decorator