Transform the names

This commit is contained in:
Raymond Feng 2013-05-21 14:43:25 -07:00
parent 88f174ee39
commit 0022edb774
1 changed files with 24 additions and 3 deletions

View File

@ -346,6 +346,26 @@ DataSource.prototype.discoverForeignKeys= function(owner, table, cb) {
}
}
function capitalize(str) {
if (!str) {
return str;
}
return str.charAt(0).toUpperCase() + (str.length > 1) ? str.slice(1).toLowerCase() : '';
}
function fromDBName(dbName, camelCase) {
if (!dbName) {
return dbName;
}
var parts = dbName.split(/-|_/);
parts[0] = camelCase ? parts[0].toLowerCase() : capitalize(parts[0]);
for (var i = 1; i < parts.length; i++) {
parts[i] = capitalize(parts[i]);
}
return parts.join('');
}
/**
* Discover ADL schema from a given table/view
* @param owner
@ -364,7 +384,7 @@ DataSource.prototype.discoverSchema = function(owner, table, cb) {
return;
}
var schema = {
name: table,
name: fromDBName(table, false),
options: {
},
properties: {
@ -377,13 +397,14 @@ DataSource.prototype.discoverSchema = function(owner, table, cb) {
};
columns.forEach(function (item) {
var i = item;
schema.properties[item.columnName] =
var propName = fromDBName(item.columnName, true);
schema.properties[propName] =
{
type: item.type,
required: (item.nullable === 'N'),
length: item.dataLength
};
schema.properties[item.columnName][dataSourceName] = {
schema.properties[propName][dataSourceName] = {
columnName: i.columnName,
dataType: i.dataType,
nullable: i.nullable