Skip to content

Commit

Permalink
Possibility to use function in multi-column index (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolezel authored Nov 14, 2017
1 parent cf783f1 commit 9111821
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/operations/indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ function generateIndexName(table, columns, options) {
: template`${table_name}_${_.isArray(columns) ? columns.join('_') : columns}${options.unique ? '_unique' : ''}_index`;
}

function generateColumnString(column) {
return /.+\(.*\)/.test(column)
? column // expression
: template`"${column}"`; // single column
}

function generateColumnsString(columns) {
if (_.isArray(columns)) {
return columns.map(name => template`"${name}"`).join(', ');
}
if (/.+\(.*\)/.test(columns)) { // expression
return columns;
}
return template`"${columns}"`; // single column
return _.isArray(columns)
? columns.map(generateColumnString).join(', ')
: generateColumnString(columns);
}

export const create = (table_name, columns, options = {}) => {
Expand Down

0 comments on commit 9111821

Please sign in to comment.