-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
index.d.ts
173 lines (149 loc) · 6.17 KB
/
index.d.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Type definitions for better-sqlite3 7.6
// Project: https://github.com/JoshuaWise/better-sqlite3
// Definitions by: Ben Davies <https://github.com/Morfent>
// Mathew Rumsey <https://github.com/matrumz>
// Santiago Aguilar <https://github.com/sant123>
// Alessandro Vergani <https://github.com/loghorn>
// Andrew Kaiser <https://github.com/andykais>
// Mark Stewart <https://github.com/mrkstwrt>
// Florian Stamer <https://github.com/stamerf>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.8
/// <reference types="node" />
type VariableArgFunction = (...params: any[]) => any;
type ArgumentTypes<F extends VariableArgFunction> = F extends (...args: infer A) => any ? A : never;
declare namespace BetterSqlite3 {
interface Statement<BindParameters extends any[]> {
database: Database;
source: string;
reader: boolean;
readonly: boolean;
busy: boolean;
run(...params: BindParameters): Database.RunResult;
get(...params: BindParameters): any;
all(...params: BindParameters): any[];
iterate(...params: BindParameters): IterableIterator<any>;
pluck(toggleState?: boolean): this;
expand(toggleState?: boolean): this;
raw(toggleState?: boolean): this;
bind(...params: BindParameters): this;
columns(): ColumnDefinition[];
safeIntegers(toggleState?: boolean): this;
}
interface ColumnDefinition {
name: string;
column: string | null;
table: string | null;
database: string | null;
type: string | null;
}
interface FTS5Tokenizer {
// The resulting array consists of the following triples:
// [..., segment_start_idx, segment_end_idx, segment | null, ...]
//
// `segment` could be `null` or `undefined` if no normalization was
// performed or if the string is unchanged after the normalization.
run(value: string): ReadonlyArray<number | string | undefined | null>;
}
interface FTS5TokenizerConstructor {
new (params: ReadonlyArray<string>): FTS5Tokenizer;
}
interface Transaction<F extends VariableArgFunction> {
(...params: ArgumentTypes<F>): ReturnType<F>;
default(...params: ArgumentTypes<F>): ReturnType<F>;
deferred(...params: ArgumentTypes<F>): ReturnType<F>;
immediate(...params: ArgumentTypes<F>): ReturnType<F>;
exclusive(...params: ArgumentTypes<F>): ReturnType<F>;
}
interface VirtualTableOptions {
rows: () => Generator;
columns: string[];
parameters?: string[] | undefined;
safeIntegers?: boolean | undefined;
directOnly?: boolean | undefined;
}
interface Database {
memory: boolean;
readonly: boolean;
name: string;
open: boolean;
inTransaction: boolean;
prepare<BindParameters extends any[] | {} = any[]>(
source: string,
): BindParameters extends any[] ? Statement<BindParameters> : Statement<[BindParameters]>;
transaction<F extends VariableArgFunction>(fn: F): Transaction<F>;
exec(source: string): this;
pragma(source: string, options?: Database.PragmaOptions): any;
function(name: string, cb: (...params: any[]) => any): this;
function(name: string, options: Database.RegistrationOptions, cb: (...params: any[]) => any): this;
aggregate(name: string, options: Database.AggregateOptions): this;
close(): this;
defaultSafeIntegers(toggleState?: boolean): this;
backup(destinationFile: string, options?: Database.BackupOptions): Promise<Database.BackupMetadata>;
table(name: string, options: VirtualTableOptions): this;
unsafeMode(unsafe?: boolean): this;
createFTS5Tokenizer(name: string, tokenizer: FTS5TokenizerConstructor): void;
signalTokenize(value: string): Array<string>;
}
interface DatabaseConstructor {
new (filename: string, options?: Database.Options): Database;
(filename: string, options?: Database.Options): Database;
prototype: Database;
SqliteError: typeof SqliteError;
setLogHandler(fn: (code: number, value: string) => void): void;
}
}
declare class SqliteError extends Error {
name: string;
message: string;
code: string;
constructor(message: string, code: string);
}
declare namespace Database {
interface RunResult {
changes: number;
lastInsertRowid: number | bigint;
}
interface Options {
readonly?: boolean | undefined;
fileMustExist?: boolean | undefined;
timeout?: number | undefined;
verbose?: ((message?: any, ...additionalArgs: any[]) => void) | undefined;
nativeBinding?: string | undefined;
}
interface SerializeOptions {
attached?: string;
}
interface PragmaOptions {
simple?: boolean | undefined;
}
interface RegistrationOptions {
varargs?: boolean | undefined;
deterministic?: boolean | undefined;
safeIntegers?: boolean | undefined;
directOnly?: boolean | undefined;
}
interface AggregateOptions extends RegistrationOptions {
start?: any;
step: (total: any, next: any) => any;
inverse?: ((total: any, dropped: any) => any) | undefined;
result?: ((total: any) => any) | undefined;
}
interface BackupMetadata {
totalPages: number;
remainingPages: number;
}
interface BackupOptions {
progress: (info: BackupMetadata) => number;
}
type SqliteError = typeof SqliteError;
type Statement<BindParameters extends any[] | {} = any[]> = BindParameters extends any[]
? BetterSqlite3.Statement<BindParameters>
: BetterSqlite3.Statement<[BindParameters]>;
type ColumnDefinition = BetterSqlite3.ColumnDefinition;
type Transaction<T extends VariableArgFunction = VariableArgFunction> = BetterSqlite3.Transaction<T>;
type FTS5Tokenizer = BetterSqlite3.FTS5Tokenizer;
type Database = BetterSqlite3.Database;
}
declare const Database: BetterSqlite3.DatabaseConstructor;
export = Database;