-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathSimple.ts
74 lines (72 loc) · 2.88 KB
/
Simple.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
70
71
72
73
74
import { AsyncDuckDB, AsyncDuckDBConnection } from "@duckdb/duckdb-wasm"
import { Connection, Database } from "duckdb"
export default class Simple {
/** A flag indicating whether debugging information should be logged. Defaults to false. @category Properties */
debug: boolean
/** The number of rows to log. Defaults to 10. @category Properties */
nbRowsToLog: number
/** The number of characters to log for text cells. By default, the whole text is logged. @category Properties */
nbCharactersToLog: number | undefined
/** A DuckDB database. @category Properties */
db!: AsyncDuckDB | Database
/** A connection to a DuckDB database. @category Properties */
connection!: AsyncDuckDBConnection | Connection
/** A worker to make DuckDB WASM work. @category Properties */
worker!: Worker | null
/** A flag for SimpleDB. Default is true. When data is retrieved from the database as an array of objects, BIGINT values are automatically converted to integers, which are easier to work with in JavaScript. If you want actual bigint values, set this option to false. @category Properties */
bigIntToInt: boolean | undefined
/** A number used when creating new tables. @category Properties */
tableIncrement: number
/** A flag to know if the name of the table has been attributed by default. @category Properties */
defaultTableName: boolean
/**
* For internal use only. If you want to run a SQL query, use the customQuery method. @category Properties
*/
runQuery!: (
query: string,
connection: AsyncDuckDBConnection | Connection,
returnDataFromQuery: boolean,
options: {
debug: boolean
method: string | null
parameters: { [key: string]: unknown } | null
bigIntToInt?: boolean
}
) => Promise<
| {
[key: string]: number | string | Date | boolean | null
}[]
| null
>
constructor(
runQuery: (
query: string,
connection: AsyncDuckDBConnection | Connection,
returnDataFromQuery: boolean,
options: {
debug: boolean
method: string | null
parameters: { [key: string]: unknown } | null
bigIntToInt?: boolean
}
) => Promise<
| {
[key: string]: number | string | Date | boolean | null
}[]
| null
>,
options: {
debug?: boolean
nbRowsToLog?: number
nbCharactersToLog?: number
} = {}
) {
this.nbRowsToLog = options.nbRowsToLog ?? 10
this.nbCharactersToLog = options.nbCharactersToLog
this.debug = options.debug ?? false
this.worker = null
this.tableIncrement = 1
this.defaultTableName = false
this.runQuery = runQuery
}
}