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