16
16
stackSave
17
17
*/
18
18
19
+ "use strict" ;
20
+
19
21
/**
20
22
* @typedef {{Database:Database} } SqlJs
21
23
* @property {Database } Database the database constructor
48
50
*/
49
51
// Wait for preRun to run, and then finish our initialization
50
52
Module [ "onRuntimeInitialized" ] = function onRuntimeInitialized ( ) {
51
- "use strict" ;
52
-
53
53
// Declare toplevel variables
54
54
// register, used for temporary stack values
55
55
var apiTemp = stackAlloc ( 4 ) ;
@@ -166,10 +166,18 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
166
166
]
167
167
) ;
168
168
var sqlite3_value_type = cwrap ( "sqlite3_value_type" , "number" , [ "number" ] ) ;
169
- var sqlite3_value_bytes = cwrap ( "sqlite3_value_bytes" , "number" , [ "number" ] ) ;
169
+ var sqlite3_value_bytes = cwrap (
170
+ "sqlite3_value_bytes" ,
171
+ "number" ,
172
+ [ "number" ]
173
+ ) ;
170
174
var sqlite3_value_text = cwrap ( "sqlite3_value_text" , "string" , [ "number" ] ) ;
171
175
var sqlite3_value_blob = cwrap ( "sqlite3_value_blob" , "number" , [ "number" ] ) ;
172
- var sqlite3_value_double = cwrap ( "sqlite3_value_double" , "number" , [ "number" ] ) ;
176
+ var sqlite3_value_double = cwrap (
177
+ "sqlite3_value_double" ,
178
+ "number" ,
179
+ [ "number" ]
180
+ ) ;
173
181
var sqlite3_result_double = cwrap (
174
182
"sqlite3_result_double" ,
175
183
"" ,
@@ -190,7 +198,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
190
198
"" ,
191
199
[ "number" , "number" , "number" , "number" ]
192
200
) ;
193
- var sqlite3_result_int = cwrap ( "sqlite3_result_int" , "" , [ "number" , "number" ] ) ;
201
+ var sqlite3_result_int = cwrap (
202
+ "sqlite3_result_int" ,
203
+ "" ,
204
+ [ "number" , "number" ]
205
+ ) ;
194
206
var sqlite3_result_error = cwrap (
195
207
"sqlite3_result_error" ,
196
208
"" ,
@@ -236,13 +248,16 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
236
248
}
237
249
238
250
/** @typedef {string|number|null|Uint8Array } Database.SqlValue */
239
- /** @typedef {Database.SqlValue[]|Object<string, Database.SqlValue>|null } Statement.BindParams
251
+ /** @typedef {
252
+ Database.SqlValue[]|Object<string, Database.SqlValue>|null
253
+ } Statement.BindParams
240
254
*/
241
255
242
256
/** Bind values to the parameters, after having reseted the statement.
243
257
* If values is null, do nothing and return true.
244
258
*
245
- * SQL statements can have parameters, named *'?', '?NNN', ':VVV', '@VVV', '$VVV'*,
259
+ * SQL statements can have parameters,
260
+ * named *'?', '?NNN', ':VVV', '@VVV', '$VVV'*,
246
261
* where NNN is a number and VVV a string.
247
262
* This function binds these parameters to the given values.
248
263
*
@@ -282,7 +297,9 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
282
297
}
283
298
this [ "reset" ] ( ) ;
284
299
if ( Array . isArray ( values ) ) return this . bindFromArray ( values ) ;
285
- if ( values != null && typeof values === "object" ) return this . bindFromObject ( values ) ;
300
+ if ( values != null && typeof values === "object" ) {
301
+ return this . bindFromObject ( values ) ;
302
+ }
286
303
return true ;
287
304
} ;
288
305
@@ -355,7 +372,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
355
372
to the statement before it is executed
356
373
@return {Database.SqlValue[] } One row of result
357
374
358
- @example <caption>Print all the rows of the table test to the console</caption>
375
+ @example
376
+ <caption>Print all the rows of the table test to the console</caption>
359
377
var stmt = db.prepare("SELECT * FROM test");
360
378
while (stmt.step()) console.log(stmt.get());
361
379
*/
@@ -392,7 +410,9 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
392
410
/** Get the list of column names of a row of result of a statement.
393
411
@return {string[] } The names of the columns
394
412
@example
395
- var stmt = db.prepare("SELECT 5 AS nbr, x'616200' AS data, NULL AS null_value;");
413
+ var stmt = db.prepare(
414
+ "SELECT 5 AS nbr, x'616200' AS data, NULL AS null_value;"
415
+ );
396
416
stmt.step(); // Execute the statement
397
417
console.log(stmt.getColumnNames());
398
418
// Will print ['nbr','data','null_value']
@@ -648,7 +668,10 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
648
668
649
669
@example
650
670
// Insert values in a table
651
- db.run("INSERT INTO test VALUES (:age, :name)", { ':age' : 18, ':name' : 'John' });
671
+ db.run(
672
+ "INSERT INTO test VALUES (:age, :name)",
673
+ { ':age' : 18, ':name' : 'John' }
674
+ );
652
675
653
676
@return {Database } The database object (useful for method chaining)
654
677
*/
@@ -671,7 +694,10 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
671
694
} ;
672
695
673
696
/**
674
- * @typedef {{columns:string[], values:Database.SqlValue[][]} } Database.QueryExecResult
697
+ * @typedef {{
698
+ columns:string[],
699
+ values:Database.SqlValue[][]
700
+ }} Database.QueryExecResult
675
701
* @property {string[] } columns the name of the columns of the result
676
702
* (as returned by {@link Statement.getColumnNames})
677
703
* @property {Database.SqlValue[][] } values one array per row, containing
@@ -798,7 +824,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
798
824
@param {Statement.BindParams } [params=[]] Parameters to bind to the query
799
825
@param {function(Object<string, Database.SqlValue>):void } callback
800
826
Function to call on each row of result
801
- @param {function():void } done A function that will be called when all rows have been retrieved
827
+ @param {function():void } done A function that will be called when
828
+ all rows have been retrieved
802
829
803
830
@return {Database } The database object. Useful for method chaining
804
831
@@ -874,8 +901,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
874
901
* The memory associated to the database and all associated statements
875
902
* will be freed.
876
903
*
877
- * **Warning**: A statement belonging to a database that has been closed cannot
878
- * be used anymore.
904
+ * **Warning**: A statement belonging to a database that has been closed
905
+ * cannot be used anymore.
879
906
*
880
907
* Databases **must** be closed when you're finished with them, or the
881
908
* memory consumption will grow forever
@@ -908,8 +935,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
908
935
throw new Error ( errmsg ) ;
909
936
} ;
910
937
911
- /** Returns the number of changed rows (modified, inserted or deleted) by the
912
- latest completed INSERT, UPDATE or DELETE statement on the
938
+ /** Returns the number of changed rows (modified, inserted or deleted)
939
+ by the latest completed INSERT, UPDATE or DELETE statement on the
913
940
database. Executing any other type of SQL statement does not modify
914
941
the value returned by this function.
915
942
@@ -924,27 +951,36 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
924
951
db.create_function("addOne", function (x) {return x+1;})
925
952
db.exec("SELECT addOne(1)") // = 2
926
953
927
- @param {string } name the name of the function as referenced in SQL statements.
954
+ @param {string } name the name of the function as referenced in
955
+ SQL statements.
928
956
@param {function } func the actual function to be executed.
929
957
@return {Database } The database object. Useful for method chaining
930
958
*/
931
- Database . prototype [ "create_function" ] = function create_function ( name , func ) {
959
+ Database . prototype [ "create_function" ] = function create_function (
960
+ name ,
961
+ func
962
+ ) {
932
963
var func_ptr ;
933
964
function wrapped_func ( cx , argc , argv ) {
934
965
var result ;
935
966
function extract_blob ( ptr ) {
936
967
var size = sqlite3_value_bytes ( ptr ) ;
937
968
var blob_ptr = sqlite3_value_blob ( ptr ) ;
938
969
var blob_arg = new Uint8Array ( size ) ;
939
- for ( var j = 0 ; j < size ; j += 1 ) blob_arg [ j ] = HEAP8 [ blob_ptr + j ] ;
970
+ for ( var j = 0 ; j < size ; j += 1 ) {
971
+ blob_arg [ j ] = HEAP8 [ blob_ptr + j ] ;
972
+ }
940
973
return blob_arg ;
941
974
}
942
975
var args = [ ] ;
943
976
for ( var i = 0 ; i < argc ; i += 1 ) {
944
977
var value_ptr = getValue ( argv + ( 4 * i ) , "i32" ) ;
945
978
var value_type = sqlite3_value_type ( value_ptr ) ;
946
979
var arg ;
947
- if ( value_type === SQLITE_INTEGER || value_type === SQLITE_FLOAT ) {
980
+ if (
981
+ value_type === SQLITE_INTEGER
982
+ || value_type === SQLITE_FLOAT
983
+ ) {
948
984
arg = sqlite3_value_double ( value_ptr ) ;
949
985
} else if ( value_type === SQLITE_TEXT ) {
950
986
arg = sqlite3_value_text ( value_ptr ) ;
0 commit comments