collimator
Advanced tools
Comparing version 2.0.0 to 2.1.0
24
api.md
@@ -5,2 +5,26 @@ | ||
## collimator(db) | ||
Inspect all enumerable table in a database, and return a promise that will | ||
resolve to information about each table. | ||
The resolved value will be an array of objects, each containing the | ||
following properties: | ||
- `name` - The name of the enumerated table | ||
- `primaryKeys` - An array of column names containing primary keys | ||
- `schema` - A JSON Schema v4 document that can be used to validated objects | ||
that are candidates for insertion into this table | ||
- `relationships` - Relationship information, determined by foreign key | ||
contraints. See `collimator.relationships` for further information on the | ||
structure of this data. | ||
### Params: | ||
* **Promise.\<Database>** *db* - The pg-promise connection | ||
### Return: | ||
* **Promise.\<Object>** A promise that will resolve to the information for each table | ||
<!-- End src/collimator.js --> | ||
@@ -7,0 +31,0 @@ |
@@ -5,2 +5,5 @@ # Change Log | ||
## 2.0.0 - 2015-09-10 | ||
* Fully inspect database by default when invoking `collimator` directly | ||
## 2.0.0 - 2015-09-09 | ||
@@ -7,0 +10,0 @@ * Aggregate primary keys into an array |
{ | ||
"name": "collimator", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Reflection & Introspection for PostgreSQL Databases", | ||
@@ -5,0 +5,0 @@ "main": "src/collimator.js", |
describe('collimator', function() { | ||
var collimator = require('../src/collimator'); | ||
var bluebird = require('bluebird'); | ||
@@ -9,2 +10,28 @@ it('exports inspectors', function() { | ||
}); | ||
it('describes the entire database when invoked directly', function(done) { | ||
var tables = bluebird.defer(); | ||
var schema = bluebird.defer(); | ||
var relationships = bluebird.defer(); | ||
spyOn(collimator, 'tables').and.returnValue(tables.promise); | ||
spyOn(collimator, 'schema').and.returnValue(schema.promise); | ||
spyOn(collimator, 'relationships').and.returnValue(relationships.promise); | ||
collimator('mockDb') | ||
.then(function(result) { | ||
expect(collimator.tables).toHaveBeenCalledWith('mockDb'); | ||
expect(collimator.schema).toHaveBeenCalledWith('mockDb', 'mockTable'); | ||
expect(collimator.relationships).toHaveBeenCalledWith('mockDb', 'mockTable'); | ||
expect(result).toEqual([ | ||
{ name: 'mockTable', schema: 'mockSchema', relationships: 'mockRelationships' } | ||
]); | ||
}) | ||
.then(done); | ||
tables.resolve([{name: 'mockTable'}]); | ||
schema.resolve('mockSchema'); | ||
relationships.resolve('mockRelationships'); | ||
}); | ||
}); |
'use strict'; | ||
module.exports = { | ||
tables: require('./inspectors/tables.js'), | ||
schema: require('./inspectors/schema.js'), | ||
relationships: require('./inspectors/relationships.js') | ||
}; | ||
var bluebird = require('bluebird'); | ||
var R = require('ramda'); | ||
/** | ||
* Inspect all enumerable table in a database, and return a promise that will | ||
* resolve to information about each table. | ||
* | ||
* The resolved value will be an array of objects, each containing the | ||
* following properties: | ||
* | ||
* - `name` - The name of the enumerated table | ||
* - `primaryKeys` - An array of column names containing primary keys | ||
* - `schema` - A JSON Schema v4 document that can be used to validated objects | ||
* that are candidates for insertion into this table | ||
* - `relationships` - Relationship information, determined by foreign key | ||
* contraints. See `collimator.relationships` for further information on the | ||
* structure of this data. | ||
* | ||
* @function collimator | ||
* @param {Promise.<Database>} db - The pg-promise connection | ||
* @returns {Promise.<Object>} A promise that will resolve to the information for each table | ||
*/ | ||
function collimator(db) { | ||
return collimator.tables(db) | ||
.map(function(table) { | ||
return bluebird.props(R.merge(table, { | ||
schema: collimator.schema(db, table.name), | ||
relationships: collimator.relationships(db, table.name) | ||
})); | ||
}); | ||
} | ||
collimator.tables = require('./inspectors/tables'); | ||
collimator.schema = require('./inspectors/schema'); | ||
collimator.relationships = require('./inspectors/relationships'); | ||
module.exports = collimator; |
28966
468