Skip to content

Commit 81174ca

Browse files
author
kai.zhu
committed
fix jslint warnings in src/api.js
1 parent 2ede981 commit 81174ca

File tree

1 file changed

+68
-27
lines changed

1 file changed

+68
-27
lines changed

src/api.js

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*jslint browser*/
1+
/*jslint browser this*/
22
/*global Module stackAlloc*/
33

44

@@ -195,7 +195,9 @@ This function binds these parameters to the given values.
195195
196196
## Binding values to named parameters
197197
@example Bind values to named parameters
198-
var stmt = db.prepare("UPDATE test SET a=@newval WHERE id BETWEEN $mini AND $maxi");
198+
var stmt = db.prepare(
199+
"UPDATE test SET a=@newval WHERE id BETWEEN $mini AND $maxi"
200+
);
199201
stmt.bind({$mini:10, $maxi:20, '@newval':5});
200202
- Create a statement that contains parameters like '$VVV', ':VVV', '@VVV'
201203
- Call Statement.bind with an object as parameter
@@ -293,7 +295,8 @@ Statement.prototype.getBlob = function(pos) {
293295

294296
/* Get one row of results of a statement.
295297
If the first parameter is not provided, step must have been called before get.
296-
@param [Array,Object] Optional: If set, the values will be bound to the statement, and it will be executed
298+
@param [Array,Object] Optional: If set, the values will be bound
299+
to the statement, and it will be executed
297300
@return [Array<String,Number,Uint8Array,null>] One row of result
298301
299302
@example Print all the rows of the table test to the console
@@ -339,7 +342,8 @@ Statement.prototype["get"] = function(params) {
339342
var x'616200' AS data;
340343
var NULL AS null_value;");
341344
stmt.step(); // Execute the statement
342-
console.log(stmt.getColumnNames()); // Will print ['nbr','data','null_value']
345+
console.log(stmt.getColumnNames());
346+
// Will print ['nbr','data','null_value']
343347
*/
344348
Statement.prototype["getColumnNames"] = function() {
345349
var i;
@@ -357,7 +361,8 @@ Statement.prototype["getColumnNames"] = function() {
357361

358362
/* Get one row of result as a javascript object, associating column names with
359363
their value in the current row.
360-
@param [Array,Object] Optional: If set, the values will be bound to the statement, and it will be executed
364+
@param [Array,Object] Optional: If set, the values will be bound
365+
to the statement, and it will be executed
361366
@return [Object] The row of result
362367
@see [Statement.get](#get-dynamic)
363368
@@ -367,7 +372,8 @@ their value in the current row.
367372
var x'616200' AS data;
368373
var NULL AS null_value;");
369374
stmt.step(); // Execute the statement
370-
console.log(stmt.getAsObject()); // Will print {nbr:5, data: Uint8Array([1,2,3]), null_value:null}
375+
console.log(stmt.getAsObject());
376+
// Will print {nbr:5, data: Uint8Array([1,2,3]), null_value:null}
371377
*/
372378
Statement.prototype["getAsObject"] = function(params) {
373379
var i;
@@ -390,7 +396,8 @@ Statement.prototype["getAsObject"] = function(params) {
390396
};
391397

392398
/* Shorthand for bind + step + reset
393-
Bind the values, execute the statement, ignoring the rows it returns, and resets it
399+
Bind the values, execute the statement, ignoring the rows it returns,
400+
and resets it
394401
@param [Array,Object] Value to bind to the statement
395402
*/
396403
Statement.prototype["run"] = function(values) {
@@ -456,7 +463,10 @@ Statement.prototype.bindValue = function(val, pos) {
456463
} else if (val.length != null) {
457464
return this.bindBlob(val, pos);
458465
} else {
459-
throw "Wrong API use : tried to bind a value of an unknown type (" + val + ").";
466+
throw (
467+
"Wrong API use : tried to bind a value of an unknown type ("
468+
+ val + ")."
469+
);
460470
}
461471
}
462472
};
@@ -496,11 +506,15 @@ Statement.prototype.bindFromArray = function(values) {
496506
};
497507

498508
/* Reset a statement, so that it's parameters can be bound to new values
499-
It also clears all previous bindings, freeing the memory used by bound parameters.
509+
It also clears all previous bindings, freeing the memory used
510+
by bound parameters.
500511
*/
501512
Statement.prototype["reset"] = function() {
502513
this.freemem();
503-
return sqlite3_clear_bindings(this.stmt) === SQLITE_OK && sqlite3_reset(this.stmt) === SQLITE_OK;
514+
return (
515+
sqlite3_clear_bindings(this.stmt) === SQLITE_OK
516+
&& sqlite3_reset(this.stmt) === SQLITE_OK
517+
);
504518
};
505519

506520
/* Free the memory allocated during parameter binding
@@ -540,13 +554,17 @@ Database = function (data) {
540554
/* Execute an SQL query, ignoring the rows it returns.
541555
542556
@param sql [String] a string containing some SQL text to execute
543-
@param params [Array] (*optional*) When the SQL statement contains placeholders, you can pass them in here. They will be bound to the statement before it is executed.
557+
@param params [Array] (*optional*) When the SQL statement contains placeholders,
558+
you can pass them in here. They will be bound to the statement
559+
before it is executed.
544560
545-
If you use the params argument, you **cannot** provide an sql string that contains several
546-
queries (separated by ';')
561+
If you use the params argument, you **cannot** provide an sql string
562+
that contains several queries (separated by ';')
547563
548564
@example Insert values in a table
549-
db.run("INSERT INTO test VALUES (:age, :name)", {':age':18, ':name':'John'});
565+
db.run(
566+
"INSERT INTO test VALUES (:age, :name)", {':age':18, ':name':'John'}
567+
);
550568
551569
@return [Database] The database object (useful for method chaining)
552570
*/
@@ -574,7 +592,8 @@ This is a wrapper against Database.prepare, Statement.step, Statement.get,
574592
and Statement.free.
575593
576594
The result is an array of result elements. There are as many result elements
577-
as the number of statements in your sql string (statements are separated by a semicolon)
595+
as the number of statements in your sql string (statements are separated
596+
by a semicolon)
578597
579598
Each result element is an object with two properties:
580599
'columns' : the name of the columns of the result (as returned by Statement.getColumnNames())
@@ -625,7 +644,13 @@ Database.prototype["exec"] = function(sql) {
625644
while (getValue(nextSqlPtr, "i8") !== NULL) {
626645
setValue(apiTemp, 0, "i32");
627646
setValue(pzTail, 0, "i32");
628-
this.handleError(sqlite3_prepare_v2_sqlptr(this.db, nextSqlPtr, -1, apiTemp, pzTail));
647+
this.handleError(sqlite3_prepare_v2_sqlptr(
648+
this.db,
649+
nextSqlPtr,
650+
-1,
651+
apiTemp,
652+
pzTail
653+
));
629654
pStmt = getValue(apiTemp, "i32");
630655
nextSqlPtr = getValue(pzTail, "i32");
631656
if (pStmt === NULL) {
@@ -656,15 +681,17 @@ Database.prototype["exec"] = function(sql) {
656681

657682
/* Execute an sql statement, and call a callback for each row of result.
658683
659-
**Currently** this method is synchronous, it will not return until the callback has
660-
been called on every row of the result. But this might change.
684+
**Currently** this method is synchronous, it will not return until the callback
685+
has been called on every row of the result. But this might change.
661686
662-
@param sql [String] A string of SQL text. Can contain placeholders that will be
663-
bound to the parameters given as the second argument
664-
@param params [Array<String,Number,null,Uint8Array>] (*optional*) Parameters to bind
665-
to the query
666-
@param callback [Function(Object)] A function that will be called on each row of result
667-
@param done [Function] A function that will be called when all rows have been retrieved
687+
@param sql [String] A string of SQL text. Can contain placeholders
688+
that will be bound to the parameters given as the second argument
689+
@param params [Array<String,Number,null,Uint8Array>] (*optional*) Parameters
690+
to bind to the query
691+
@param callback [Function(Object)] A function that will be called on each row
692+
of result
693+
@param done [Function] A function that will be called when all rows
694+
have been retrieved
668695
669696
@return [Database] The database object. Useful for method chaining
670697
@@ -695,7 +722,8 @@ Database.prototype["each"] = function(sql, params, callback, done) {
695722
};
696723

697724
/* Prepare an SQL statement
698-
@param sql [String] a string of SQL, that can contain placeholders ('?', ':VVV', ':AAA', '@AAA')
725+
@param sql [String] a string of SQL, that can contain placeholders
726+
('?', ':VVV', ':AAA', '@AAA')
699727
@param params [Array] (*optional*) values to bind to placeholders
700728
@return [Statement] the resulting statement
701729
@throw [String] SQLite error
@@ -872,7 +900,10 @@ Database.prototype["create_function"] = function(name, func) {
872900
sqlite3_result_blob(cx, blobptr, result.length, -1);
873901
_free(blobptr);
874902
} else {
875-
sqlite3_result_error(cx, "Wrong API use : tried to return a value of an unknown type (" + result + ").", -1);
903+
sqlite3_result_error(cx, (
904+
"Wrong API use : tried to return a value "
905+
+ "of an unknown type (" + result + ")."
906+
), -1);
876907
}
877908
break;
878909
default:
@@ -885,7 +916,17 @@ Database.prototype["create_function"] = function(name, func) {
885916
}
886917
func_ptr = addFunction(wrapped_func);
887918
this.functions[name] = func_ptr;
888-
this.handleError(sqlite3_create_function_v2(this.db, name, func.length, SQLITE_UTF8, 0, func_ptr, 0, 0, 0));
919+
this.handleError(sqlite3_create_function_v2(
920+
this.db,
921+
name,
922+
func.length,
923+
SQLITE_UTF8,
924+
0,
925+
func_ptr,
926+
0,
927+
0,
928+
0
929+
));
889930
return this;
890931
};
891932

0 commit comments

Comments
 (0)