UNPKG

@proddata/node-cratedb

Version:
93 lines (92 loc) 5.39 kB
import http from 'http'; import { Cursor } from './Cursor.js'; import { CrateDBConfig, CrateDBBaseResponse, CrateDBResponse, CrateDBBulkResponse, CrateDBRecord, OptimizeOptions, ColumnDefinition, TableOptions, QueryConfig } from './interfaces'; export declare class CrateDBClient { private cfg; private httpAgent; private protocol; private httpOptions; constructor(config?: {}); createCursor(sql: string): Cursor; streamQuery(sql: string, batchSize?: number): AsyncGenerator<CrateDBRecord, void, unknown>; execute(stmt: string, args?: unknown[], config?: QueryConfig): Promise<CrateDBResponse>; executeMany(stmt: string, bulk_args: unknown[][]): Promise<CrateDBBulkResponse>; /** * Inserts a single row into a specified table with optional primary key conflict resolution. * * If primaryKeys are provided, conflicts will be handled by updating the non-primary key * fields of the conflicting row. If no primaryKeys are provided, conflicting rows will be skipped. * * @param {string} tableName - The name of the table to insert the row into. * @param {Record<string, unknown>} obj - An object representing the row to insert. * @param {string[] | null} [primaryKeys=null] - Array of column names to use as primary keys for conflict resolution. * @returns {Promise<CrateDBResponse>} A promise resolving to the response from CrateDB. * @throws {Error} If the input parameters are invalid. */ insert(tableName: string, obj: Record<string, unknown>, primaryKeys?: string[] | null): Promise<CrateDBResponse>; /** * Inserts multiple rows into a table with optional primary key conflict resolution. * * If primaryKeys are provided, conflicts will be handled by updating the non-primary key * fields of conflicting rows. If no primaryKeys are provided, conflicting rows will be skipped. * The method automatically handles varying column sets across the input objects. * * @param {string} tableName - The name of the table to insert rows into. * @param {Record<string, unknown>[]} objectArray - Array of objects representing rows to insert. * @param {string[] | null} [primaryKeys=null] - Array of column names to use as primary keys for conflict resolution. * @returns {Promise<CrateDBBulkResponse>} A promise resolving to the bulk operation response from CrateDB. * @throws {Error} If the input parameters are invalid or if the operation fails. */ insertMany(tableName: string, objectArray: Record<string, unknown>[], primaryKeys?: string[] | null): Promise<CrateDBBulkResponse>; /** * Drops a table if it exists in CrateDB. * * Constructs and executes a `DROP TABLE IF EXISTS` SQL statement. * * @param {string} tableName - The name of the table to drop. * @returns {Promise<CrateDBResponse>} A promise resolving to the response from CrateDB. */ drop(tableName: string): Promise<CrateDBResponse>; createTable(tableName: string, schema: Record<string, ColumnDefinition>, options?: TableOptions): Promise<CrateDBResponse>; /** * Refreshes a given table by refreshing it in CrateDB. * * The `REFRESH TABLE` command makes recently committed changes available for querying * without waiting for automatic refresh intervals. * * @param {string} tableName - The name of the table to refresh. * @returns {Promise<CrateDBResponse>} A promise resolving to the response from CrateDB. */ refresh(tableName: string): Promise<CrateDBResponse>; /** * Optimizes a given table or specific partitions in CrateDB by merging table segments. * * The `OPTIMIZE TABLE` command reduces the number of segments in a table, improving * query performance and reducing storage overhead. It supports optimizing the entire table * or specific partitions and allows additional optimization parameters. * * @param {string} tableName - The name of the table to optimize. * @param {OptimizeOptions} [options] - Optional parameters for table optimization. * @param {Record<string, string | number>} [partitions] - Optional key-value pairs specifying partition columns and values. * @returns {Promise<CrateDBResponse>} A promise resolving to the response from CrateDB. */ optimize(tableName: string, options?: OptimizeOptions, partitions?: Record<string, string | number>): Promise<CrateDBResponse>; /** * Retrieves the primary key columns for a given table. * * Queries the information_schema to get the primary key columns * of the specified table in their defined order. * * @param {string} tableName - The name of the table to get primary keys for. * @returns {Promise<string[]>} A promise resolving to an array of primary key column names. * @throws {Error} If the table doesn't exist or if there's an error retrieving the information. */ getPrimaryKeys(tableName: string): Promise<string[]>; private _addDurations; _makeRequest(options: http.RequestOptions & { body?: string | Buffer; }): Promise<CrateDBBaseResponse>; protected _transformResponse(response: CrateDBBaseResponse, rowMode?: 'array' | 'object'): CrateDBBaseResponse; getConfig(): Readonly<CrateDBConfig>; getHttpOptions(): Readonly<http.RequestOptions>; }