Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sworm

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sworm - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

db.sql

83

index.js

@@ -18,3 +18,5 @@ (function() {

var sortedResults = [];
indexes.sort();
indexes.sort(function(a, b) {
return a - b;
});
for (n = 0; n < indexes.length; n++) {

@@ -52,2 +54,3 @@ if (areRanges) {

derive.prototype = p;
constructor.prototype.constructor = derive;
return derive;

@@ -59,3 +62,3 @@ };

var self = this;
var crypto, _, mssqlDriver, pgDriver, mysqlDriver, rowBase, option;
var crypto, _, mssqlDriver, pgDriver, mysqlDriver, oracleDriver, debugQuery, debugResults, rowBase, option;
crypto = require("crypto");

@@ -66,2 +69,5 @@ _ = require("underscore");

mysqlDriver = require("./mysqlDriver");
oracleDriver = require("./oracleDriver");
debugQuery = require("debug")("sworm");
debugResults = require("debug")("sworm:results");
rowBase = function() {

@@ -108,3 +114,3 @@ var fieldsForObject, foreignFieldsForObject, insert, update, foreignField, saveManyToOne, saveManyToOnes, saveOneToMany, saveOneToManys, hash;

insert = function(obj) {
var keys, fields, values, outputId, statementString, gen8_asyncResult, r, insertedId;
var keys, fields, values, outputId, statementString, params, gen8_asyncResult, r, insertedId;
return new Promise(function(gen9_onFulfilled) {

@@ -151,3 +157,9 @@ keys = fieldsForObject(obj);

statementString = "insert into " + obj._meta.table + "\n (" + fields + ")\n " + outputId.beforeValues() + "\n values (" + values + ")\n " + outputId.afterValues();
gen9_onFulfilled(Promise.resolve(obj._meta.db.query(statementString, _.pick(obj, keys))).then(function(gen8_asyncResult) {
params = _.pick(obj, keys);
if (obj._meta.db.driver.outputIdKeys && !obj._meta.compoundKey) {
params = _.extend(params, obj._meta.db.driver.outputIdKeys(obj._meta.idType));
}
gen9_onFulfilled(Promise.resolve(obj._meta.db.query(statementString, params, {
statement: true
})).then(function(gen8_asyncResult) {
r = gen8_asyncResult;

@@ -217,3 +229,5 @@ obj.setSaved();

statementString = "update " + obj._meta.table + " set " + assignments + " where " + whereClause;
gen9_onFulfilled(Promise.resolve(obj._meta.db.query(statementString, _.pick(obj, keys))).then(function(gen14_asyncResult) {
gen9_onFulfilled(Promise.resolve(obj._meta.db.query(statementString, _.pick(obj, keys), {
statement: true
})).then(function(gen14_asyncResult) {
gen14_asyncResult;

@@ -495,15 +509,39 @@ return obj.setNotChanged();

},
query: function(query, params) {
query: function(query, params, gen55_options) {
var self = this;
self.logQuery(query, params);
return self.driver.query(query, params);
var statement;
statement = gen55_options !== void 0 && Object.prototype.hasOwnProperty.call(gen55_options, "statement") && gen55_options.statement !== void 0 ? gen55_options.statement : false;
var gen56_asyncResult, results;
return new Promise(function(gen9_onFulfilled) {
gen9_onFulfilled(new Promise(function(gen9_onFulfilled) {
gen9_onFulfilled(Promise.resolve(self.driver.query(query, params, {
statement: statement
})).then(function(gen57_asyncResult) {
results = gen57_asyncResult;
self.logResults(query, params, results, statement);
return results;
}));
}).then(void 0, function(e) {
self.logError(query, params, e);
throw e;
}));
});
},
logQuery: function(query, params) {
logError: function(query, params, error) {
var self = this;
if (self.log) {
if (self.log instanceof Function) {
return self.log(query, params);
return debugQuery(query, params, error);
},
logResults: function(query, params, results, statement) {
var self = this;
if (self.log instanceof Function) {
return self.log(query, params, results, statement);
} else {
if (params) {
debugQuery(query, params);
} else {
return console.log(query, params);
debugQuery(query);
}
if (!statement && results) {
return debugResults(results);
}
}

@@ -513,9 +551,14 @@ },

var self = this;
var gen55_asyncResult;
var driver, gen58_asyncResult;
return new Promise(function(gen9_onFulfilled) {
self.driver = {
driver = {
mssql: mssqlDriver,
pg: pgDriver,
mysql: mysqlDriver
}[config.driver]();
mysql: mysqlDriver,
oracle: oracleDriver
}[config.driver];
if (!driver) {
throw new Error("no such driver: `" + config.driver + "'");
}
self.driver = driver();
gen9_onFulfilled(Promise.resolve(self.driver.connect(config)));

@@ -531,6 +574,6 @@ });

return function() {
var gen56_asyncResult;
var gen59_asyncResult;
return new Promise(function(gen9_onFulfilled) {
gen9_onFulfilled(Promise.resolve(db.connect(config)).then(function(gen56_asyncResult) {
gen56_asyncResult;
gen9_onFulfilled(Promise.resolve(db.connect(config)).then(function(gen59_asyncResult) {
gen59_asyncResult;
return db;

@@ -537,0 +580,0 @@ }));

{
"name": "sworm",
"version": "0.4.0",
"version": "0.5.0",
"description": "a lightweight write-only ORM for MSSQL, MySQL, PostgreSQL",

@@ -10,13 +10,13 @@ "main": "index.js",

"dependencies": {
"bluebird": "^2.2.2",
"underscore": "^1.6.0"
"bluebird": "2.9.12",
"underscore": "1.8.1"
},
"devDependencies": {
"chai": "^1.9.1",
"chai-as-promised": "^4.1.1",
"mocha": "^1.21.4",
"pogo": "^0.9.4",
"mssql": "^1.1.1",
"mysql": "^2.4.2",
"pg": "^3.4.1"
"chai": "2.0.0",
"chai-as-promised": "4.2.0",
"mocha": "2.3.4",
"mssql": "2.1.0",
"mysql": "2.5.4",
"pg": "4.2.0",
"pogo": "0.9.10"
},

@@ -23,0 +23,0 @@ "scripts": {

@@ -8,2 +8,3 @@ # SWORM

* MySQL
* Oracle DB

@@ -19,2 +20,3 @@ ## NPM

npm install mysql
npm install oracledb

@@ -391,3 +393,4 @@ See [sworm](https://www.npmjs.org/package/sworm) in NPM.

```JavaScript
var records = db.query(sql, [parameters]);
db.query(sql, [parameters]).then(function (records) {
});
```

@@ -402,2 +405,20 @@

```js
db.query('select * from people where name = @name', {name: 'Bob'}).then(function (results) {
console.log(results);
/*
[
{id: 2, name: 'Bob'}
]
*/
});
```
## Stored Procedure Example
```JavaScript
db.query('myProcName @param1, @param2', {param1: 'a', param2: 'b'});
```
## Model Queries

@@ -404,0 +425,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc