UNPKG

@vulcan-sql/core

Version:
66 lines (65 loc) 2.47 kB
/// <reference types="node" /> import { Parameterized, SQLClauseOperation } from '../../lib/data-query/index'; import { CacheLayerStoreFormatType, IncomingHttpHeaders, Profile } from '../index'; import { Readable } from 'stream'; import { ExtensionBase } from './base'; export interface ExportOptions { sql: string; directory: string; profileName: string; options?: any; type: CacheLayerStoreFormatType | string; } export interface ImportOptions { tableName: string; directory: string; profileName: string; schema: string; type: CacheLayerStoreFormatType | string; indexes?: Record<string, string>; } export interface RequestParameter { /** The index (starts from 1) of parameters, it's useful to generate parameter id like $1, $2 ...etc. */ parameterIndex: number; /** The raw value (not name) */ value: any; profileName: string; } export declare type BindParameters = Map<string, string>; export declare type DataColumn = { name: string; type: string; }; export interface DataResult { getColumns: () => DataColumn[]; getData: () => Readable; } export interface ExecuteOptions { statement: string; /** For core version >= 0.3.0, operations.limit and operation.offset must be handled */ operations: Partial<Parameterized<SQLClauseOperation>>; /** The parameter bindings, we guarantee the order of the keys in the map is the same as the order when they were used in queries. */ bindParams: BindParameters; profileName: string; headers?: IncomingHttpHeaders; } export declare type PrepareParameterFunc = { (param: RequestParameter): Promise<string>; }; export declare abstract class DataSource<C = any, PROFILE = Record<string, any>> extends ExtensionBase<C> { private profiles; constructor(config: C, moduleName: string, profiles?: Profile[]); abstract execute(options: ExecuteOptions): Promise<DataResult>; abstract prepare(param: RequestParameter): Promise<string>; /** * Export query result data to cache file for cache layer loader used */ export(options: ExportOptions): Promise<void>; /** * Import data to create table from cache file for cache layer loader used */ import(options: ImportOptions): Promise<void>; /** Get all the profiles which belong to this data source */ protected getProfiles(): Map<string, Profile<PROFILE>>; protected getProfile(name: string): Profile<PROFILE>; }