From da85732bbf9aacbba98441c21ddf94f31bcdf904 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 20 Oct 2015 07:32:09 +0000 Subject: [PATCH] fix modelname --- lib/dbwrap.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/dbwrap.js b/lib/dbwrap.js index b302794..3e84451 100644 --- a/lib/dbwrap.js +++ b/lib/dbwrap.js @@ -22,16 +22,18 @@ function wrap(db, dir) { } function camelCase(str) { - return str.replace( + str = str.replace( /_([a-z])/g , function (g) { - return g[1].toUpperCase(); - }); + return g[1].toUpperCase(); + } + ); + return str; } function upperCamelCase(str) { // TODO handle UTF-8 properly (use codePointAt, don't use slice) - return camelCase(str).charAt(0).toUpperCase() + str.slice(1); + return str.charAt(0).toUpperCase() + camelCase(str).slice(1); } function createTable(opts) { @@ -379,11 +381,14 @@ function wrap(db, dir) { dir.forEach(function (opts) { promises.push(createTable(opts).then(function (dbw) { - var tablename = (opts.tablename || 'data'); + var modelname = opts.modelname; + + if (!modelname) { + modelname = (opts.tablename || 'data'); + modelname = upperCamelCase(modelname); + } - tablename = upperCamelCase(tablename); - - dbsMap[tablename] = dbw; + dbsMap[modelname] = dbw; return dbw; }));