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; }));