Comparing version 1.1.0 to 1.2.0
10
index.js
@@ -35,12 +35,10 @@ var crypto = require("crypto"); | ||
var beforeValues, afterValues; | ||
var outputId; | ||
if (typeof obj._meta.id == 'string') { | ||
beforeValues = obj._meta.db.driver.outputIdBeforeValues(obj._meta.id); | ||
afterValues = obj._meta.db.driver.outputIdAfterValues(obj._meta.id); | ||
outputId = obj._meta.db.driver.outputId(obj._meta.id); | ||
} else { | ||
beforeValues = ''; | ||
afterValues = ''; | ||
outputId = ''; | ||
} | ||
var statementString = 'insert into ' + obj._meta.table + ' (' + fields + ') ' + beforeValues + ' values (' + values + ') ' + afterValues; | ||
var statementString = 'insert into ' + obj._meta.table + ' (' + fields + ') values (' + values + ') ' + outputId; | ||
@@ -47,0 +45,0 @@ var params = _.pick(obj, keys); |
var promisify = require('./promisify'); | ||
var optionalRequire = require("./optionalRequire"); | ||
var debug = require('debug')('sworm:mssql'); | ||
@@ -18,2 +19,3 @@ module.exports = function() { | ||
return promisify(function(cb) { | ||
debug(query, params); | ||
return request.query(query, cb); | ||
@@ -35,8 +37,7 @@ }); | ||
}, | ||
outputIdBeforeValues: function(id) { | ||
return "output Inserted." + id; | ||
outputId: function(id) { | ||
return "; select scope_identity() as " + id; | ||
}, | ||
outputIdAfterValues: function(id) { | ||
return ""; | ||
}, | ||
insertedId: function(rows, id) { | ||
@@ -43,0 +44,0 @@ return rows[0][id]; |
var promisify = require('./promisify'); | ||
var optionalRequire = require("./optionalRequire"); | ||
var debug = require('debug')('sworm:mysql'); | ||
@@ -24,2 +25,3 @@ module.exports = function() { | ||
return promisify(function(cb) { | ||
debug(query, paramList); | ||
return self.connection.query(query, paramList, cb); | ||
@@ -44,7 +46,3 @@ }); | ||
outputIdBeforeValues: function(id) { | ||
return ""; | ||
}, | ||
outputIdAfterValues: function(id) { | ||
outputId: function(id) { | ||
return "; select last_insert_id() as id"; | ||
@@ -51,0 +49,0 @@ }, |
@@ -60,7 +60,3 @@ var optionalRequire = require('./optionalRequire'); | ||
outputIdBeforeValues: function (id) { | ||
return ""; | ||
}, | ||
outputIdAfterValues: function (id) { | ||
outputId: function (id) { | ||
return " returning " + id + " into :returning_into_id"; | ||
@@ -67,0 +63,0 @@ }, |
{ | ||
"name": "sworm", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "a lightweight write-only ORM for MSSQL, MySQL, PostgreSQL, Oracle, Sqlite 3", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var promisify = require('./promisify'); | ||
var optionalRequire = require("./optionalRequire"); | ||
var debug = require('debug')('sworm:pg'); | ||
@@ -38,2 +39,3 @@ module.exports = function() { | ||
return promisify(function(cb) { | ||
debug(query, paramList); | ||
return self.client.query(query, paramList, cb); | ||
@@ -64,8 +66,7 @@ }).then(function(result) { | ||
}, | ||
outputIdBeforeValues: function(id) { | ||
return ""; | ||
}, | ||
outputIdAfterValues: function(id) { | ||
outputId: function(id) { | ||
return "returning " + id; | ||
}, | ||
insertedId: function(rows, id) { | ||
@@ -72,0 +73,0 @@ return rows[0][id]; |
@@ -207,2 +207,20 @@ # SWORM | ||
### Debug | ||
This module uses [debug](https://www.npmjs.com/package/debug), so you can easily see what's happening under the hood by setting a `DEBUG` environment variable. | ||
```js | ||
DEBUG=sworm node myapp.js | ||
``` | ||
There are various schemes you can use: | ||
* `sworm` all queries | ||
* `sworm:results` all results | ||
* `sworm:mssql` exact query passed to mssql | ||
* `sworm:mysql` exact query passed to mysql | ||
* `sworm:pg` exact query passed to postgres | ||
* `sworm:oracle` exact query passed to oracle | ||
* `sworm:sqlite` exact query passed to sqlite3 | ||
## Models | ||
@@ -209,0 +227,0 @@ |
var promisify = require('./promisify'); | ||
var optionalRequire = require("./optionalRequire"); | ||
var debug = require('debug')('sworm:sqlite'); | ||
@@ -20,2 +21,3 @@ module.exports = function() { | ||
return new Promise(function (fulfil, reject) { | ||
debug(query, sqliteParams); | ||
self.connection.run(query, sqliteParams, function (error, result) { | ||
@@ -31,2 +33,3 @@ if (error) { | ||
return promisify(function (cb) { | ||
debug(query, sqliteParams); | ||
self.connection.all(query, sqliteParams, cb); | ||
@@ -56,10 +59,6 @@ }); | ||
outputIdBeforeValues: function(id) { | ||
outputId: function(id) { | ||
return ''; | ||
}, | ||
outputIdAfterValues: function(id) { | ||
return ''; | ||
}, | ||
insertedId: function(result, id) { | ||
@@ -66,0 +65,0 @@ return result.lastId; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58284
511
629