UNPKG

ts-hdb

Version:

hdb driver with typescript

186 lines (185 loc) 5.17 kB
/// <reference types="node" /> import { ResultSet } from "./ResultSet"; import { FunctionCode, NotEmptyArray } from "./types"; export declare class Statement<T = any, P extends Array<any> = Array<any>> { #private; /** * @private * @internal * @param statement */ constructor(statement: any); /** * get statement id */ get id(): Buffer; /** * get functionCode */ get functionCode(): FunctionCode; /** * execute statement directly, return result if applicable * * @param params * @returns */ exec(...params: P): Promise<any>; /** * direct execute write * * @param params each param item will contain an array, each item could be inserted to table * @returns affectedRows array * * * @example * ```ts * const affectedRows = await stat.write([1, "Theo"], [2, "People"], [3, "Jason"]); * expect(affectedRows).toStrictEqual([1, 1, 1]); * ``` * */ write<PA extends NotEmptyArray<P>>(...params: PA): Promise<{ [key in keyof PA]: number; }>; /** * direct execute write * * @param params * * @example * ```ts * const affectedRows = await stat.write([1, "Theo"]); * expect(affectedRows).toStrictEqual(1); * ``` */ write(...params: P): Promise<number>; /** * direct execute query * * @param params * @returns query result */ query(...params: P): Promise<Array<T>>; /** * call proc directly * * ref the [document](https://github.com/SAP/node-hdb#calling-stored-procedures) * * @param param * param map, * for example, * a proc have 3 `in` params: `A,B,C`, * the input param should have this format `{A:1,B:2,C:3}` * * @returns * out parameters array, * the plain type will be converted as map and stored in the first item * and other `table type` out parameters will be appended to the results array */ call(param: T): Promise<P>; /** * drop the prepared statement * * @returns */ drop(): Promise<void>; /** * query result set, in stream mode * * @param params * @returns result set * @throws {NotSupportedOperationError} */ streamQuery(...params: P): Promise<ResultSet<T>>; /** * query object stream * * @returns async object iterator * * @example * * ```ts * for await (const row of stat.streamQueryObject(1)) { * expect(row.ID).not.toBeUndefined(); * expect(row.NAME).not.toBeUndefined(); * } * ``` * */ streamQueryObject(...params: P): AsyncIterable<T>; /** * query object list stream * * @returns async object iterator * @example * * ```ts * for await (const rows of stat.streamQueryObject(1, 'string')) { * expect(rows[0].ID).not.toBeUndefined(); * expect(rows[0].NAME).not.toBeUndefined(); * } * ``` * */ streamQueryList(...params: P): AsyncIterable<Array<T>>; } type CommonMethod = "id" | "drop" | "functionCode"; type TransactionKeyword = "commit" | "rollback" | "lock table" | "set transaction" | "savepoint" | "release savepoint"; type CUDKeyword = "insert" | "update" | "upsert" | "delete"; type DMLKeyword = CUDKeyword | "load" | "unload" | "truncate"; export type DQLKeyword = "select"; type NoParamKeyword = "commit" | "rollback"; /** * @private * @internal */ type DDLKeyword = "create" | "drop" | "alter" | "comment" | "annotate" | "rename" | "refresh"; type DCLKeyword = "grant" | "deny" | "revoke" | "backup"; export type ProceduralStatement = `${"call" | "CALL"}${any}`; /** * transaction related statements */ export type TransactionStatement = `${TransactionKeyword | Uppercase<TransactionKeyword>}${any}`; /** * subset of Data Manipulation Language * * only contains INSERT/UPDATE/DELETE/ */ export type CUDStatement = `${CUDKeyword | Uppercase<CUDKeyword>}${any}`; /** * Data Manipulation Language */ export type DML = `${DMLKeyword | Uppercase<DMLKeyword>}${any}`; /** * Data Query Language */ export type DQL = `${DQLKeyword | Uppercase<DQLKeyword>}${any}`; /** * Data Definition Language */ export type DDL = `${DDLKeyword | Uppercase<DDLKeyword>}${any}`; /** * Data Control Language */ export type DCL = `${DCLKeyword | Uppercase<DCLKeyword>}${any}`; /** * no params statements */ export type NoParamMatcher = `${NoParamKeyword | Uppercase<NoParamKeyword>}${any}`; /** * execute procedure */ export type ProcedureStatement<T, P extends Array<any>> = Pick<Statement<T, P>, CommonMethod | "call">; /** * no param statement */ export type NoParamStatement = Pick<Statement<void, []>, CommonMethod | "exec">; /** * perform INSERT/UPDATE/DELETE */ export type DMLStatement<T, P extends Array<any>> = Pick<Statement<T, P>, CommonMethod | "write">; /** * perform SELECT query */ export type DQLStatement<T, P extends Array<any>> = Pick<Statement<T, P>, CommonMethod | "streamQuery" | "query" | "streamQueryList" | "streamQueryObject">; export {};