1 |
|
2 |
|
3 |
|
4 | type VariableArgFunction = (...params: any[]) => unknown;
|
5 | type ArgumentTypes<F extends VariableArgFunction> = F extends (...args: infer A) => unknown ? A : never;
|
6 | type ElementOf<T> = T extends Array<infer E> ? E : T;
|
7 |
|
8 | declare namespace BetterSqlite3 {
|
9 | interface Statement<BindParameters extends unknown[]> {
|
10 | database: Database;
|
11 | source: string;
|
12 | reader: boolean;
|
13 | readonly: boolean;
|
14 | busy: boolean;
|
15 |
|
16 | run(...params: BindParameters): Database.RunResult;
|
17 | get(...params: BindParameters): unknown;
|
18 | all(...params: BindParameters): unknown[];
|
19 | iterate(...params: BindParameters): IterableIterator<unknown>;
|
20 | pluck(toggleState?: boolean): this;
|
21 | expand(toggleState?: boolean): this;
|
22 | raw(toggleState?: boolean): this;
|
23 | bind(...params: BindParameters): this;
|
24 | columns(): ColumnDefinition[];
|
25 | safeIntegers(toggleState?: boolean): this;
|
26 | }
|
27 |
|
28 | interface ColumnDefinition {
|
29 | name: string;
|
30 | column: string | null;
|
31 | table: string | null;
|
32 | database: string | null;
|
33 | type: string | null;
|
34 | }
|
35 |
|
36 | interface Transaction<F extends VariableArgFunction> {
|
37 | (...params: ArgumentTypes<F>): ReturnType<F>;
|
38 | default(...params: ArgumentTypes<F>): ReturnType<F>;
|
39 | deferred(...params: ArgumentTypes<F>): ReturnType<F>;
|
40 | immediate(...params: ArgumentTypes<F>): ReturnType<F>;
|
41 | exclusive(...params: ArgumentTypes<F>): ReturnType<F>;
|
42 | }
|
43 |
|
44 | interface VirtualTableOptions {
|
45 | rows: () => Generator;
|
46 | columns: string[];
|
47 | parameters?: string[] | undefined;
|
48 | safeIntegers?: boolean | undefined;
|
49 | directOnly?: boolean | undefined;
|
50 | }
|
51 |
|
52 | interface Database {
|
53 | memory: boolean;
|
54 | readonly: boolean;
|
55 | name: string;
|
56 | open: boolean;
|
57 | inTransaction: boolean;
|
58 |
|
59 | prepare<BindParameters extends unknown[] | {} = unknown[]>(
|
60 | source: string,
|
61 | ): BindParameters extends unknown[] ? Statement<BindParameters> : Statement<[BindParameters]>;
|
62 | transaction<F extends VariableArgFunction>(fn: F): Transaction<F>;
|
63 | exec(source: string): this;
|
64 | pragma(source: string, options?: Database.PragmaOptions): unknown;
|
65 | function(name: string, cb: (...params: unknown[]) => unknown): this;
|
66 | function(name: string, options: Database.RegistrationOptions, cb: (...params: unknown[]) => unknown): this;
|
67 | aggregate<T>(
|
68 | name: string,
|
69 | options: Database.RegistrationOptions & {
|
70 | start?: T | (() => T);
|
71 | // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
72 | step: (total: T, next: ElementOf<T>) => T | void;
|
73 | inverse?: ((total: T, dropped: T) => T) | undefined;
|
74 | result?: ((total: T) => unknown) | undefined;
|
75 | },
|
76 | ): this;
|
77 | loadExtension(path: string): this;
|
78 | close(): this;
|
79 | defaultSafeIntegers(toggleState?: boolean): this;
|
80 | backup(destinationFile: string, options?: Database.BackupOptions): Promise<Database.BackupMetadata>;
|
81 | table(name: string, options: VirtualTableOptions): this;
|
82 | unsafeMode(unsafe?: boolean): this;
|
83 | serialize(options?: Database.SerializeOptions): Buffer;
|
84 | }
|
85 |
|
86 | interface DatabaseConstructor {
|
87 | new(filename?: string | Buffer, options?: Database.Options): Database;
|
88 | (filename?: string, options?: Database.Options): Database;
|
89 | prototype: Database;
|
90 |
|
91 | SqliteError: typeof SqliteError;
|
92 | }
|
93 | }
|
94 |
|
95 | declare class SqliteError extends Error {
|
96 | name: string;
|
97 | message: string;
|
98 | code: string;
|
99 | constructor(message: string, code: string);
|
100 | }
|
101 |
|
102 | declare namespace Database {
|
103 | interface RunResult {
|
104 | changes: number;
|
105 | lastInsertRowid: number | bigint;
|
106 | }
|
107 |
|
108 | interface Options {
|
109 | readonly?: boolean | undefined;
|
110 | fileMustExist?: boolean | undefined;
|
111 | timeout?: number | undefined;
|
112 | verbose?: ((message?: unknown, ...additionalArgs: unknown[]) => void) | undefined;
|
113 | nativeBinding?: string | undefined;
|
114 | }
|
115 |
|
116 | interface SerializeOptions {
|
117 | attached?: string;
|
118 | }
|
119 |
|
120 | interface PragmaOptions {
|
121 | simple?: boolean | undefined;
|
122 | }
|
123 |
|
124 | interface RegistrationOptions {
|
125 | varargs?: boolean | undefined;
|
126 | deterministic?: boolean | undefined;
|
127 | safeIntegers?: boolean | undefined;
|
128 | directOnly?: boolean | undefined;
|
129 | }
|
130 |
|
131 | type AggregateOptions = Parameters<BetterSqlite3.Database["aggregate"]>[1];
|
132 |
|
133 | interface BackupMetadata {
|
134 | totalPages: number;
|
135 | remainingPages: number;
|
136 | }
|
137 | interface BackupOptions {
|
138 | progress: (info: BackupMetadata) => number;
|
139 | }
|
140 |
|
141 | type SqliteError = typeof SqliteError;
|
142 | type Statement<BindParameters extends unknown[] | {} = unknown[]> = BindParameters extends unknown[]
|
143 | ? BetterSqlite3.Statement<BindParameters>
|
144 | : BetterSqlite3.Statement<[BindParameters]>;
|
145 | type ColumnDefinition = BetterSqlite3.ColumnDefinition;
|
146 | type Transaction<T extends VariableArgFunction = VariableArgFunction> = BetterSqlite3.Transaction<T>;
|
147 | type Database = BetterSqlite3.Database;
|
148 | }
|
149 |
|
150 | declare const Database: BetterSqlite3.DatabaseConstructor;
|
151 | export = Database;
|