1
- var path = require ( 'path' ) ;
2
- var sqlite3 = require ( './sqlite3-binding.js' ) ;
3
- var EventEmitter = require ( 'events' ) . EventEmitter ;
1
+ const path = require ( 'path' ) ;
2
+ const sqlite3 = require ( './sqlite3-binding.js' ) ;
3
+ const EventEmitter = require ( 'events' ) . EventEmitter ;
4
4
module . exports = exports = sqlite3 ;
5
5
6
6
function normalizeMethod ( fn ) {
7
7
return function ( sql ) {
8
- var errBack ;
9
- var args = Array . prototype . slice . call ( arguments , 1 ) ;
8
+ let errBack ;
9
+ const args = Array . prototype . slice . call ( arguments , 1 ) ;
10
+
10
11
if ( typeof args [ args . length - 1 ] === 'function' ) {
11
- var callback = args [ args . length - 1 ] ;
12
+ const callback = args [ args . length - 1 ] ;
12
13
errBack = function ( err ) {
13
14
if ( err ) {
14
15
callback ( err ) ;
15
16
}
16
17
} ;
17
18
}
18
- var statement = new Statement ( this , sql , errBack ) ;
19
+ const statement = new Statement ( this , sql , errBack ) ;
19
20
return fn . call ( this , statement , args ) ;
20
21
} ;
21
22
}
22
23
23
24
function inherits ( target , source ) {
24
- for ( var k in source . prototype )
25
+ for ( const k in source . prototype )
25
26
target . prototype [ k ] = source . prototype [ k ] ;
26
27
}
27
28
@@ -32,18 +33,18 @@ sqlite3.cached = {
32
33
return new Database ( file , a , b ) ;
33
34
}
34
35
35
- var db ;
36
+ let db ;
36
37
file = path . resolve ( file ) ;
37
- function cb ( ) { callback . call ( db , null ) ; }
38
38
39
39
if ( ! sqlite3 . cached . objects [ file ] ) {
40
40
db = sqlite3 . cached . objects [ file ] = new Database ( file , a , b ) ;
41
41
}
42
42
else {
43
43
// Make sure the callback is called.
44
44
db = sqlite3 . cached . objects [ file ] ;
45
- var callback = ( typeof a === 'number' ) ? b : a ;
45
+ const callback = ( typeof a === 'number' ) ? b : a ;
46
46
if ( typeof callback === 'function' ) {
47
+ function cb ( ) { callback . call ( db , null ) ; }
47
48
if ( db . open ) process . nextTick ( cb ) ;
48
49
else db . once ( 'open' , cb ) ;
49
50
}
@@ -55,9 +56,9 @@ sqlite3.cached = {
55
56
} ;
56
57
57
58
58
- var Database = sqlite3 . Database ;
59
- var Statement = sqlite3 . Statement ;
60
- var Backup = sqlite3 . Backup ;
59
+ const Database = sqlite3 . Database ;
60
+ const Statement = sqlite3 . Statement ;
61
+ const Backup = sqlite3 . Backup ;
61
62
62
63
inherits ( Database , EventEmitter ) ;
63
64
inherits ( Statement , EventEmitter ) ;
@@ -102,7 +103,7 @@ Database.prototype.map = normalizeMethod(function(statement, params) {
102
103
// Database#backup(filename, [callback])
103
104
// Database#backup(filename, destName, sourceName, filenameIsDest, [callback])
104
105
Database . prototype . backup = function ( ) {
105
- var backup ;
106
+ let backup ;
106
107
if ( arguments . length <= 2 ) {
107
108
// By default, we write the main database out to the main database of the named file.
108
109
// This is the most likely use of the backup api.
@@ -117,22 +118,23 @@ Database.prototype.backup = function() {
117
118
} ;
118
119
119
120
Statement . prototype . map = function ( ) {
120
- var params = Array . prototype . slice . call ( arguments ) ;
121
- var callback = params . pop ( ) ;
121
+ const params = Array . prototype . slice . call ( arguments ) ;
122
+ const callback = params . pop ( ) ;
122
123
params . push ( function ( err , rows ) {
123
124
if ( err ) return callback ( err ) ;
124
- var result = { } ;
125
+ const result = { } ;
125
126
if ( rows . length ) {
126
- var keys = Object . keys ( rows [ 0 ] ) , key = keys [ 0 ] ;
127
+ const keys = Object . keys ( rows [ 0 ] ) ;
128
+ const key = keys [ 0 ] ;
127
129
if ( keys . length > 2 ) {
128
130
// Value is an object
129
- for ( var i = 0 ; i < rows . length ; i ++ ) {
131
+ for ( let i = 0 ; i < rows . length ; i ++ ) {
130
132
result [ rows [ i ] [ key ] ] = rows [ i ] ;
131
133
}
132
134
} else {
133
- var value = keys [ 1 ] ;
135
+ const value = keys [ 1 ] ;
134
136
// Value is a plain value
135
- for ( i = 0 ; i < rows . length ; i ++ ) {
137
+ for ( let i = 0 ; i < rows . length ; i ++ ) {
136
138
result [ rows [ i ] [ key ] ] = rows [ i ] [ value ] ;
137
139
}
138
140
}
@@ -142,28 +144,28 @@ Statement.prototype.map = function() {
142
144
return this . all . apply ( this , params ) ;
143
145
} ;
144
146
145
- var isVerbose = false ;
147
+ let isVerbose = false ;
146
148
147
- var supportedEvents = [ 'trace' , 'profile' , 'insert' , 'update' , 'delete' ] ;
149
+ const supportedEvents = [ 'trace' , 'profile' , 'insert' , 'update' , 'delete' ] ;
148
150
149
151
Database . prototype . addListener = Database . prototype . on = function ( type ) {
150
- var val = EventEmitter . prototype . addListener . apply ( this , arguments ) ;
152
+ const val = EventEmitter . prototype . addListener . apply ( this , arguments ) ;
151
153
if ( supportedEvents . indexOf ( type ) >= 0 ) {
152
154
this . configure ( type , true ) ;
153
155
}
154
156
return val ;
155
157
} ;
156
158
157
159
Database . prototype . removeListener = function ( type ) {
158
- var val = EventEmitter . prototype . removeListener . apply ( this , arguments ) ;
160
+ const val = EventEmitter . prototype . removeListener . apply ( this , arguments ) ;
159
161
if ( supportedEvents . indexOf ( type ) >= 0 && ! this . _events [ type ] ) {
160
162
this . configure ( type , false ) ;
161
163
}
162
164
return val ;
163
165
} ;
164
166
165
167
Database . prototype . removeAllListeners = function ( type ) {
166
- var val = EventEmitter . prototype . removeAllListeners . apply ( this , arguments ) ;
168
+ const val = EventEmitter . prototype . removeAllListeners . apply ( this , arguments ) ;
167
169
if ( supportedEvents . indexOf ( type ) >= 0 ) {
168
170
this . configure ( type , false ) ;
169
171
}
@@ -173,7 +175,7 @@ Database.prototype.removeAllListeners = function(type) {
173
175
// Save the stack trace over EIO callbacks.
174
176
sqlite3 . verbose = function ( ) {
175
177
if ( ! isVerbose ) {
176
- var trace = require ( './trace' ) ;
178
+ const trace = require ( './trace' ) ;
177
179
[
178
180
'prepare' ,
179
181
'get' ,
0 commit comments