import { freeze } from '../util/object-utils.js' ; import { FromNode } from './from-node.js' ; import { GroupByItemNode } from './group-by-item-node.js' ; import { GroupByNode } from './group-by-node.js' ; import { HavingNode } from './having-node.js' ; import { JoinNode } from './join-node.js' ; import { LimitNode } from './limit-node.js' ; import { OffsetNode } from './offset-node.js' ; import { OperationNode } from './operation-node.js' ; import { FilterExpressionNode , TableExpressionNode , } from './operation-node-utils.js' ; import { OrderByItemNode } from './order-by-item-node.js' ; import { OrderByNode } from './order-by-node.js' ; import { SelectionNode } from './selection-node.js' ; import { WhereNode } from './where-node.js' ; import { WithNode } from './with-node.js' ; import { UnionNode } from './union-node.js' ; export type SelectModifier = 'ForUpdate' | 'ForNoKeyUpdate' | 'ForShare' | 'ForKeyShare' | 'NoWait' | 'SkipLocked' ; export interface SelectQueryNode extends OperationNode { readonly kind : 'SelectQueryNode' ; readonly from : FromNode ; readonly selections ? : ReadonlyArray < SelectionNode > ; readonly distinctOnSelections ? : ReadonlyArray < SelectionNode > ; readonly distinct ? : boolean ; readonly joins ? : ReadonlyArray < JoinNode > ; readonly groupBy ? : GroupByNode ; readonly orderBy ? : OrderByNode ; readonly where ? : WhereNode ; readonly modifiers ? : ReadonlyArray < SelectModifier > ; readonly limit ? : LimitNode ; readonly offset ? : OffsetNode ; readonly with ? : WithNode ; readonly having ? : HavingNode ; readonly union ? : ReadonlyArray < UnionNode > ; } internal export const SelectQueryNode = freeze ( { is ( node ) { return node . kind === 'SelectQueryNode' ; } , create ( fromItems , withNode ? ) { return freeze ( { kind : 'SelectQueryNode' , from : FromNode . create ( fromItems ) , ... ( withNode && { with : withNode } ) , } ) ; } , cloneWithSelections ( select , selections ) { return freeze ( { ... select , selections : select . selections ? freeze ( [ ... select . selections , ... selections ] ) : freeze ( selections ) , } ) ; } , cloneWithDistinctOnSelections ( select , selections ) { return freeze ( { ... select , distinctOnSelections : select . distinctOnSelections ? freeze ( [ ... select . distinctOnSelections , ... selections ] ) : freeze ( selections ) , } ) ; } , cloneWithModifier ( select , modifier ) { return freeze ( { ... select , modifiers : select . modifiers ? freeze ( [ ... select . modifiers , modifier ] ) : freeze ( [ modifier ] ) , } ) ; } , cloneWithOrderByItem ( selectNode , item ) { return freeze ( { ... selectNode , orderBy : selectNode . orderBy ? OrderByNode . cloneWithItem ( selectNode . orderBy , item ) : OrderByNode . create ( item ) , } ) ; } , cloneWithGroupByItems ( selectNode , items ) { return freeze ( { ... selectNode , groupBy : selectNode . groupBy ? GroupByNode . cloneWithItems ( selectNode . groupBy , items ) : GroupByNode . create ( items ) , } ) ; } , cloneWithLimit ( selectNode , limit ) { return freeze ( { ... selectNode , limit , } ) ; } , cloneWithOffset ( selectNode , offset ) { return freeze ( { ... selectNode , offset , } ) ; } , cloneWithHaving ( selectNode , filter ) { return freeze ( { ... selectNode , having : selectNode . having ? HavingNode . cloneWithFilter ( selectNode . having , 'And' , filter ) : HavingNode . create ( filter ) , } ) ; } , cloneWithOrHaving ( selectNode , filter ) { return freeze ( { ... selectNode , having : selectNode . having ? HavingNode . cloneWithFilter ( selectNode . having , 'Or' , filter ) : HavingNode . create ( filter ) , } ) ; } , cloneWithDistinct ( selectNode ) { return freeze ( { ... selectNode , distinct : true , } ) ; } , cloneWithUnion ( selectNode , union ) { return freeze ( { ... selectNode , union : selectNode . union ? freeze ( [ ... selectNode . union , union ] ) : freeze ( [ union ] ) , } ) ; } , } ) ;