UNPKG

@tealbase/postgres-js

Version:
318 lines 11.2 kB
/// <reference types="node" /> import { URL } from 'url'; /** * Base builder */ export declare abstract class PostgrestBuilder<T> implements PromiseLike<any> { method: 'GET' | 'HEAD' | 'POST' | 'PATCH' | 'DELETE'; url: URL; headers: { [key: string]: string; }; schema?: string; body?: Partial<T> | Partial<T>[]; constructor(builder: PostgrestBuilder<T>); then(onfulfilled?: (value: any) => any, onrejected?: (value: any) => any): Promise<any>; } /** * CRUD */ export declare class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> { constructor(url: string, { headers, schema }?: { headers?: { [key: string]: string; }; schema?: string; }); /** * Performs horizontal filtering with SELECT. * * @param columns The columns to retrieve, separated by commas. */ select(columns?: string): PostgrestFilterBuilder<T>; /** * Performs an INSERT into the table. * * @param values The values to insert. * @param upsert If `true`, performs an UPSERT. */ insert(values: Partial<T> | Partial<T>[], { upsert }?: { upsert?: boolean | undefined; }): PostgrestBuilder<T>; /** * Performs an UPDATE on the table. * * @param values The values to update. */ update(values: Partial<T>): PostgrestFilterBuilder<T>; /** * Performs a DELETE on the table. */ delete(): PostgrestFilterBuilder<T>; } /** * Post-filters (transforms) */ declare class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> { /** * Orders the result with the specified `column`. * * @param column The column to order on. * @param ascending If `true`, the result will be in ascending order. * @param nullsFirst If `true`, `null`s appear first. * @param foreignTable The foreign table to use (if `column` is a foreign column). */ order(column: keyof T, { ascending, nullsFirst, foreignTable, }?: { ascending?: boolean; nullsFirst?: boolean; foreignTable?: string; }): PostgrestTransformBuilder<T>; /** * Limits the result with the specified `count`. * * @param count The maximum no. of rows to limit to. * @param foreignTable The foreign table to use (for foreign columns). */ limit(count: number, { foreignTable }?: { foreignTable?: string; }): PostgrestTransformBuilder<T>; /** * Limits the result to rows within the specified range, inclusive. * * @param from The starting index from which to limit the result, inclusive. * @param to The last index to which to limit the result, inclusive. * @param foreignTable The foreign table to use (for foreign columns). */ range(from: number, to: number, { foreignTable }?: { foreignTable?: string; }): PostgrestTransformBuilder<T>; /** * Retrieves only one row from the result. Result must be one row (e.g. using * `limit`), otherwise this will result in an error. */ single(): PostgrestTransformBuilder<T>; } declare type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'is' | 'in' | 'cs' | 'cd' | 'sl' | 'sr' | 'nxl' | 'nxr' | 'adj' | 'ov' | 'fts' | 'plfts' | 'phfts' | 'wfts'; declare class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> { /** * Finds all rows which doesn't satisfy the filter. * * @param column The column to filter on. * @param operator The operator to filter with. * @param value The value to filter with. */ not(column: keyof T, operator: FilterOperator, value: any): this; /** * Finds all rows satisfying at least one of the filters. * * @param filters The filters to use, separated by commas. */ or(filters: string): this; /** * Finds all rows whose value on the stated `column` exactly matches the * specified `value`. * * @param column The column to filter on. * @param value The value to filter with. */ eq(column: keyof T, value: T[keyof T]): this; /** * Finds all rows whose value on the stated `column` doesn't match the * specified `value`. * * @param column The column to filter on. * @param value The value to filter with. */ neq(column: keyof T, value: T[keyof T]): this; /** * Finds all rows whose value on the stated `column` is greater than the * specified `value`. * * @param column The column to filter on. * @param value The value to filter with. */ gt(column: keyof T, value: T[keyof T]): this; /** * Finds all rows whose value on the stated `column` is greater than or * equal to the specified `value`. * * @param column The column to filter on. * @param value The value to filter with. */ gte(column: keyof T, value: T[keyof T]): this; /** * Finds all rows whose value on the stated `column` is less than the * specified `value`. * * @param column The column to filter on. * @param value The value to filter with. */ lt(column: keyof T, value: T[keyof T]): this; /** * Finds all rows whose value on the stated `column` is less than or equal * to the specified `value`. * * @param column The column to filter on. * @param value The value to filter with. */ lte(column: keyof T, value: T[keyof T]): this; /** * Finds all rows whose value in the stated `column` matches the supplied * `pattern` (case sensitive). * * @param column The column to filter on. * @param pattern The pattern to filter with. */ like(column: keyof T, pattern: string): this; /** * Finds all rows whose value in the stated `column` matches the supplied * `pattern` (case insensitive). * * @param column The column to filter on. * @param pattern The pattern to filter with. */ ilike(column: keyof T, pattern: string): this; /** * A check for exact equality (null, true, false), finds all rows whose * value on the stated `column` exactly match the specified `value`. * * @param column The column to filter on. * @param value The value to filter with. */ is(column: keyof T, value: boolean | null): this; /** * Finds all rows whose value on the stated `column` is found on the * specified `values`. * * @param column The column to filter on. * @param values The values to filter with. */ in(column: keyof T, values: T[keyof T][]): this; /** * Finds all rows whose json, array, or range value on the stated `column` * contains the values specified in `value`. * * @param column The column to filter on. * @param value The value to filter with. */ cs(column: keyof T, value: string | T[keyof T][] | object): this; /** * Finds all rows whose json, array, or range value on the stated `column` is * contained by the specified `value`. * * @param column The column to filter on. * @param value The value to filter with. */ cd(column: keyof T, value: string | T[keyof T][] | object): this; /** * Finds all rows whose range value on the stated `column` is strictly to the * left of the specified `range`. * * @param column The column to filter on. * @param range The range to filter with. */ sl(column: keyof T, range: string): this; /** * Finds all rows whose range value on the stated `column` is strictly to * the right of the specified `range`. * * @param column The column to filter on. * @param range The range to filter with. */ sr(column: keyof T, range: string): this; /** * Finds all rows whose range value on the stated `column` does not extend * to the left of the specified `range`. * * @param column The column to filter on. * @param range The range to filter with. */ nxl(column: keyof T, range: string): this; /** * Finds all rows whose range value on the stated `column` does not extend * to the right of the specified `range`. * * @param column The column to filter on. * @param range The range to filter with. */ nxr(column: keyof T, range: string): this; /** * Finds all rows whose range value on the stated `column` is adjacent to * the specified `range`. * * @param column The column to filter on. * @param range The range to filter with. */ adj(column: keyof T, range: string): this; /** * Finds all rows whose array or range value on the stated `column` is * contained by the specified `value`. * * @param column The column to filter on. * @param value The value to filter with. */ ov(column: keyof T, value: string | T[keyof T][]): this; /** * Finds all rows whose tsvector value on the stated `column` matches * to_tsquery(`query`). * * @param column The column to filter on. * @param query The Postgres tsquery string to filter with. * @param config The text search configuration to use. */ fts(column: keyof T, query: string, { config }?: { config?: string; }): this; /** * Finds all rows whose tsvector value on the stated `column` matches * plainto_tsquery(`query`). * * @param column The column to filter on. * @param query The Postgres tsquery string to filter with. * @param config The text search configuration to use. */ plfts(column: keyof T, query: string, { config }?: { config?: string; }): this; /** * Finds all rows whose tsvector value on the stated `column` matches * phraseto_tsquery(`query`). * * @param column The column to filter on. * @param query The Postgres tsquery string to filter with. * @param config The text search configuration to use. */ phfts(column: keyof T, query: string, { config }?: { config?: string; }): this; /** * Finds all rows whose tsvector value on the stated `column` matches * websearch_to_tsquery(`query`). * * @param column The column to filter on. * @param query The Postgres tsquery string to filter with. * @param config The text search configuration to use. */ wfts(column: keyof T, query: string, { config }?: { config?: string; }): this; /** * Finds all rows whose `column` satisfies the filter. * * @param column The column to filter on. * @param operator The operator to filter with. * @param value The value to filter with. */ filter(column: keyof T, operator: FilterOperator, value: any): this; /** * Finds all rows whose columns match the specified `query` object. * * @param query The object to filter with, with column names as keys mapped * to their filter values. */ match(query: { [key: string]: string; }): this; } export {}; //# sourceMappingURL=builder.d.ts.map