fix modelname

This commit is contained in:
AJ ONeal 2015-10-20 07:32:09 +00:00
parent 81a7bd3811
commit da85732bbf
1 changed files with 13 additions and 8 deletions

View File

@ -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;
tablename = upperCamelCase(tablename);
if (!modelname) {
modelname = (opts.tablename || 'data');
modelname = upperCamelCase(modelname);
}
dbsMap[tablename] = dbw;
dbsMap[modelname] = dbw;
return dbw;
}));