-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
driver.interface.ts
69 lines (58 loc) · 2.14 KB
/
driver.interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* eslint-disable max-len */
export type GenericDataBaseType = string;
export interface TableColumn {
name: string;
type: GenericDataBaseType;
}
export type TableStructure = TableColumn[];
export interface DownloadTableMemoryData {
rows: Record<string, unknown>[];
}
export interface DownloadTableCSVData {
csvFile: string[];
}
export interface StreamTableData {
rowStream: NodeJS.ReadableStream;
/**
* Some drivers know types of response
*/
types?: TableStructure;
/**
* Optional function to release stream/cursor/connection
*/
release?: () => Promise<void>;
}
export type StreamTableDataWithTypes = StreamTableData & {
/**
* Some drivers know types of response
*/
types: TableStructure;
};
export type DownloadTableData = DownloadTableMemoryData | DownloadTableCSVData | StreamTableData;
export interface ExternalDriverCompatibilities {
csvImport?: true,
streamImport?: true,
}
export type StreamOptions = {
highWaterMark: number
};
export interface DownloadQueryResultsBase {
types: TableStructure
}
export type DownloadQueryResultsOptions = StreamOptions & ExternalDriverCompatibilities;
export type IndexesSQL = {
sql: [string, unknown[]];
}[];
export interface DriverInterface {
createSchemaIfNotExists(schemaName: string): Promise<any>;
uploadTableWithIndexes(table: string, columns: TableStructure, tableData: DownloadTableData, indexesSql: IndexesSQL): Promise<void>;
loadPreAggregationIntoTable: (preAggregationTableName: string, loadSql: string, params: any, options: any) => Promise<any>;
//
tableColumnTypes: (table: string) => Promise<TableStructure>;
// Download data from Query (for readOnly)
downloadQueryResults: (query: string, values: unknown[], options: DownloadQueryResultsOptions) => Promise<DownloadQueryResultsBase & (DownloadTableMemoryData | DownloadTableCSVData | StreamTableData)>;
// Download table
downloadTable: (table: string, options: ExternalDriverCompatibilities) => Promise<DownloadTableMemoryData | DownloadTableCSVData>;
// Some drivers can implement streaming from SQL
stream?: (table: string, values: unknown[], options: StreamOptions) => Promise<StreamTableData>;
}