1616 stackSave
1717*/
1818
19+ "use strict" ;
20+
1921/**
2022 * @typedef {{Database:Database} } SqlJs
2123 * @property {Database } Database the database constructor
4850 */
4951// Wait for preRun to run, and then finish our initialization
5052Module [ "onRuntimeInitialized" ] = function onRuntimeInitialized ( ) {
51- "use strict" ;
52-
5353 // Declare toplevel variables
5454 // register, used for temporary stack values
5555 var apiTemp = stackAlloc ( 4 ) ;
@@ -166,10 +166,18 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
166166 ]
167167 ) ;
168168 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+ ) ;
170174 var sqlite3_value_text = cwrap ( "sqlite3_value_text" , "string" , [ "number" ] ) ;
171175 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+ ) ;
173181 var sqlite3_result_double = cwrap (
174182 "sqlite3_result_double" ,
175183 "" ,
@@ -190,7 +198,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
190198 "" ,
191199 [ "number" , "number" , "number" , "number" ]
192200 ) ;
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+ ) ;
194206 var sqlite3_result_error = cwrap (
195207 "sqlite3_result_error" ,
196208 "" ,
@@ -236,13 +248,16 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
236248 }
237249
238250 /** @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
240254 */
241255
242256 /** Bind values to the parameters, after having reseted the statement.
243257 * If values is null, do nothing and return true.
244258 *
245- * SQL statements can have parameters, named *'?', '?NNN', ':VVV', '@VVV', '$VVV'*,
259+ * SQL statements can have parameters,
260+ * named *'?', '?NNN', ':VVV', '@VVV', '$VVV'*,
246261 * where NNN is a number and VVV a string.
247262 * This function binds these parameters to the given values.
248263 *
@@ -282,7 +297,9 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
282297 }
283298 this [ "reset" ] ( ) ;
284299 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+ }
286303 return true ;
287304 } ;
288305
@@ -355,7 +372,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
355372 to the statement before it is executed
356373 @return {Database.SqlValue[] } One row of result
357374
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>
359377 var stmt = db.prepare("SELECT * FROM test");
360378 while (stmt.step()) console.log(stmt.get());
361379 */
@@ -392,7 +410,9 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
392410 /** Get the list of column names of a row of result of a statement.
393411 @return {string[] } The names of the columns
394412 @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+ );
396416 stmt.step(); // Execute the statement
397417 console.log(stmt.getColumnNames());
398418 // Will print ['nbr','data','null_value']
@@ -648,7 +668,10 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
648668
649669 @example
650670 // 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+ );
652675
653676 @return {Database } The database object (useful for method chaining)
654677 */
@@ -671,7 +694,10 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
671694 } ;
672695
673696 /**
674- * @typedef {{columns:string[], values:Database.SqlValue[][]} } Database.QueryExecResult
697+ * @typedef {{
698+ columns:string[],
699+ values:Database.SqlValue[][]
700+ }} Database.QueryExecResult
675701 * @property {string[] } columns the name of the columns of the result
676702 * (as returned by {@link Statement.getColumnNames})
677703 * @property {Database.SqlValue[][] } values one array per row, containing
@@ -798,7 +824,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
798824 @param {Statement.BindParams } [params=[]] Parameters to bind to the query
799825 @param {function(Object<string, Database.SqlValue>):void } callback
800826 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
802829
803830 @return {Database } The database object. Useful for method chaining
804831
@@ -874,8 +901,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
874901 * The memory associated to the database and all associated statements
875902 * will be freed.
876903 *
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.
879906 *
880907 * Databases **must** be closed when you're finished with them, or the
881908 * memory consumption will grow forever
@@ -908,8 +935,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
908935 throw new Error ( errmsg ) ;
909936 } ;
910937
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
913940 database. Executing any other type of SQL statement does not modify
914941 the value returned by this function.
915942
@@ -924,27 +951,36 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
924951 db.create_function("addOne", function (x) {return x+1;})
925952 db.exec("SELECT addOne(1)") // = 2
926953
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.
928956 @param {function } func the actual function to be executed.
929957 @return {Database } The database object. Useful for method chaining
930958 */
931- Database . prototype [ "create_function" ] = function create_function ( name , func ) {
959+ Database . prototype [ "create_function" ] = function create_function (
960+ name ,
961+ func
962+ ) {
932963 var func_ptr ;
933964 function wrapped_func ( cx , argc , argv ) {
934965 var result ;
935966 function extract_blob ( ptr ) {
936967 var size = sqlite3_value_bytes ( ptr ) ;
937968 var blob_ptr = sqlite3_value_blob ( ptr ) ;
938969 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+ }
940973 return blob_arg ;
941974 }
942975 var args = [ ] ;
943976 for ( var i = 0 ; i < argc ; i += 1 ) {
944977 var value_ptr = getValue ( argv + ( 4 * i ) , "i32" ) ;
945978 var value_type = sqlite3_value_type ( value_ptr ) ;
946979 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+ ) {
948984 arg = sqlite3_value_double ( value_ptr ) ;
949985 } else if ( value_type === SQLITE_TEXT ) {
950986 arg = sqlite3_value_text ( value_ptr ) ;
0 commit comments