select is a method for specifying which fields to query. You can select fields in a type-safe manner and use SQL aggregate functions and expressions.
Basic Usage
Query All Fields
Select Specific Fields
Field Alias
SQL Aggregate Functions
Puri provides type-safe SQL functions.COUNT
SUM, AVG, MAX, MIN
String Functions
Raw SQL Expressions
You can use complex SQL expressions.Type-Specific Raw Functions
Nested Object Selection
You can write SELECT statements with nested object structures.appendSelect
Adds fields to existing SELECT.Full-Text Search Functions
ts_highlight (PostgreSQL)
Highlighting using PostgreSQL’s tsvector.parser: Query parser (default:"websearch_to_tsquery")config: Text search configuration (default:"simple")startSel: Start tag (default:"<b>")stopSel: End tag (default:"</b>")maxWords: Maximum number of wordsminWords: Minimum number of wordsmaxFragments: Maximum number of fragments
ts_rank (PostgreSQL)
Calculates search relevance score.parser: Query parser (default:"websearch_to_tsquery")config: Text search configuration (default:"simple")weights: [D, C, B, A] weight arraynormalization: Normalization option (0-32)
PGroonga Functions
Full-text search using PGroonga extension.pg_trgm Similarity Functions
Calculates similarity scores provided by PostgreSQL’spg_trgm extension in SELECT. After filtering candidates with whereFuzzy, these functions can be used to compute per-column weighted scores.
SqlExpression<"number">) can be combined with rawNumber to compute per-column weighted scores.
These functions return
SqlExpression<"number"> and can be used within select. The pg_trgm extension must be installed.Practical Examples
- User Statistics
- Order Summary
- Users + Posts
- Search + Highlighting
Type Safety
SELECT return types are automatically inferred.Cautions
1. select vs appendSelect
2. Table Prefix Required
3. Specify Raw SQL Types
Next Steps
where
Filter with conditions
join
Join tables
order-by
Sort results
advanced-methods
Advanced query methods