Skip to main content

LogicalOperator

Abstract base for And and Or — a group of conditions joined by and/or. Select/Update/Delete#where() and Join#on() build their implicit top-level group from this class (specifically an And). Extends Operator.

LogicalOperator cannot be instantiated directly; calling LogicalOperator() or new LogicalOperator() throws a TypeError ("LogicalOperator is abstract and cannot be instantiated"). Use And or Or.

Constructor

LogicalOperator(...expressions: any[]): LogicalOperator
new LogicalOperator(...expressions: any[]): LogicalOperator

Dual-callable (on a concrete subclass). expressions are forwarded to .add().

Properties

KeyTypeReadonlyDescription
_typeSerializationType.LOGICAL_EXPRESSIONYesDiscriminates this node during serialization.
_itemsSqlElement[]NoThe accumulated child expressions, in order.

Plus _operatorType inherited from Operator (OperatorType.and / OperatorType.or, set by the concrete subclass).

Methods

add()

add(...expressions: (LogicalOperator | any)[]): this

Appends items to _items. Falsy arguments are skipped. Each argument must be one of:

  • another LogicalOperator (nested And/Or),
  • a Raw fragment, a CompOperator instance (Eq, Gt, In, ...), or a Not instance,
  • a plain object — expanded using the same object-literal shorthand rules described in Operators and Conditions.

Anything else throws a TypeError ("Operator or Raw type required").

import { And, Eq } from '@sqb/builder';

And().add(Eq('id', 1), { name: 'John' });

_serialize()

_serialize(ctx: SerializeContext): string

Renders every item in _items, joined by _operatorType (' and ' / ' or '), through the active SerializeContext. You normally don't call this directly — it runs as part of the owning query's .generate().

See also