From 0022edb774e0fe5bd72c1684f85ab453d736982a Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 21 May 2013 14:43:25 -0700 Subject: [PATCH] Transform the names --- lib/datasource.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/datasource.js b/lib/datasource.js index e5a98cf0..1ca15643 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -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