Class

CouchDBStatement

CouchDBStatement(adapter)

Constructor

# new CouchDBStatement(adapter)

Provides a fluent interface for building CouchDB Mango queries with type safety

Statement builder for CouchDB Mango queries

Parameters:
Name Type Description
adapter

The CouchDB adapter

View Source query/Statement.ts, line 8

Example
// Example of using CouchDBStatement
const adapter = new MyCouchDBAdapter(scope);
const statement = new CouchDBStatement<User, User[]>(adapter);

// Build a query
const users = await statement
  .from(User)
  .where(Condition.attribute<User>('age').gt(18))
  .orderBy('lastName', 'asc')
  .limit(10)
  .execute();

Methods

# protected build() → {MangoQuery}

Converts the statement's conditions, selectors, and options into a CouchDB Mango query

Builds a CouchDB Mango query from the statement

sequenceDiagram participant Statement participant Repository participant parseCondition Statement->>Statement: build() Note over Statement: Initialize selectors Statement->>Repository: Get table name Repository-->>Statement: Return table name Statement->>Statement: Create base query alt Has selectSelector Statement->>Statement: Add fields to query end alt Has whereCondition Statement->>Statement: Create combined condition with table Statement->>parseCondition: Parse condition parseCondition-->>Statement: Return parsed condition alt Is group operator alt Is AND operator Statement->>Statement: Flatten nested AND conditions else Is OR operator Statement->>Statement: Combine with table condition else Statement->>Statement: Throw error end else Statement->>Statement: Merge conditions with existing selector end end alt Has orderBySelector Statement->>Statement: Add sort to query Statement->>Statement: Ensure field exists in selector end alt Has limitSelector Statement->>Statement: Set limit else Statement->>Statement: Use default limit end alt Has offsetSelector Statement->>Statement: Set skip end Statement-->>Statement: Return query

View Source query/Statement.ts, line 352

If there are invalid query conditions

Error

The built Mango query

MangoQuery

# async paginate(size) → {Promise.<Paginator.<M, R, MangoQuery>>}

Builds the query and returns a CouchDBPaginator for paginated results

Creates a paginator for the statement

Parameters:
Name Type Description
size number

The page size

View Source query/Statement.ts, line 363

If there's an error building the query

InternalError

A promise that resolves to a paginator

Promise.<Paginator.<M, R, MangoQuery>>

# protected parseCondition(condition) → {MangoQuery}

Converts a Condition object into a CouchDB Mango query selector structure

Parses a condition into a CouchDB Mango query selector

sequenceDiagram participant Statement participant translateOperators participant merge Statement->>Statement: parseCondition(condition) Note over Statement: Extract condition parts alt Simple comparison operator Statement->>translateOperators: translateOperators(operator) translateOperators-->>Statement: Return CouchDB operator Statement->>Statement: Create selector with attribute and operator else NOT operator Statement->>Statement: parseCondition(attr1) Statement->>translateOperators: translateOperators(Operator.NOT) translateOperators-->>Statement: Return CouchDB NOT operator Statement->>Statement: Create negated selector else AND/OR operator Statement->>Statement: parseCondition(attr1) Statement->>Statement: parseCondition(comparison) Statement->>translateOperators: translateOperators(operator) translateOperators-->>Statement: Return CouchDB group operator Statement->>merge: merge(operator, op1, op2) merge-->>Statement: Return merged selector end Statement-->>Statement: Return query with selector
Parameters:
Name Type Description
condition Condition.<M>

The condition to parse

View Source query/Statement.ts, line 422

The Mango query with the parsed condition as its selector

MangoQuery

# protected processRecord(r, pkAttr, sequenceType) → {any}

Extracts the ID from a CouchDB document and reverts it to a model instance

Processes a record from CouchDB

Parameters:
Name Type Description
r any

The raw record from CouchDB

pkAttr

The primary key attribute of the model

sequenceType "Number" | "BigInt" | undefined

The type of the sequence

View Source query/Statement.ts, line 374

The processed record

any

# async raw(rawInput) → {Promise.<R>}

Sends a raw Mango query to CouchDB and processes the results

Executes a raw Mango query

Parameters:
Name Type Description
rawInput MangoQuery

The raw Mango query to execute

View Source query/Statement.ts, line 384

A promise that resolves to the query results

Promise.<R>