Comparing version 0.1.1 to 0.1.2
@@ -11,5 +11,5 @@ /* | ||
var EventEmitter = require('events').EventEmitter; | ||
var Util = require('util'); | ||
var util = require('util'); | ||
var Structure = function (structure, params, parent, name) { | ||
var Structure = function Structure(structure, params, parent, name) { | ||
EventEmitter.call(this); | ||
@@ -36,7 +36,7 @@ | ||
Util.inherits(Structure, EventEmitter); | ||
util.inherits(Structure, EventEmitter); | ||
var p = Structure.prototype; | ||
p.init = function () { | ||
p.init = function init() { | ||
// Execute the source query for this part of the structure | ||
@@ -50,3 +50,3 @@ this.structure.source(this.params()) | ||
p.prepare = function () { | ||
p.prepare = function prepare() { | ||
this.rows = []; | ||
@@ -85,3 +85,3 @@ // This is the root, so we just place the result rows into an array | ||
// If it's the root query then we just stuff the result into the array from prepare() | ||
p.rootRow = function (row) { | ||
p.rootRow = function rootRow(row) { | ||
this.rows.push(row); | ||
@@ -91,3 +91,3 @@ }; | ||
// Child rows need to be added to all parent rows that have the appropriate key | ||
p.childRow = function (row) { | ||
p.childRow = function childRow(row) { | ||
var i, j; | ||
@@ -103,3 +103,3 @@ this.rows.push(row); | ||
// to fetch the corresponding child records | ||
p.params = function () { | ||
p.params = function params() { | ||
return this.parent ? { id: Object.keys(this.parentRows) } : this._params; | ||
@@ -109,3 +109,3 @@ }; | ||
// This particular part of the structure has completed | ||
p.end = function () { | ||
p.end = function end() { | ||
// Only if we have rows should we bother trying to fetch any child rows | ||
@@ -117,3 +117,3 @@ if (this.rows.length && this.structure.children) { | ||
new Structure(this.structure.children[name], this.params(), this, name) | ||
.on('done', this.childDone.bind(this)) | ||
.on('end', this.childEnd.bind(this)) | ||
.on('error', this.error.bind(this)) | ||
@@ -123,14 +123,14 @@ .init(); | ||
} else { | ||
this.emit('done', this.target); | ||
this.emit('end', this.rows); | ||
} | ||
}; | ||
p.error = function (err) { | ||
p.error = function error(err) { | ||
throw 'Structure error : ' + err + ' processing ' + Util.inspect(this.structure); | ||
}; | ||
p.childDone = function () { | ||
p.childEnd = function childDone() { | ||
this.pending--; | ||
if (!this.pending) { | ||
this.emit('done', this.rows); | ||
this.emit('end', this.rows); | ||
} | ||
@@ -137,0 +137,0 @@ }; |
{ | ||
"name": "structures", | ||
"description": "Create tree-like data structures from multiple SQL queries. Useful for rich API output.", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"homepage": "", | ||
@@ -32,2 +32,5 @@ "author": { | ||
"devDependencies": { | ||
"any-db": "~0", | ||
"db-query": "~0", | ||
"Faker": "~0", | ||
"grunt-contrib-jshint": "~0.1.1", | ||
@@ -34,0 +37,0 @@ "grunt-contrib-nodeunit": "~0.1.2", |
@@ -1,2 +0,2 @@ | ||
# structures [![Build Status](https://secure.travis-ci.org/markselby/node-structures.png?branch=master)](http://travis-ci.org/markselby/node-structures) | ||
# structures [![Build Status](https://secure.travis-ci.org/markselby/node-structures.png?branch=master)](http://travis-ci.org/markselby/node-structures) ![Dependencies Status](https://david-dm.org/markselby/node-structures.png) | ||
@@ -3,0 +3,0 @@ Create data structures from SQL queries, especially useful for building API's |
'use strict'; | ||
var structure = require('../lib/structure.js'); | ||
var Structure = require('../lib/structure.js'); | ||
var pg = require('db').pgPool; | ||
@@ -25,14 +26,17 @@ /* | ||
exports.awesome = { | ||
setUp: function (done) { | ||
// setup here | ||
done(); | ||
exports.cheese = { | ||
setUp: function (cb) { | ||
this.a = 10; | ||
cb(); | ||
}, | ||
'no args': function (test) { | ||
test.expect(1); | ||
// tests here | ||
console.log(structure); | ||
test.equal('test', 'test', 'should be placeholder test.'); | ||
tearDown: function (cb) { | ||
cb(); | ||
}, | ||
'gorgonzola': function (test) { | ||
test.expect(2); | ||
this.a++; | ||
test.equal(this.a, 11, 'should be placeholder test.'); | ||
test.ok(true, 'Ok test'); | ||
test.done(); | ||
} | ||
}; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10631
11
229
0
8