UNPKG

5.19 kBTypeScriptView Raw
1/// <reference types="node" />
2
3declare module 'sqlite3' {
4 // Type definitions for sqlite3 3.1
5 // Project: http://github.com/mapbox/node-sqlite3
6 // Definitions by: Nick Malaguti <https://github.com/nmalaguti>
7 // Sumant Manne <https://github.com/dpyro>
8 // Behind The Math <https://github.com/BehindTheMath>
9 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10
11 import events = require('events')
12
13 export const OPEN_READONLY: number
14 export const OPEN_READWRITE: number
15 export const OPEN_CREATE: number
16 export const OPEN_SHAREDCACHE: number
17 export const OPEN_PRIVATECACHE: number
18 export const OPEN_URI: number
19
20 export const cached: {
21 Database(
22 filename: string,
23 callback?: (this: Database, err: Error | null) => void
24 ): Database
25 Database(
26 filename: string,
27 mode?: number,
28 callback?: (this: Database, err: Error | null) => void
29 ): Database
30 }
31
32 export interface RunResult extends Statement {
33 lastID: number
34 changes: number
35 }
36
37 export class Statement {
38 bind (callback?: (err: Error | null) => void): this
39 bind (...params: any[]): this
40
41 reset (callback?: (err: null) => void): this
42
43 finalize (callback?: (err: Error) => void): Database
44
45 run (callback?: (err: Error | null) => void): this
46 run (
47 params: any,
48 callback?: (this: RunResult, err: Error | null) => void
49 ): this
50 run (...params: any[]): this
51
52 get (callback?: (err: Error | null, row?: any) => void): this
53 get (
54 params: any,
55 callback?: (this: RunResult, err: Error | null, row?: any) => void
56 ): this
57 get (...params: any[]): this
58
59 all (callback?: (err: Error | null, rows: any[]) => void): this
60 all (
61 params: any,
62 callback?: (this: RunResult, err: Error | null, rows: any[]) => void
63 ): this
64 all (...params: any[]): this
65
66 each (
67 callback?: (err: Error | null, row: any) => void,
68 complete?: (err: Error | null, count: number) => void
69 ): this
70 each (
71 params: any,
72 callback?: (this: RunResult, err: Error | null, row: any) => void,
73 complete?: (err: Error | null, count: number) => void
74 ): this
75 each (...params: any[]): this
76 }
77
78 export class Database extends events.EventEmitter {
79 constructor (filename: string, callback?: (err: Error | null) => void)
80 constructor (
81 filename: string,
82 mode?: number,
83 callback?: (err: Error | null) => void
84 )
85
86 close (callback?: (err: Error | null) => void): void
87
88 run (
89 sql: string,
90 callback?: (this: RunResult, err: Error | null) => void
91 ): this
92 run (
93 sql: string,
94 params: any,
95 callback?: (this: RunResult, err: Error | null) => void
96 ): this
97 run (sql: string, ...params: any[]): this
98
99 get (
100 sql: string,
101 callback?: (this: Statement, err: Error | null, row: any) => void
102 ): this
103 get (
104 sql: string,
105 params: any,
106 callback?: (this: Statement, err: Error | null, row: any) => void
107 ): this
108 get (sql: string, ...params: any[]): this
109
110 all (
111 sql: string,
112 callback?: (this: Statement, err: Error | null, rows: any[]) => void
113 ): this
114 all (
115 sql: string,
116 params: any,
117 callback?: (this: Statement, err: Error | null, rows: any[]) => void
118 ): this
119 all (sql: string, ...params: any[]): this
120
121 each (
122 sql: string,
123 callback?: (this: Statement, err: Error | null, row: any) => void,
124 complete?: (err: Error | null, count: number) => void
125 ): this
126 each (
127 sql: string,
128 params: any,
129 callback?: (this: Statement, err: Error | null, row: any) => void,
130 complete?: (err: Error | null, count: number) => void
131 ): this
132 each (sql: string, ...params: any[]): this
133
134 exec (
135 sql: string,
136 callback?: (this: Statement, err: Error | null) => void
137 ): this
138
139 prepare (
140 sql: string,
141 callback?: (this: Statement, err: Error | null) => void
142 ): Statement
143 prepare (
144 sql: string,
145 params: any,
146 callback?: (this: Statement, err: Error | null) => void
147 ): Statement
148 prepare (sql: string, ...params: any[]): Statement
149
150 serialize (callback?: () => void): void
151 parallelize (callback?: () => void): void
152
153 on (event: 'trace', listener: (sql: string) => void): this
154 on (event: 'profile', listener: (sql: string, time: number) => void): this
155 on (event: 'error', listener: (err: Error) => void): this
156 on (event: 'open' | 'close', listener: () => void): this
157 on (event: string, listener: (...args: any[]) => void): this
158
159 configure (option: 'busyTimeout', value: number): void
160 interrupt (): void
161
162 loadExtension (path: string, callback?: (err: Error | null) => void): void
163 }
164
165 export function verbose (): sqlite3
166
167 export interface sqlite3 {
168 OPEN_READONLY: number
169 OPEN_READWRITE: number
170 OPEN_CREATE: number
171 OPEN_SHAREDCACHE: number
172 OPEN_PRIVATECACHE: number
173 OPEN_URI: number
174 cached: typeof cached
175 RunResult: RunResult
176 Statement: typeof Statement
177 Database: typeof Database
178 verbose(): this
179 }
180}