UNPKG

@tmlmobilidade/connectors

Version:

This package provides pre-made database connectors to streamline development and reduce boilerplate. By using these connectors, you can avoid re-implementing controller classes every time, ensuring consistency and saving development time.

71 lines (70 loc) 2.08 kB
import { QueryResult } from 'trino-client'; export interface TrinoOptions { catalog: string; host: string; password?: string; schema: string; user: string; } export interface QueryOptions { limit?: number; orderBy?: { direction: 'asc' | 'desc'; field: string; }; unique?: boolean; where?: Record<string, any>; } export declare class TrinoConnector { private catalog; private client; private schema; constructor(options: TrinoOptions); /** * Constructs an ORDER BY clause from the given options. */ buildOrderByClause(orderBy?: { direction: 'asc' | 'desc'; field: string; }): string; /** * Constructs a WHERE clause from the given filter object, escaping values to prevent SQL injection. */ buildWhereClause(where?: Record<string, any>): string; /** * Converts query result iterators to an array of objects using column headers. */ convertIteratorToObject(headers: string[], resultsIterator: AsyncIterator<QueryResult>): Promise<Record<string, any>[]>; /** * Counts the number of rows matching the conditions. */ count(table: string, options?: QueryOptions): Promise<number | undefined>; /** * Executes the SQL query and returns an AsyncIterator. */ executeQuery(sql: string): Promise<AsyncIterator<QueryResult>>; /** * Finds the first row matching the conditions. */ findFirst<T>(table: string, options: QueryOptions): Promise<null | T>; /** * Finds multiple rows matching the conditions. */ findMany<T>(table: string, options?: QueryOptions): Promise<T[]>; /** * Finds a single unique row based on the given conditions. */ findUnique<T>(table: string, options: QueryOptions): Promise<null | T>; /** * Generic method for fetching query results based on options. */ private fetchResults; /** * Utility method to format values for SQL. */ private formatValue; /** * Fetches column headers for the given table. */ private getColumnHeaders; }