ObjectStackObjectStack

Query

Query protocol schemas

Sort Node

Represents "Order By".

Source: packages/spec/src/data/query.zod.ts

TypeScript Usage

import { AggregationFunction, AggregationNode, FieldNode, FullTextSearch, JoinNode, JoinStrategy, JoinType, Query, SortNode, WindowFunction, WindowFunctionNode, WindowSpec } from '@objectstack/spec/data';
import type { AggregationFunction, AggregationNode, FieldNode, FullTextSearch, JoinNode, JoinStrategy, JoinType, Query, SortNode, WindowFunction, WindowFunctionNode, WindowSpec } from '@objectstack/spec/data';

// Validate data
const result = AggregationFunction.parse(data);

AggregationFunction

Allowed Values

  • count
  • sum
  • avg
  • min
  • max
  • count_distinct
  • array_agg
  • string_agg

AggregationNode

Properties

PropertyTypeRequiredDescription
functionEnum<'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct' | 'array_agg' | 'string_agg'>Aggregation function
fieldstringoptionalField to aggregate (optional for COUNT(*))
aliasstringResult column alias
distinctbooleanoptionalApply DISTINCT before aggregation
filter[__schema0](./__schema0)optionalFilter/Condition to apply to the aggregation (FILTER WHERE clause)

FieldNode

Union Options

This schema accepts one of the following structures:

Option 1

Type: string


Option 2

Properties

PropertyTypeRequiredDescription
fieldstring
fields[#](./#)[]optional
aliasstringoptional


FullTextSearch

Properties

PropertyTypeRequiredDescription
querystringSearch query text
fieldsstring[]optionalFields to search in (if not specified, searches all text fields)
fuzzybooleanEnable fuzzy matching (tolerates typos)
operatorEnum<'and' | 'or'>Logical operator between terms
boostRecord<string, number>optionalField-specific relevance boosting (field name -> boost factor)
minScorenumberoptionalMinimum relevance score threshold
languagestringoptionalLanguage for text analysis (e.g., "en", "zh", "es")
highlightbooleanEnable search result highlighting

JoinNode

Properties

PropertyTypeRequiredDescription
typeEnum<'inner' | 'left' | 'right' | 'full'>Join type
strategyEnum<'auto' | 'database' | 'hash' | 'loop'>optionalExecution strategy hint
objectstringObject/table to join
aliasstringoptionalTable alias
on[__schema0](./__schema0)Join condition
subquery[__schema1](./__schema1)optionalSubquery instead of object

JoinStrategy

Allowed Values

  • auto
  • database
  • hash
  • loop

JoinType

Allowed Values

  • inner
  • left
  • right
  • full

Query

Properties

PropertyTypeRequiredDescription
objectstringObject name (e.g. account)
fields[__schema0](./__schema0)[]optionalFields to retrieve
where[__schema1](./__schema1)optionalFiltering criteria (WHERE)
searchObjectoptionalFull-text search configuration ($search parameter)
orderByObject[]optionalSorting instructions (ORDER BY)
limitnumberoptionalMax records to return (LIMIT)
offsetnumberoptionalRecords to skip (OFFSET)
topnumberoptionalAlias for limit (OData compatibility)
cursorRecord<string, any>optionalCursor for keyset pagination
joinsObject[]optionalExplicit Table Joins
aggregationsObject[]optionalAggregation functions
groupBystring[]optionalGROUP BY fields
having[__schema1](./__schema1)optionalHAVING clause for aggregation filtering
windowFunctionsObject[]optionalWindow functions with OVER clause
distinctbooleanoptionalSELECT DISTINCT flag
expandRecord<string, [#](./#)>optionalRecursive relation loading map. Keys are lookup/master_detail field names; values are nested QueryAST objects that control select, filter, sort, and further expansion on the related object. The engine resolves expand via batch $in queries (driver-agnostic) with a default max depth of 3.

SortNode

Properties

PropertyTypeRequiredDescription
fieldstring
orderEnum<'asc' | 'desc'>

WindowFunction

Allowed Values

  • row_number
  • rank
  • dense_rank
  • percent_rank
  • lag
  • lead
  • first_value
  • last_value
  • sum
  • avg
  • count
  • min
  • max

WindowFunctionNode

Properties

PropertyTypeRequiredDescription
functionEnum<'row_number' | 'rank' | 'dense_rank' | 'percent_rank' | 'lag' | 'lead' | 'first_value' | 'last_value' | 'sum' | 'avg' | 'count' | 'min' | 'max'>Window function name
fieldstringoptionalField to operate on (for aggregate window functions)
aliasstringResult column alias
overObjectWindow specification (OVER clause)

WindowSpec

Properties

PropertyTypeRequiredDescription
partitionBystring[]optionalPARTITION BY fields
orderByObject[]optionalORDER BY specification
frameObjectoptionalWindow frame specification

On this page