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 2.2.0 to 2.3.0

blah.db

20

index.js

@@ -30,4 +30,3 @@ var crypto = require("crypto");

function insert(obj) {
var keys = fieldsForObject(obj);
function insertStatement(obj, keys) {
var fields = keys.join(', ');

@@ -43,4 +42,17 @@ var values = keys.map(function (key) { return '@' + key; }).join(', ');

var statementString = 'insert into ' + obj._meta.table + ' (' + fields + ') values (' + values + ') ' + outputId;
if (!fields.length) {
if (obj._meta.db.driver.insertEmpty) {
return obj._meta.db.driver.insertEmpty(obj._meta.table, obj._meta.id) + ' ' + outputId;
} else {
return 'insert into ' + obj._meta.table + ' default values ' + outputId;
}
} else {
return 'insert into ' + obj._meta.table + ' (' + fields + ') values (' + values + ') ' + outputId;
}
}
function insert(obj) {
var keys = fieldsForObject(obj);
var statementString = insertStatement(obj, keys);
var params = _.pick(obj, keys);

@@ -111,3 +123,3 @@

if (!(value instanceof Array)) {
if (value && !(value instanceof Array)) {
return value.save().then(function () {

@@ -114,0 +126,0 @@ var foreignId =

8

mysqlDriver.js

@@ -45,7 +45,11 @@ var promisify = require('./promisify');

outputId: function(id) {
outputId: function() {
return "; select last_insert_id() as id";
},
insertedId: function(rows, id) {
insertEmpty: function(table) {
return 'insert into ' + table + ' () values ()';
},
insertedId: function(rows) {
return rows[1][0].id;

@@ -52,0 +56,0 @@ }

@@ -64,2 +64,6 @@ var optionalRequire = require('./optionalRequire');

insertEmpty: function(table, id) {
return 'insert into ' + table + ' (' + id + ') values (default)';
},
outputIdKeys: function (idType) {

@@ -71,3 +75,3 @@ return {

insertedId: function (rows, id) {
insertedId: function (rows) {
return rows.outBinds.returning_into_id[0];

@@ -78,4 +82,4 @@ }

function formatRows(results) {
var rows = results.rows;
function formatRows(resultSet) {
var rows = resultSet.rows;
if (!rows) {

@@ -85,3 +89,3 @@ return rows;

var fields = results.metaData.map(function (field) {
var fields = resultSet.metaData.map(function (field) {
if (/[a-z]/.test(field.name)) {

@@ -95,3 +99,2 @@ return field.name;

if (fields.length > 0) {
var results;
var length = rows.length;

@@ -98,0 +101,0 @@ var results = new Array(length);

{
"name": "sworm",
"version": "2.2.0",
"version": "2.3.0",
"description": "a lightweight write-only ORM for MSSQL, MySQL, PostgreSQL, Oracle, Sqlite 3",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -62,7 +62,7 @@ var promisify = require('./promisify');

outputId: function(id) {
outputId: function() {
return '';
},
insertedId: function(result, id) {
insertedId: function(result) {
return result.lastId;

@@ -69,0 +69,0 @@ }

@@ -36,3 +36,3 @@ module.exports = {

[weird_id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](50) NOT NULL,
[name] [nvarchar](50) NULL,
[address_weird_id] [int] NULL

@@ -109,3 +109,3 @@ )`

weird_id serial NOT NULL,
name varchar(50) NOT NULL,
name varchar(50) NULL,
address_weird_id int NULL

@@ -166,3 +166,3 @@ )`

weird_id serial NOT NULL,
name varchar(50) NOT NULL,
name varchar(50) NULL,
address_weird_id int NULL

@@ -259,3 +259,3 @@ )`

weird_id number primary key,
name varchar2(50) NOT NULL,
name varchar2(50) NULL,
address_weird_id int NULL

@@ -315,3 +315,3 @@ )`

weird_id integer primary key,
name varchar(50) NOT NULL,
name varchar(50) NULL,
address_weird_id integer NULL

@@ -318,0 +318,0 @@ )`

@@ -59,3 +59,3 @@ var debug = require("debug")("sworm");

driver: "sqlite",
config: { filename: __dirname + "/test.sql" }
config: { filename: __dirname + "/test.db" }
});

@@ -85,3 +85,3 @@ } else {

driver: "sqlite",
config: { filename: __dirname + "/test.sql" }
config: { filename: __dirname + "/test.db" }
});

@@ -186,2 +186,21 @@ }

it("can insert emtpy rows", function() {
var personWeirdId = db.model({
table: "people_weird_id",
id: "weird_id"
});
var p = personWeirdId({});
return p.save().then(function() {
expect(p.weird_id).to.exist;
return db.query("select * from people_weird_id").then(function(people) {
return expect(helpers.clean(people)).to.eql([{
weird_id: p.weird_id,
name: null,
address_weird_id: null
}]);
});
});
});
describe("concurrency", function() {

@@ -617,2 +636,28 @@ it("can insert multiple rows, maintaining correct IDs", function() {

it("can save a many to one relationship with function that returns undefined", function() {
var bobsAddress;
var bob = person({
name: "bob",
address: function () {
}
});
return bob.save().then(function() {
expect(statements).to.eql([ "insert" ]);
expect(bob.address).to.equal(bobsAddress);
return db.query("select * from addresses").then(function(addresses) {
expect(helpers.clean(addresses)).to.eql([]);
});
}).then(function () {
return db.query("select * from people").then(function(people) {
expect(helpers.clean(people)).to.eql([{
id: bob.id,
name: 'bob',
address_id: null
}]);
});
});
});
describe("custom foreign keys", function() {

@@ -619,0 +664,0 @@ it("can save a many to one relationship with a custom foreign key", function() {

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