-
-
Notifications
You must be signed in to change notification settings - Fork 801
/
sqlite3.js
48 lines (39 loc) · 1.55 KB
/
sqlite3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var sqlite3 = module.exports = exports = require('./sqlite3_bindings');
var sys = require("sys");
var Database = sqlite3.Database;
var Statement = sqlite3.Statement;
// Database#prepare(sql, [bind1, bind2, ...], [callback])
Database.prototype.prepare = function(sql) {
var callback, params = Array.prototype.slice.call(arguments, 1);
if (params.length && typeof params[params.length - 1] !== 'function') {
params.push(undefined);
}
if (params.length > 1) {
var statement = new Statement(this, sql);
return statement.bind.apply(statement, params);
} else {
return new Statement(this, sql, params.pop());
}
};
// Database#run(sql, [bind1, bind2, ...], [callback])
Database.prototype.run = function(sql) {
var statement = new Statement(this, sql);
statement.run.apply(statement, Array.prototype.slice.call(arguments, 1)).finalize();
return this;
}
// Database#get(sql, [bind1, bind2, ...], [callback])
Database.prototype.get = function(sql) {
var statement = new Statement(this, sql);
statement.get.apply(statement, Array.prototype.slice.call(arguments, 1)).finalize();
return this;
}
// Database#all(sql, [bind1, bind2, ...], [callback])
Database.prototype.all = function(sql) {
var statement = new Statement(this, sql);
statement.all.apply(statement, Array.prototype.slice.call(arguments, 1)).finalize();
return this;
}
Database.prototype.execute = function() {
console.warn('Database#execute() is deprecated. Use Database#all() instead.');
return this.all.apply(this, arguments);
};