Class

Statement

Statement(adapter)

Constructor

# new Statement(adapter)

Provides a foundation for building and executing database queries

This abstract class implements the query builder pattern for constructing database queries. It supports various query operations like select, from, where, orderBy, groupBy, limit, and offset. It also provides methods for executing queries and handling pagination.

Base class for database query statements

sequenceDiagram participant Client participant Statement participant Adapter participant Database Client->>Statement: select() Client->>Statement: from(Model) Client->>Statement: where(condition) Client->>Statement: orderBy([field, direction]) Client->>Statement: limit(value) Client->>Statement: execute() Statement->>Statement: build() Statement->>Adapter: raw(query) Adapter->>Database: execute query Database-->>Adapter: return results Adapter-->>Statement: return processed results Statement-->>Client: return final results
Parameters:
Name Type Description
adapter Adapter.<any, Q, any, any>

The database adapter to use for executing queries

View Source query/Statement.ts, line 20

Example
// Create a statement to query users
const statement = new SQLStatement(adapter);
const users = await statement
  .select()
  .from(User)
  .where(Condition.attribute("status").eq("active"))
  .orderBy(["createdAt", "DESC"])
  .limit(10)
  .execute();

// Use pagination
const paginator = await statement
  .select()
  .from(User)
  .paginate(20); // 20 users per page

Methods

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

Builds the query and wraps it in a RamPaginator to enable pagination of results. This allows retrieving large result sets in smaller chunks.

Creates a paginator for the query

Parameters:
Name Type Description
size number

The page size (number of results per page)

View Source query/Statement.ts, line 441

A promise that resolves to a paginator for the query

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