Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static table(thiz) {
if (thiz.constructor.name === 'Function') {
// static context
return inflection.tableize(thiz.name);
}
// non-static context
return inflection.tableize(thiz.constructor.name);
}
tableName() {
// TODO strategy to shorten names to 64 chars
return tableize(
singularize(
this.sourceModelName() +
'_' +
this.from_field.name.replace(/Keys([0-9]*)$/, '$1'),
),
);
}
resolveTableName(tableName) {
const tableParts = tableName.split('.');
if (tableParts.length === 2) {
this.scaffoldingSchema.resolveTableDefinition(tableName);
return tableName;
} else if (tableParts.length === 1) {
const schema = Object.keys(this.dbSchema).find(schema => this.dbSchema[schema][tableName] || this.dbSchema[schema][inflection.tableize(tableName)]);
if (!schema) {
throw new UserError(`Can't find any table with '${tableName}' name`);
}
if (this.dbSchema[schema][tableName]){
return `${schema}.${tableName}`;
}
if (this.dbSchema[schema][inflection.tableize(tableName)]){
return `${schema}.${inflection.tableize(tableName)}`;
}
} else {
throw new UserError(`Table names should be in or .<table></table><table></table> format`);
}
}
resolveTableName(tableName) {
const tableParts = tableName.split('.');
if (tableParts.length === 2) {
this.scaffoldingSchema.resolveTableDefinition(tableName);
return tableName;
} else if (tableParts.length === 1) {
const schema = Object.keys(this.dbSchema).find(schema => this.dbSchema[schema][tableName] || this.dbSchema[schema][inflection.tableize(tableName)]);
if (!schema) {
throw new UserError(`Can't find any table with '${tableName}' name`);
}
if (this.dbSchema[schema][tableName]){
return `${schema}.${tableName}`;
}
if (this.dbSchema[schema][inflection.tableize(tableName)]){
return `${schema}.${inflection.tableize(tableName)}`;
}
} else {
throw new UserError(`Table names should be in or .<table></table><table></table> format`);
}
}
const schema = Object.keys(this.dbSchema).find(schema => this.dbSchema[schema][tableName] || this.dbSchema[schema][inflection.tableize(tableName)]);
if (!schema) {
static tableCasing(model_name) {
return tableize(model_name);
}
get: function() {
return this._urlRoot ? this._urlRoot : '/'+tableize(this.modelName || this.name);
},
set: function(value) {
associatedProperty.options.relationshipVia = property;
property.options.relationshipVia = associatedProperty;
}
}
if(associatedModel) {
return {
index: 999,
clause: Table.keywords.References(associatedModel.getTableName()),
dataType: 'UUID'
};
}
else {
return {
index: 999,
clause: Table.keywords.References(inflection.tableize(property.options.referenceName)),
dataType: 'UUID'
};
}
}, [modelNameOrModel, options]);
}
Handlebars.registerHelper('tableize', function(value, options) {
return value != null ? inflection.tableize(value) : null;
});