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

rdb

Package Overview
Dependencies
Maintainers
1
Versions
266
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rdb - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

examples/getById.js

6

package.json
{
"name": "rdb",
"version": "0.0.3",
"version": "0.0.4",
"main": "index.js",

@@ -10,5 +10,5 @@ "title": "rdb",

"a": "0.4.3",
"pg.js" : "*",
"pg.js" : "3.1.0",
"node-uuid" : "1.4.1",
"promise" : "*"
"promise" : "5.0.0"
},

@@ -15,0 +15,0 @@ "repository" : {

@@ -11,4 +11,4 @@ _rdb_

Based on promises.
API is not documented yet, but see [examples][0] at git@github.com:alfateam/rdb-demo.git.
API is not documented yet, but see [examples][0] at npmjs.org/package/rdb-demo.
[0]:https://github.com/alfateam/rdb-demo
[0]:https://npmjs.org/package/rdb-demo
var tryGetFromDbById = require('./tryGetFromDbById');
function get() {
var row = tryGetFromDbById.apply(null,arguments);
if (row === null)
throw("Row not found.")
return row;
return tryGetFromDbById.apply(null,arguments).then(onResult);
function onResult(row) {
if (row === null)
throw new Error("Row not found.")
return row;
}
}
module.exports = get;

@@ -1,2 +0,3 @@

var requireMock = require('a').requireMock;
var a = require('a');
var requireMock = a.requireMock;
var tryGetFromDbById = requireMock('./tryGetFromDbById');

@@ -9,2 +10,3 @@

function act(c) {
c.mock = a.mock;
c.tryGetFromDbById = tryGetFromDbById;

@@ -16,10 +18,8 @@ c.sut = require('../getFromDbById');

c.strategy = strategy;
c.resultPromise = {};
c.resultPromise.then = c.mock();
c.tryGetFromDbById.expect(c.table,c.id,c.strategy).return(c.resultPromise);
function get() {
try {
c.returned = c.sut(table,id,strategy);
}
catch(thrownMsg) {
c.thrownMsg = thrownMsg;
}
c.returnedPromise = c.sut(table,id,strategy);
}

@@ -26,0 +26,0 @@

@@ -5,6 +5,11 @@ var expected = {};

c.expected = expected;
c.tryGetFromDbById.expect(c.table,c.id,c.strategy).return(expected);
c.row = {};
c.resultPromise.then.expectAnything().whenCalled(onResult).return(c.expected);
function onResult(cb) {
c.returned = cb(c.row);
}
c.get();
}
act.base = '../../new';
module.exports = act;
var when = require('a').when;
var c = {};
when('./get',c)
.it('returns row').assertEqual(c.expected,c.returned);
when(c)
.it('returns row').assertEqual(c.row, c.returned)
.it('returns promise').assertEqual(c.expected,c.returnedPromise);

@@ -0,7 +1,20 @@

var expected = {};
function act(c) {
c.tryGetFromDbById.expect(c.table,c.id,c.strategy).return(null);
c.resultPromise.then.expectAnything().whenCalled(onResult);
function onResult(cb) {
try {
cb(null);
}
catch (e)
{
c.thrownMsg = e.message;
}
}
c.get();
}
act.base = '../../new';
module.exports = act;
var when = require('a').when;
var c = {};
when('./get',c)
when(c)
.it('throws not found').assertEqual('Row not found.',c.thrownMsg);
var Promise = require('promise');
var objectToCallback = require('./objectToCallback');
var commit = commitFirstTime;
var rollback = rollbackFirstTime;
var oldDone = Promise.prototype.done;
function commitFirstTime() {
commit = require('./commit');
return commit();
}
function rollbackFirstTime() {
rollback = require('./rollback')
return rollback();
}
function newPromise(func) {

@@ -18,0 +5,0 @@ if (!func)

var updateField = require('../updateField');
var newEmitEvent = require('../../emitEvent');
var extractStrategy = require('./toDto/extractStrategy');
var newToDto = require('./toDto/newToDto');
var newDto = require('../../newObject');

@@ -69,3 +72,12 @@ function shallowDbRowToRow(table, values) {

};
}
}
row.toJSON = function(strategy) {
var args = Array.prototype.slice.call(arguments, 0);
args.push(table);
strategy = extractStrategy.apply(null,args);
var dto = newDto();
var toDto = newToDto(strategy, table, dto);
return toDto(row).then(JSON.stringify);
};

@@ -72,0 +84,0 @@ return row;

@@ -8,3 +8,8 @@ var a = require('a');

function act(c){
c.updateField = requireMock('../updateField');
c.extractStrategy = requireMock('./toDto/extractStrategy');
c.newToDto = requireMock('./toDto/newToDto');
c.newObject = requireMock('../../newObject');
c.mock = mock;

@@ -11,0 +16,0 @@ c.table = {};

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