Merge pull request #875 from bitmage/custom-field-settings
support custom field settings under the connector's namespace
This commit is contained in:
commit
41ad561f11
|
@ -1343,8 +1343,6 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
columns.forEach(function (item) {
|
columns.forEach(function (item) {
|
||||||
var i = item;
|
|
||||||
|
|
||||||
var propName = nameMapper('column', item.columnName);
|
var propName = nameMapper('column', item.columnName);
|
||||||
schema.properties[propName] = {
|
schema.properties[propName] = {
|
||||||
type: item.type,
|
type: item.type,
|
||||||
|
@ -1358,14 +1356,20 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
|
||||||
if (pks[item.columnName]) {
|
if (pks[item.columnName]) {
|
||||||
schema.properties[propName].id = pks[item.columnName];
|
schema.properties[propName].id = pks[item.columnName];
|
||||||
}
|
}
|
||||||
schema.properties[propName][dbType] = {
|
var dbSpecific = schema.properties[propName][dbType] = {
|
||||||
columnName: i.columnName,
|
columnName: item.columnName,
|
||||||
dataType: i.dataType,
|
dataType: item.dataType,
|
||||||
dataLength: i.dataLength,
|
dataLength: item.dataLength,
|
||||||
dataPrecision: item.dataPrecision,
|
dataPrecision: item.dataPrecision,
|
||||||
dataScale: item.dataScale,
|
dataScale: item.dataScale,
|
||||||
nullable: i.nullable
|
nullable: item.nullable
|
||||||
};
|
};
|
||||||
|
// merge connector-specific properties
|
||||||
|
if (item[dbType]) {
|
||||||
|
for (var k in item[dbType]) {
|
||||||
|
dbSpecific[k] = item[dbType][k];
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add current modelName to the visited tables
|
// Add current modelName to the visited tables
|
||||||
|
|
|
@ -602,3 +602,20 @@ describe('discoverExportedForeignKeys', function(){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Mock connector', function() {
|
||||||
|
mockConnectors = require('./mock-connectors');
|
||||||
|
describe('customFieldSettings', function() {
|
||||||
|
ds = new DataSource(mockConnectors.customFieldSettings);
|
||||||
|
|
||||||
|
it('should be present in discoverSchemas', function(done) {
|
||||||
|
ds.discoverSchemas('person', function(err, schemas) {
|
||||||
|
should.not.exist(err);
|
||||||
|
schemas.should.be.an.Object;
|
||||||
|
schemas['public.person'].properties.name
|
||||||
|
.custom.storage.should.equal('quantum');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
// connector which uses custom field settings
|
||||||
|
customFieldSettings: {
|
||||||
|
initialize: function(ds, done) {
|
||||||
|
ds.connector = {
|
||||||
|
name: 'custom',
|
||||||
|
discoverModelProperties: function(resource, options, done) {
|
||||||
|
done(null, [
|
||||||
|
{
|
||||||
|
owner: 'public',
|
||||||
|
columnName: 'name',
|
||||||
|
type: 'String',
|
||||||
|
required: false,
|
||||||
|
|
||||||
|
// custom properties listed under a key matching the connector name
|
||||||
|
custom: {storage: 'quantum'}
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ds.connector.dataSource = ds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
Loading…
Reference in New Issue