Reformat code

This commit is contained in:
Raymond Feng 2014-02-12 16:57:06 -08:00
parent 59676592e0
commit e54aa56cee
11 changed files with 1888 additions and 1905 deletions

View File

@ -1,8 +1,14 @@
{
"content": [
{"title": "LoopBack MySQL Connector API", "depth": 2},
"content": [
{
"title": "LoopBack MySQL Connector API",
"depth": 2
},
"lib/mysql.js",
{"title": "MySQL Discovery API", "depth": 2},
{
"title": "MySQL Discovery API",
"depth": 2
},
"lib/discovery.js"
],
"codeSectionDepth": 3

View File

@ -17,7 +17,6 @@ function show(err, models) {
}
}
ds.discoverModelDefinitions({views: true, limit: 20}, show);
ds.discoverModelProperties('customer', show);
@ -29,7 +28,6 @@ ds.discoverForeignKeys('inventory', show);
ds.discoverExportedForeignKeys('location', show);
ds.discoverAndBuildModels('weapon', {owner: 'strongloop', visited: {}, associations: true}, function (err, models) {
for (var m in models) {

View File

@ -12,7 +12,7 @@ function mixinDiscovery(MySQL) {
limit = limit + ',' + options.limit;
}
}
if(!orderBy) {
if (!orderBy) {
sql += ' ORDER BY ' + orderBy;
}
return sql + limit;

View File

@ -1,11 +1,11 @@
var EnumFactory = function() {
if(arguments.length > 0){
var Enum = function Enum(arg){
if(typeof arg === 'number' && arg % 1 == 0) {
var EnumFactory = function () {
if (arguments.length > 0) {
var Enum = function Enum(arg) {
if (typeof arg === 'number' && arg % 1 == 0) {
return Enum._values[arg];
} else if(Enum[arg]){
} else if (Enum[arg]) {
return Enum[arg]
} else if (Enum._values.indexOf(arg) !== -1 ) {
} else if (Enum._values.indexOf(arg) !== -1) {
return arg;
} else if (arg === null) {
return null;
@ -15,7 +15,7 @@ var EnumFactory = function() {
};
var dxList = [];
dxList.push(''); // Want empty value to be at index 0 to match MySQL Enum values and MySQL non-strict behavior.
for(var arg in arguments){
for (var arg in arguments) {
arg = String(arguments[arg]);
Object.defineProperty(Enum, arg.toUpperCase(), {configurable: false, enumerable: true, value: arg, writable: false});
dxList.push(arg);
@ -31,8 +31,8 @@ var EnumFactory = function() {
function stringified(anEnum) {
var s = [];
for(var i in anEnum._values){
if(anEnum._values[i] != ''){
for (var i in anEnum._values) {
if (anEnum._values[i] != '') {
s.push("'" + anEnum._values[i] + "'");
}
}

View File

@ -31,7 +31,7 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
s.supportBigNumbers = (s.supportBigNumbers || false);
s.timezone = (s.timezone || 'local');
if(!isNaN(s.connectionLimit)) {
if (!isNaN(s.connectionLimit)) {
s.connectionLimit = 10;
}
@ -49,7 +49,7 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
};
// Don't configure the DB if the pool can be used for multiple DBs
if(!s.createDatabase) {
if (!s.createDatabase) {
options.database = s.database;
}
@ -74,7 +74,7 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
dataSource.EnumFactory = EnumFactory; // factory for Enums. Note that currently Enums can not be registered.
process.nextTick(function() {
process.nextTick(function () {
callback && callback();
});
};
@ -173,7 +173,6 @@ MySQL.prototype.query = function (sql, callback) {
});
};
/**
* Create the data model in MySQL
*
@ -1082,10 +1081,10 @@ function unsigned(p, dt) {
* Disconnect from MySQL
*/
MySQL.prototype.disconnect = function () {
if(this.debug) {
if (this.debug) {
console.log('disconnect');
}
if(this.client) {
if (this.client) {
this.client.end();
}
};

View File

@ -3,17 +3,16 @@ var assert = require('assert');
var db, DummyModel, odb;
describe('migrations', function() {
describe('migrations', function () {
before(function() {
before(function () {
require('./init.js');
odb = getDataSource({collation: 'utf8_general_ci', createDatabase: true});
db = odb;
});
it('should use utf8 charset', function(done) {
it('should use utf8 charset', function (done) {
var test_set = /utf8/;
var test_collo = /utf8_general_ci/;
@ -23,14 +22,14 @@ describe('migrations', function() {
});
it('should disconnect first db', function(done) {
db.client.end(function(){
it('should disconnect first db', function (done) {
db.client.end(function () {
odb = getSchema();
done()
});
});
it('should use latin1 charset', function(done) {
it('should use latin1 charset', function (done) {
var test_set = /latin1/;
var test_collo = /latin1_general_ci/;
@ -40,31 +39,29 @@ describe('migrations', function() {
});
it('should drop db and disconnect all', function(done) {
db.connector.query('DROP DATABASE IF EXISTS ' + db.settings.database, function(err) {
db.client.end(function(){
it('should drop db and disconnect all', function (done) {
db.connector.query('DROP DATABASE IF EXISTS ' + db.settings.database, function (err) {
db.client.end(function () {
done();
});
});
});
});
function charsetTest(test_set, test_collo, test_set_str, test_set_collo, done) {
function charsetTest(test_set, test_collo, test_set_str, test_set_collo, done){
query('DROP DATABASE IF EXISTS ' + odb.settings.database, function(err) {
query('DROP DATABASE IF EXISTS ' + odb.settings.database, function (err) {
assert.ok(!err);
odb.client.end(function(){
odb.client.end(function () {
db = getSchema({collation: test_set_collo, createDatabase: true});
DummyModel = db.define('DummyModel', {string: String});
db.automigrate(function(){
db.automigrate(function () {
var q = 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = ' + db.client.escape(db.settings.database) + ' LIMIT 1';
db.connector.query(q, function(err, r) {
db.connector.query(q, function (err, r) {
assert.ok(!err);
assert.ok(r[0].DEFAULT_COLLATION_NAME.match(test_collo));
db.connector.query('SHOW VARIABLES LIKE "character_set%"', function(err, r){
db.connector.query('SHOW VARIABLES LIKE "character_set%"', function (err, r) {
assert.ok(!err);
var hit_all = 0;
for (var result in r) {
@ -75,7 +72,7 @@ function charsetTest(test_set, test_collo, test_set_str, test_set_collo, done){
}
assert.equal(hit_all, 4);
});
db.connector.query('SHOW VARIABLES LIKE "collation%"', function(err, r){
db.connector.query('SHOW VARIABLES LIKE "collation%"', function (err, r) {
assert.ok(!err);
var hit_all = 0;
for (var result in r) {
@ -93,7 +90,7 @@ function charsetTest(test_set, test_collo, test_set_str, test_set_collo, done){
}
function matchResult(result, variable_name, match) {
if(result.Variable_name == variable_name){
if (result.Variable_name == variable_name) {
assert.ok(result.Value.match(match));
return 1;
}

View File

@ -3,17 +3,17 @@ var assert = require('assert');
var db, EnumModel, ANIMAL_ENUM;
describe('MySQL specific datatypes', function() {
describe('MySQL specific datatypes', function () {
before(setup);
it('should run migration', function(done) {
db.automigrate(function(){
it('should run migration', function (done) {
db.automigrate(function () {
done();
});
});
it('An enum should parse itself', function(done) {
it('An enum should parse itself', function (done) {
assert.equal(ANIMAL_ENUM.CAT, ANIMAL_ENUM('cat'));
assert.equal(ANIMAL_ENUM.CAT, ANIMAL_ENUM('CAT'));
assert.equal(ANIMAL_ENUM.CAT, ANIMAL_ENUM(2));
@ -24,11 +24,11 @@ describe('MySQL specific datatypes', function() {
done();
});
it('should create a model instance with Enums', function(done) {
var em = EnumModel.create({animal: ANIMAL_ENUM.CAT, condition: 'sleepy', mood: 'happy'}, function(err, obj) {
it('should create a model instance with Enums', function (done) {
var em = EnumModel.create({animal: ANIMAL_ENUM.CAT, condition: 'sleepy', mood: 'happy'}, function (err, obj) {
assert.ok(!err);
assert.equal(obj.condition, 'sleepy');
EnumModel.findOne({where: {animal: ANIMAL_ENUM.CAT}}, function(err, found){
EnumModel.findOne({where: {animal: ANIMAL_ENUM.CAT}}, function (err, found) {
assert.ok(!err);
assert.equal(found.mood, 'happy');
assert.equal(found.animal, ANIMAL_ENUM.CAT);
@ -37,10 +37,10 @@ describe('MySQL specific datatypes', function() {
});
});
it('should fail spectacularly with invalid enum values', function(done) {
var em = EnumModel.create({animal: 'horse', condition: 'sleepy', mood: 'happy'}, function(err, obj) {
it('should fail spectacularly with invalid enum values', function (done) {
var em = EnumModel.create({animal: 'horse', condition: 'sleepy', mood: 'happy'}, function (err, obj) {
assert.ok(!err);
EnumModel.findById(obj.id, function(err, found){
EnumModel.findById(obj.id, function (err, found) {
assert.ok(!err);
assert.equal(found.animal, ''); // MySQL fun.
assert.equal(found.animal, 0);
@ -49,7 +49,7 @@ describe('MySQL specific datatypes', function() {
});
});
it('should disconnect when done', function(done) {
it('should disconnect when done', function (done) {
db.disconnect();
done()
});
@ -82,27 +82,27 @@ var blankDatabase = function (db, cb) {
var dbn = db.settings.database;
var cs = db.settings.charset;
var co = db.settings.collation;
query('DROP DATABASE IF EXISTS ' + dbn, function(err) {
query('DROP DATABASE IF EXISTS ' + dbn, function (err) {
var q = 'CREATE DATABASE ' + dbn;
if(cs){
if (cs) {
q += ' CHARACTER SET ' + cs;
}
if(co){
if (co) {
q += ' COLLATE ' + co;
}
query(q, function(err) {
query('USE '+ dbn, cb);
query(q, function (err) {
query('USE ' + dbn, cb);
});
});
};
getFields = function (model, cb) {
query('SHOW FIELDS FROM ' + model, function(err, res) {
query('SHOW FIELDS FROM ' + model, function (err, res) {
if (err) {
cb(err);
} else {
var fields = {};
res.forEach(function(field){
res.forEach(function (field) {
fields[field.Field] = field;
});
cb(err, fields);
@ -111,14 +111,14 @@ getFields = function (model, cb) {
}
getIndexes = function (model, cb) {
query('SHOW INDEXES FROM ' + model, function(err, res) {
query('SHOW INDEXES FROM ' + model, function (err, res) {
if (err) {
console.log(err);
cb(err);
} else {
var indexes = {};
// Note: this will only show the first key of compound keys
res.forEach(function(index) {
res.forEach(function (index) {
if (parseInt(index.Seq_in_index, 10) == 1) {
indexes[index.Key_name] = index
}

View File

@ -1,6 +1,6 @@
describe('mysql imported features', function() {
describe('mysql imported features', function () {
before(function() {
before(function () {
require('./init.js');
});

View File

@ -4,7 +4,7 @@ var DataSource = require('loopback-datasource-juggler').DataSource;
var config = require('rc')('loopback', {test: {mysql: {}}}).test.mysql;
global.getConfig = function(options) {
global.getConfig = function (options) {
var dbConf = {
host: config.host || 'localhost',
@ -24,7 +24,7 @@ global.getConfig = function(options) {
return dbConf;
};
global.getDataSource = global.getSchema = function(options) {
global.getDataSource = global.getSchema = function (options) {
var db = new DataSource(require('../'), getConfig(options));
return db;
};

View File

@ -4,18 +4,18 @@ var Schema = require('loopback-datasource-juggler').Schema;
var db, UserData, StringData, NumberData, DateData;
describe('migrations', function() {
describe('migrations', function () {
before(setup);
it('should run migration', function(done) {
db.automigrate(function(){
it('should run migration', function (done) {
db.automigrate(function () {
done();
});
});
it('UserData should have correct columns', function(done) {
getFields('UserData', function(err, fields) {
it('UserData should have correct columns', function (done) {
getFields('UserData', function (err, fields) {
assert.deepEqual(fields, {
id: {
Field: 'id',
@ -71,12 +71,11 @@ describe('migrations', function() {
});
});
it('UserData should have correct indexes', function(done) {
it('UserData should have correct indexes', function (done) {
// Note: getIndexes truncates multi-key indexes to the first member. Hence index1 is correct.
getIndexes('UserData', function(err, fields) {
getIndexes('UserData', function (err, fields) {
// console.log('....', fields);
assert.deepEqual(fields, { PRIMARY:
{ Table: 'UserData',
assert.deepEqual(fields, { PRIMARY: { Table: 'UserData',
Non_unique: 0,
Key_name: 'PRIMARY',
Seq_in_index: 1,
@ -88,8 +87,7 @@ describe('migrations', function() {
Null: '',
Index_type: 'BTREE',
Comment: '' },
email:
{ Table: 'UserData',
email: { Table: 'UserData',
Non_unique: 1,
Key_name: 'email',
Seq_in_index: 1,
@ -101,8 +99,7 @@ describe('migrations', function() {
Null: '',
Index_type: 'BTREE',
Comment: '' },
index0:
{ Table: 'UserData',
index0: { Table: 'UserData',
Non_unique: 1,
Key_name: 'index0',
Seq_in_index: 1,
@ -119,45 +116,39 @@ describe('migrations', function() {
});
});
it('StringData should have correct columns', function(done) {
getFields('StringData', function(err, fields) {
assert.deepEqual(fields, { id:
{ Field: 'id',
it('StringData should have correct columns', function (done) {
getFields('StringData', function (err, fields) {
assert.deepEqual(fields, { id: { Field: 'id',
Type: 'int(11)',
Null: 'NO',
Key: 'PRI',
Default: null,
Extra: 'auto_increment' },
smallString:
{ Field: 'smallString',
smallString: { Field: 'smallString',
Type: 'char(127)',
Null: 'NO',
Key: 'MUL',
Default: null,
Extra: '' },
mediumString:
{ Field: 'mediumString',
mediumString: { Field: 'mediumString',
Type: 'varchar(255)',
Null: 'NO',
Key: '',
Default: null,
Extra: '' },
tinyText:
{ Field: 'tinyText',
tinyText: { Field: 'tinyText',
Type: 'tinytext',
Null: 'YES',
Key: '',
Default: null,
Extra: '' },
giantJSON:
{ Field: 'giantJSON',
giantJSON: { Field: 'giantJSON',
Type: 'longtext',
Null: 'YES',
Key: '',
Default: null,
Extra: '' },
text:
{ Field: 'text',
text: { Field: 'text',
Type: 'varchar(1024)',
Null: 'YES',
Key: '',
@ -168,39 +159,34 @@ describe('migrations', function() {
});
});
it('NumberData should have correct columns', function(done) {
getFields('NumberData', function(err, fields) {
it('NumberData should have correct columns', function (done) {
getFields('NumberData', function (err, fields) {
assert.deepEqual(fields, {
id:
{ Field: 'id',
id: { Field: 'id',
Type: 'int(11)',
Null: 'NO',
Key: 'PRI',
Default: null,
Extra: 'auto_increment' },
number:
{ Field: 'number',
number: { Field: 'number',
Type: 'decimal(10,3) unsigned',
Null: 'NO',
Key: 'MUL',
Default: null,
Extra: '' },
tinyInt:
{ Field: 'tinyInt',
tinyInt: { Field: 'tinyInt',
Type: 'tinyint(2)',
Null: 'YES',
Key: '',
Default: null,
Extra: '' },
mediumInt:
{ Field: 'mediumInt',
mediumInt: { Field: 'mediumInt',
Type: 'mediumint(8) unsigned',
Null: 'YES',
Key: '',
Default: null,
Extra: '' },
floater:
{ Field: 'floater',
floater: { Field: 'floater',
Type: 'double(14,6)',
Null: 'YES',
Key: '',
@ -211,25 +197,22 @@ describe('migrations', function() {
});
});
it('DateData should have correct columns', function(done) {
getFields('DateData', function(err, fields) {
it('DateData should have correct columns', function (done) {
getFields('DateData', function (err, fields) {
assert.deepEqual(fields, {
id:
{ Field: 'id',
id: { Field: 'id',
Type: 'int(11)',
Null: 'NO',
Key: 'PRI',
Default: null,
Extra: 'auto_increment' },
dateTime:
{ Field: 'dateTime',
dateTime: { Field: 'dateTime',
Type: 'datetime',
Null: 'YES',
Key: '',
Default: null,
Extra: '' },
timestamp:
{ Field: 'timestamp',
timestamp: { Field: 'timestamp',
Type: 'timestamp',
Null: 'YES',
Key: '',
@ -240,24 +223,24 @@ describe('migrations', function() {
});
});
it('should autoupgrade', function(done) {
var userExists = function(cb) {
query('SELECT * FROM UserData', function(err, res) {
it('should autoupgrade', function (done) {
var userExists = function (cb) {
query('SELECT * FROM UserData', function (err, res) {
cb(!err && res[0].email == 'test@example.com');
});
}
UserData.create({email: 'test@example.com'}, function(err, user) {
UserData.create({email: 'test@example.com'}, function (err, user) {
assert.ok(!err, 'Could not create user: ' + err);
userExists(function(yep) {
userExists(function (yep) {
assert.ok(yep, 'User does not exist');
});
UserData.defineProperty('email', { type: String });
UserData.defineProperty('name', {type: String, dataType: 'char', limit: 50});
UserData.defineProperty('newProperty', {type: Number, unsigned: true, dataType: 'bigInt'});
// UserData.defineProperty('pendingPeriod', false); This will not work as expected.
db.autoupdate( function(err) {
getFields('UserData', function(err, fields) {
db.autoupdate(function (err) {
getFields('UserData', function (err, fields) {
// change nullable for email
assert.equal(fields.email.Null, 'YES', 'Email does not allow null');
// change type of name
@ -270,7 +253,7 @@ describe('migrations', function() {
// drop column - will not happen.
// assert.ok(!fields.pendingPeriod, 'Did not drop column pendingPeriod');
// user still exists
userExists(function(yep) {
userExists(function (yep) {
assert.ok(yep, 'User does not exist');
done();
});
@ -279,24 +262,24 @@ describe('migrations', function() {
});
});
it('should check actuality of dataSource', function(done) {
it('should check actuality of dataSource', function (done) {
// 'drop column'
UserData.dataSource.isActual(function(err, ok) {
UserData.dataSource.isActual(function (err, ok) {
assert.ok(ok, 'dataSource is not actual (should be)');
UserData.defineProperty('essay', {type: Schema.Text});
// UserData.defineProperty('email', false); Can't undefine currently.
UserData.dataSource.isActual(function(err, ok) {
UserData.dataSource.isActual(function (err, ok) {
assert.ok(!ok, 'dataSource is actual (shouldn\t be)');
done()
});
});
});
it('should allow numbers with decimals', function(done) {
NumberData.create({number: 1.1234567, tinyInt: 123456, mediumInt: -1234567, floater: 123456789.1234567 }, function(err, obj) {
it('should allow numbers with decimals', function (done) {
NumberData.create({number: 1.1234567, tinyInt: 123456, mediumInt: -1234567, floater: 123456789.1234567 }, function (err, obj) {
assert.ok(!err);
assert.ok(obj);
NumberData.findById(obj.id, function(err, found) {
NumberData.findById(obj.id, function (err, found) {
assert.equal(found.number, 1.123);
assert.equal(found.tinyInt, 127);
assert.equal(found.mediumInt, 0);
@ -306,14 +289,14 @@ describe('migrations', function() {
});
});
it('should allow both kinds of date columns', function(done) {
it('should allow both kinds of date columns', function (done) {
DateData.create({
dateTime: new Date('Aug 9 1996 07:47:33 GMT'),
timestamp: new Date('Sep 22 2007 17:12:22 GMT')
}, function(err, obj){
}, function (err, obj) {
assert.ok(!err);
assert.ok(obj);
DateData.findById(obj.id, function(err, found){
DateData.findById(obj.id, function (err, found) {
assert.equal(found.dateTime.toGMTString(), 'Fri, 09 Aug 1996 07:47:33 GMT');
assert.equal(found.timestamp.toGMTString(), 'Sat, 22 Sep 2007 17:12:22 GMT');
done();
@ -321,7 +304,7 @@ describe('migrations', function() {
});
});
it('should disconnect when done', function(done) {
it('should disconnect when done', function (done) {
db.disconnect();
done()
});
@ -341,7 +324,7 @@ function setup(done) {
birthDate: Date,
pendingPeriod: Number,
createdByAdmin: Boolean,
} , { indexes: {
}, { indexes: {
index0: {
columns: 'email, createdByAdmin'
}
@ -380,27 +363,27 @@ var blankDatabase = function (db, cb) {
var dbn = db.settings.database;
var cs = db.settings.charset;
var co = db.settings.collation;
query('DROP DATABASE IF EXISTS ' + dbn, function(err) {
query('DROP DATABASE IF EXISTS ' + dbn, function (err) {
var q = 'CREATE DATABASE ' + dbn;
if(cs){
if (cs) {
q += ' CHARACTER SET ' + cs;
}
if(co){
if (co) {
q += ' COLLATE ' + co;
}
query(q, function(err) {
query('USE '+ dbn, cb);
query(q, function (err) {
query('USE ' + dbn, cb);
});
});
};
getFields = function (model, cb) {
query('SHOW FIELDS FROM ' + model, function(err, res) {
query('SHOW FIELDS FROM ' + model, function (err, res) {
if (err) {
cb(err);
} else {
var fields = {};
res.forEach(function(field){
res.forEach(function (field) {
fields[field.Field] = field;
});
cb(err, fields);
@ -409,14 +392,14 @@ getFields = function (model, cb) {
}
getIndexes = function (model, cb) {
query('SHOW INDEXES FROM ' + model, function(err, res) {
query('SHOW INDEXES FROM ' + model, function (err, res) {
if (err) {
console.log(err);
cb(err);
} else {
var indexes = {};
// Note: this will only show the first key of compound keys
res.forEach(function(index) {
res.forEach(function (index) {
if (parseInt(index.Seq_in_index, 10) == 1) {
indexes[index.Key_name] = index
}

View File

@ -5,26 +5,26 @@ var assert = require('assert');
var DataSource = require('loopback-datasource-juggler').DataSource;
var db;
before(function() {
before(function () {
var config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
config.database = 'STRONGLOOP';
db = new DataSource(require('../'), config);
});
describe('discoverModels', function() {
describe('Discover models including views', function() {
it('should return an array of tables and views', function(done) {
describe('discoverModels', function () {
describe('Discover models including views', function () {
it('should return an array of tables and views', function (done) {
db.discoverModelDefinitions({
views : true,
limit : 3
}, function(err, models) {
views: true,
limit: 3
}, function (err, models) {
if (err) {
console.error(err);
done(err);
} else {
var views = false;
models.forEach(function(m) {
models.forEach(function (m) {
// console.dir(m);
if (m.type === 'view') {
views = true;
@ -37,19 +37,19 @@ describe('discoverModels', function() {
});
});
describe('Discover models excluding views', function() {
it('should return an array of only tables', function(done) {
describe('Discover models excluding views', function () {
it('should return an array of only tables', function (done) {
db.discoverModelDefinitions({
views : false,
limit : 3
}, function(err, models) {
views: false,
limit: 3
}, function (err, models) {
if (err) {
console.error(err);
done(err);
} else {
var views = false;
models.forEach(function(m) {
models.forEach(function (m) {
// console.dir(m);
if (m.type === 'view') {
views = true;
@ -64,19 +64,19 @@ describe('discoverModels', function() {
});
});
describe('Discover models including other users', function() {
it('should return an array of all tables and views', function(done) {
describe('Discover models including other users', function () {
it('should return an array of all tables and views', function (done) {
db.discoverModelDefinitions({
all : true,
limit : 3
}, function(err, models) {
all: true,
limit: 3
}, function (err, models) {
if (err) {
console.error(err);
done(err);
} else {
var others = false;
models.forEach(function(m) {
models.forEach(function (m) {
// console.dir(m);
if (m.owner !== 'STRONGLOOP') {
others = true;
@ -89,15 +89,15 @@ describe('Discover models including other users', function() {
});
});
describe('Discover model properties', function() {
describe('Discover a named model', function() {
it('should return an array of columns for PRODUCT', function(done) {
db.discoverModelProperties('PRODUCT', function(err, models) {
describe('Discover model properties', function () {
describe('Discover a named model', function () {
it('should return an array of columns for PRODUCT', function (done) {
db.discoverModelProperties('PRODUCT', function (err, models) {
if (err) {
console.error(err);
done(err);
} else {
models.forEach(function(m) {
models.forEach(function (m) {
// console.dir(m);
assert(m.tableName === 'PRODUCT');
});
@ -111,7 +111,7 @@ describe('Discover model properties', function() {
describe('Discover model primary keys', function () {
it('should return an array of primary keys for PRODUCT', function (done) {
db.discoverPrimaryKeys('PRODUCT',function (err, models) {
db.discoverPrimaryKeys('PRODUCT', function (err, models) {
if (err) {
console.error(err);
done(err);
@ -143,7 +143,7 @@ describe('Discover model primary keys', function () {
describe('Discover model foreign keys', function () {
it('should return an array of foreign keys for INVENTORY', function (done) {
db.discoverForeignKeys('INVENTORY',function (err, models) {
db.discoverForeignKeys('INVENTORY', function (err, models) {
if (err) {
console.error(err);
done(err);