Comparing version 0.6.16 to 0.6.17
@@ -1,5 +0,4 @@ | ||
var anyDB = require('any-db'); | ||
var sql = require('sql'); | ||
var url = require('url'); | ||
var grouper = require('./lib/grouper'); | ||
var EventEmitter = require('events').EventEmitter; | ||
@@ -10,2 +9,6 @@ var crypto = require('crypto'); | ||
var AnyDBPool = require('./lib/anydb-pool'); | ||
var grouper = require('./lib/grouper'); | ||
var savePoint = require('./lib/savepoint'); | ||
var queryMethods = [ | ||
@@ -26,16 +29,2 @@ 'select', 'from', 'insert', 'update', | ||
function wrapQuery(ctx) { | ||
if (ctx._wrapquery) return ctx; | ||
var res = ctx; | ||
res._wrapquery = true; | ||
if (typeof(res.queryAsync) !== 'function') { | ||
if (!res.queryAsync) | ||
if (res._mainpool || res._transaction) | ||
P.promisifyAll(Object.getPrototypeOf(res)); | ||
else | ||
P.promisifyAll(res); | ||
} | ||
return res; | ||
} | ||
module.exports = function (opt) { | ||
@@ -60,6 +49,5 @@ | ||
else { | ||
pool = anyDB.createPool(opt.url, opt.connections); | ||
pool = new AnyDBPool(opt.url, opt.connections); | ||
} | ||
pool._mainpool = true; | ||
pool = wrapQuery(pool); | ||
} | ||
@@ -189,4 +177,3 @@ | ||
db.close = function() { | ||
if (pool) | ||
pool.close.apply(pool, arguments); | ||
if (pool) pool.close.apply(pool, arguments); | ||
pool = null; | ||
@@ -275,26 +262,3 @@ }; | ||
function wrapTransaction(tx) { | ||
tx.savepoint = function() { | ||
var spname = crypto.randomBytes(6).toString('base64'); | ||
if (dialect == 'mysql') | ||
spname = '`' + spname + '`'; | ||
else | ||
spname = '"' + spname + '"'; | ||
tx.query('SAVEPOINT ' + spname); | ||
function restore(cb) { | ||
return tx.query('ROLLBACK TO SAVEPOINT ' + spname, cb); | ||
} | ||
function release(cb) { | ||
return tx.query('RELEASE SAVEPOINT ' + spname, cb); | ||
} | ||
return { | ||
__savepoint: true, | ||
rollback: restore, | ||
commit: release, | ||
restore: restore, | ||
release: release, | ||
query: function() { | ||
return tx.query.apply(tx, arguments); | ||
} | ||
}; | ||
}; | ||
tx.savepoint = savePoint(dialect); | ||
tx.__transaction = true; | ||
@@ -304,27 +268,7 @@ tx.logQueries = function(enabled) { | ||
} | ||
return wrapQuery(tx); | ||
return tx; | ||
} | ||
var oldpool; | ||
db.getPool = function() { return pool; }; | ||
db.test = { | ||
end: function() { | ||
if (pool.rollback) { | ||
pool.rollback(); | ||
pool = oldpool; | ||
} | ||
}, begin: function() { | ||
if (!pool) db.open(); | ||
if (!pool.rollback) { | ||
oldpool = pool; | ||
pool = db.begin(); | ||
pool.begin = pool.savepoint | ||
} | ||
} | ||
}; | ||
db.getPool = function() { | ||
return pool; | ||
}; | ||
return db; | ||
@@ -331,0 +275,0 @@ |
var url = require('url'); | ||
var path = require('path'); | ||
var sqlite = require('sqlite3'); | ||
var Promise = require('bluebird'); | ||
function SQLitePool(dbpath, conns) { | ||
@@ -69,4 +69,5 @@ if (!this instanceof SQLitePool) | ||
Promise.promisifyAll(SQLiteTransaction.prototype); | ||
Promise.promisifyAll(SQLitePool.prototype); | ||
module.exports = SQLitePool; |
{ | ||
"name": "anydb-sql", | ||
"version": "0.6.16", | ||
"version": "0.6.17", | ||
"description": "Minimal ORM for mysql, postgresql and sqlite with complete arbitrary SQL query support (based on brianc's query builder sql)", | ||
@@ -34,12 +34,13 @@ "main": "anydb-sql.js", | ||
"dependencies": { | ||
"bluebird": "~1.0.3", | ||
"any-db": "~1.0.3", | ||
"any-db-postgres": "~1.0.2", | ||
"any-db-mysql": "~1.0.1", | ||
"sql": "~0.34.0" | ||
"any-db": "^2.1.0", | ||
"any-db-mysql": "^2.1.2", | ||
"any-db-postgres": "^2.1.3", | ||
"any-db-transaction": "^2.2.1", | ||
"bluebird": "^2.3.5", | ||
"sql": "^0.40.0" | ||
}, | ||
"devDependencies": { | ||
"sqlite3": "~2.1.10", | ||
"tape": "~2.12.2" | ||
"blue-tape": "^0.1.7", | ||
"sqlite3": "~2.1.10" | ||
} | ||
} |
var util = require('util'); | ||
var grouper = require('../lib/grouper'); | ||
var t = require('tape'); | ||
var t = require('blue-tape'); | ||
@@ -5,0 +5,0 @@ |
@@ -1,2 +0,2 @@ | ||
var test = require('tape').test; | ||
var test = require('blue-tape').test; | ||
@@ -79,2 +79,3 @@ var anydbsql = require('../anydb-sql'); | ||
}).done(null, function(e) { | ||
console.error(e.stack) | ||
t.notOk(e, 'db.transaction should not throw'); | ||
@@ -81,0 +82,0 @@ t.end(); |
39837
14
983
6
+ Addedany-db-transaction@^2.2.1
+ Addedany-db@2.1.02.2.1(transitive)
+ Addedany-db-mysql@2.3.0(transitive)
+ Addedany-db-pool@2.0.12.2.0(transitive)
+ Addedany-db-postgres@2.3.0(transitive)
+ Addedany-db-transaction@2.3.0(transitive)
+ Addedbignumber.js@3.1.2(transitive)
+ Addedbluebird@2.11.0(transitive)
+ Addedbuffer-writer@2.0.0(transitive)
+ Addedinherits@2.0.1(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedmysql@2.13.0(transitive)
+ Addedonce@1.3.3(transitive)
+ Addedpacket-reader@1.0.0(transitive)
+ Addedpg@7.18.2(transitive)
+ Addedpg-connection-string@0.1.3(transitive)
+ Addedpg-packet-stream@1.1.0(transitive)
+ Addedpg-pool@2.0.10(transitive)
+ Addedpg-query-stream@0.2.0(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedsemver@4.3.2(transitive)
+ Addedsql@0.40.0(transitive)
+ Addedsqlstring@2.2.0(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedany-db@1.0.3(transitive)
- Removedany-db-mysql@1.0.1(transitive)
- Removedany-db-pool@1.0.3(transitive)
- Removedany-db-postgres@1.0.2(transitive)
- Removedany-db-transaction@0.0.1(transitive)
- Removedbignumber.js@9.0.0(transitive)
- Removedbluebird@1.0.8(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedmysql@2.18.1(transitive)
- Removedpg@8.13.3(transitive)
- Removedpg-cloudflare@1.1.1(transitive)
- Removedpg-connection-string@2.7.0(transitive)
- Removedpg-pool@3.7.1(transitive)
- Removedpg-protocol@1.7.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.7(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsql@0.34.0(transitive)
- Removedsqlstring@2.3.1(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updatedany-db@^2.1.0
Updatedany-db-mysql@^2.1.2
Updatedany-db-postgres@^2.1.3
Updatedbluebird@^2.3.5
Updatedsql@^0.40.0