1 | import * as sqlite3 from 'sqlite3';
|
2 | import { ISqlite, IMigrate } from './interfaces';
|
3 | import { Statement } from './Statement';
|
4 | import MigrationParams = IMigrate.MigrationParams;
|
5 |
|
6 |
|
7 |
|
8 | export declare class Database<Driver extends sqlite3.Database = sqlite3.Database, Stmt extends sqlite3.Statement = sqlite3.Statement> {
|
9 | config: ISqlite.Config;
|
10 | db: Driver;
|
11 | constructor(config: ISqlite.Config);
|
12 | /**
|
13 | * Event handler when verbose mode is enabled.
|
14 | * @see https://github.com/mapbox/node-sqlite3/wiki/Debugging
|
15 | */
|
16 | on(event: string, listener: any): void;
|
17 | /**
|
18 | * Returns the underlying sqlite3 Database instance
|
19 | */
|
20 | getDatabaseInstance(): Driver;
|
21 | /**
|
22 | * Opens the database
|
23 | */
|
24 | open(): Promise<void>;
|
25 | /**
|
26 | * Closes the database.
|
27 | */
|
28 | close(): Promise<void>;
|
29 | /**
|
30 | * @see https://github.com/mapbox/node-sqlite3/wiki/API#databaseconfigureoption-value
|
31 | */
|
32 | configure(option: ISqlite.ConfigureOption, value: any): any;
|
33 | /**
|
34 | * Runs the SQL query with the specified parameters. It does not retrieve any result data.
|
35 | * The function returns the Database object for which it was called to allow for function chaining.
|
36 | *
|
37 | * @param {string} sql The SQL query to run.
|
38 | *
|
39 | * @param {any} [params, ...] When the SQL statement contains placeholders, you
|
40 | * can pass them in here. They will be bound to the statement before it is
|
41 | * executed. There are three ways of passing bind parameters: directly in
|
42 | * the function's arguments, as an array, and as an object for named
|
43 | * parameters. This automatically sanitizes inputs.
|
44 | *
|
45 | * @see https://github.com/mapbox/node-sqlite3/wiki/API#databaserunsql-param--callback
|
46 | */
|
47 | run(sql: ISqlite.SqlType, ...params: any[]): Promise<ISqlite.RunResult<Stmt>>;
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | get<T = any>(sql: ISqlite.SqlType, ...params: any[]): Promise<T | undefined>;
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | each<T = any>(sql: ISqlite.SqlType, callback: (err: any, row: T) => void): Promise<number>;
|
87 | each<T = any>(sql: ISqlite.SqlType, param1: any, callback: (err: any, row: T) => void): Promise<number>;
|
88 | each<T = any>(sql: ISqlite.SqlType, param1: any, param2: any, callback: (err: any, row: T) => void): Promise<number>;
|
89 | each<T = any>(sql: ISqlite.SqlType, param1: any, param2: any, param3: any, callback: (err: any, row: T) => void): Promise<number>;
|
90 | each<T = any>(sql: ISqlite.SqlType, ...params: any[]): Promise<number>;
|
91 | /**
|
92 | * Runs the SQL query with the specified parameters. The parameters are the same as the
|
93 | * Database#run function, with the following differences:
|
94 | *
|
95 | * If the result set is empty, it will be an empty array, otherwise it will
|
96 | * have an object for each result row which
|
97 | * in turn contains the values of that row, like the Database#get function.
|
98 | *
|
99 | * Note that it first retrieves all result rows and stores them in memory.
|
100 | * For queries that have potentially large result sets, use the Database#each
|
101 | * function to retrieve all rows or Database#prepare followed by multiple
|
102 | * Statement#get calls to retrieve a previously unknown amount of rows.
|
103 | *
|
104 | * @param {string} sql The SQL query to run.
|
105 | *
|
106 | * @param {any} [params, ...] When the SQL statement contains placeholders, you
|
107 | * can pass them in here. They will be bound to the statement before it is
|
108 | * executed. There are three ways of passing bind parameters: directly in
|
109 | * the function's arguments, as an array, and as an object for named
|
110 | * parameters. This automatically sanitizes inputs.
|
111 | *
|
112 | * @see https://github.com/mapbox/node-sqlite3/wiki/API#databaseallsql-param--callback
|
113 | */
|
114 | all<T = any[]>(sql: ISqlite.SqlType, ...params: any[]): Promise<T>;
|
115 | /**
|
116 | * Runs all SQL queries in the supplied string. No result rows are retrieved. If a query fails,
|
117 | * no subsequent statements will be executed (wrap it in a transaction if you want all
|
118 | * or none to be executed).
|
119 | *
|
120 | * Note: This function will only execute statements up to the first NULL byte.
|
121 | * Comments are not allowed and will lead to runtime errors.
|
122 | *
|
123 | * @param {string} sql The SQL query to run.
|
124 | * @see https://github.com/mapbox/node-sqlite3/wiki/API#databaseexecsql-callback
|
125 | */
|
126 | exec(sql: ISqlite.SqlType): Promise<void>;
|
127 | /**
|
128 | * Prepares the SQL statement and optionally binds the specified parameters.
|
129 | * When bind parameters are supplied, they are bound to the prepared statement.
|
130 | *
|
131 | * @param {string} sql The SQL query to run.
|
132 | * @param {any} [params, ...] When the SQL statement contains placeholders, you
|
133 | * can pass them in here. They will be bound to the statement before it is
|
134 | * executed. There are three ways of passing bind parameters: directly in
|
135 | * the function's arguments, as an array, and as an object for named
|
136 | * parameters. This automatically sanitizes inputs.
|
137 | * @returns Promise<Statement> Statement object
|
138 | */
|
139 | prepare(sql: ISqlite.SqlType, ...params: any[]): Promise<Statement<Stmt>>;
|
140 | /**
|
141 | * Loads a compiled SQLite extension into the database connection object.
|
142 | *
|
143 | * @param {string} path Filename of the extension to load
|
144 | */
|
145 | loadExtension(path: string): Promise<void>;
|
146 | /**
|
147 | * Performs a database migration.
|
148 | */
|
149 | migrate(config?: MigrationParams): Promise<void>;
|
150 | /**
|
151 | * The methods underneath requires creative work to implement. PRs / proposals accepted!
|
152 | */
|
153 | serialize(): void;
|
154 | parallelize(): void;
|
155 | }
|
156 |
|
\ | No newline at end of file |