import type { EntityQueryContext } from '@expo/entity'; import { EntityDatabaseAdapter } from '@expo/entity'; import type { Knex } from 'knex'; import type { SQLFragment } from './SQLOperator.ts'; /** * Equality operand that is used for selecting entities with a field with a single value. */ export interface SingleValueFieldEqualityCondition, N extends keyof TFields = keyof TFields> { fieldName: N; fieldValue: TFields[N]; } /** * Equality operand that is used for selecting entities with a field matching one of multiple values. */ export interface MultiValueFieldEqualityCondition, N extends keyof TFields = keyof TFields> { fieldName: N; fieldValues: readonly TFields[N][]; } /** * A single equality operand for use in a selection clause. * See EntityLoader.loadManyByFieldEqualityConjunctionAsync documentation for examples. */ export type FieldEqualityCondition, N extends keyof TFields = keyof TFields> = SingleValueFieldEqualityCondition | MultiValueFieldEqualityCondition; export declare function isSingleValueFieldEqualityCondition, N extends keyof TFields = keyof TFields>(condition: FieldEqualityCondition): condition is SingleValueFieldEqualityCondition; export interface TableFieldSingleValueEqualityCondition { tableField: string; tableValue: any; } export interface TableFieldMultiValueEqualityCondition { tableField: string; tableValues: readonly any[]; } export declare enum NullsOrdering { FIRST = "first", LAST = "last" } /** * Ordering options for `orderBy` clauses. */ export declare enum OrderByOrdering { /** * Ascending order (lowest to highest). * Ascending order puts smaller values first, where "smaller" is defined in terms of the %3C operator. */ ASCENDING = "asc", /** * Descending order (highest to lowest). * Descending order puts larger values first, where "larger" is defined in terms of the %3E operator. */ DESCENDING = "desc" } export type PostgresOrderByClause> = { /** * The field name to order by. */ fieldName: keyof TFields; /** * The OrderByOrdering to order by. */ order: OrderByOrdering; /** * Optional nulls ordering. If not provided, the database default is used * (NULLS LAST for ASC, NULLS FIRST for DESC in PostgreSQL). */ nulls?: NullsOrdering | undefined; } | { /** * A raw SQL fragment to order by. May not contain ASC or DESC, as ordering direction is determined by the `order` property. */ fieldFragment: SQLFragment; /** * The OrderByOrdering to order by. */ order: OrderByOrdering; /** * Optional nulls ordering. If not provided, the database default is used * (NULLS LAST for ASC, NULLS FIRST for DESC in PostgreSQL). */ nulls?: NullsOrdering | undefined; }; /** * SQL modifiers that only affect the selection but not the projection. */ export interface PostgresQuerySelectionModifiers> { /** * Order the entities by specified columns and orders. */ orderBy?: readonly PostgresOrderByClause[]; /** * Skip the specified number of entities queried before returning. */ offset?: number; /** * Limit the number of entities returned. */ limit?: number; } export type TableOrderByClause> = { columnName: string; order: OrderByOrdering; nulls: NullsOrdering | undefined; } | { columnFragment: SQLFragment; order: OrderByOrdering; nulls: NullsOrdering | undefined; }; export interface TableQuerySelectionModifiers> { orderBy: TableOrderByClause[] | undefined; offset: number | undefined; limit: number | undefined; } export declare abstract class BasePostgresEntityDatabaseAdapter, TIDField extends keyof TFields> extends EntityDatabaseAdapter { /** * Get the maximum page size for pagination. * @returns maximum page size if configured, undefined otherwise */ get paginationMaxPageSize(): number | undefined; /** * Fetch many objects matching the conjunction of where clauses constructed from * specified field equality operands. * * @param queryContext - query context with which to perform the fetch * @param fieldEqualityOperands - list of field equality where clause operand specifications * @param querySelectionModifiers - limit, offset, orderBy, and orderByRaw for the query * @returns array of objects matching the query */ fetchManyByFieldEqualityConjunctionAsync(queryContext: EntityQueryContext, fieldEqualityOperands: readonly FieldEqualityCondition[], querySelectionModifiers: PostgresQuerySelectionModifiers): Promise[]>; protected abstract fetchManyByFieldEqualityConjunctionInternalAsync(queryInterface: Knex, tableName: string, tableFieldSingleValueEqualityOperands: TableFieldSingleValueEqualityCondition[], tableFieldMultiValueEqualityOperands: TableFieldMultiValueEqualityCondition[], querySelectionModifiers: TableQuerySelectionModifiers): Promise; /** * Fetch many objects matching the SQL fragment. * * @param queryContext - query context with which to perform the fetch * @param sqlFragment - SQLFragment for the WHERE clause of the query * @param querySelectionModifiers - limit, offset, and orderByFragment for the query * @returns array of objects matching the query */ fetchManyBySQLFragmentAsync(queryContext: EntityQueryContext, sqlFragment: SQLFragment, querySelectionModifiers: PostgresQuerySelectionModifiers): Promise[]>; protected abstract fetchManyBySQLFragmentInternalAsync(queryInterface: Knex, tableName: string, sqlFragment: SQLFragment, querySelectionModifiers: TableQuerySelectionModifiers): Promise; /** * Count objects matching the conjunction of where clauses constructed from * specified field equality operands. * * @param queryContext - query context with which to perform the count * @param fieldEqualityOperands - list of field equality where clause operand specifications * @returns count of objects matching the query */ countByFieldEqualityConjunctionAsync(queryContext: EntityQueryContext, fieldEqualityOperands: readonly FieldEqualityCondition[]): Promise; protected abstract countByFieldEqualityConjunctionInternalAsync(queryInterface: Knex, tableName: string, tableFieldSingleValueEqualityOperands: TableFieldSingleValueEqualityCondition[], tableFieldMultiValueEqualityOperands: TableFieldMultiValueEqualityCondition[]): Promise; /** * Count objects matching the SQL fragment. * * @param queryContext - query context with which to perform the count * @param sqlFragment - SQLFragment for the WHERE clause of the query * @returns count of objects matching the query */ countBySQLFragmentAsync(queryContext: EntityQueryContext, sqlFragment: SQLFragment): Promise; protected abstract countBySQLFragmentInternalAsync(queryInterface: Knex, tableName: string, sqlFragment: SQLFragment): Promise; private convertToTableQueryModifiers; }