mirror of
https://github.com/knex/knex.git
synced 2025-07-07 17:10:49 +00:00
20 lines
609 B
JavaScript
20 lines
609 B
JavaScript
![]() |
function compileCreateIndex(ast, wrap = (v) => v) {
|
||
|
const columns = ast.columns
|
||
|
.map((column) => {
|
||
|
return `${!column.expression ? wrap(column.name) : column.name}${
|
||
|
column.collation ? ` COLLATE ${column.collation}` : ''
|
||
|
}${column.order ? ` ${column.order}` : ''}`;
|
||
|
})
|
||
|
.join(', ');
|
||
|
|
||
|
return `CREATE${ast.unique ? ' UNIQUE' : ''} INDEX${
|
||
|
ast.exists ? ' IF NOT EXISTS' : ''
|
||
|
} ${ast.schema ? `${wrap(ast.schema)}.` : ''}${wrap(ast.index)} on ${wrap(
|
||
|
ast.table
|
||
|
)} (${columns})${ast.where ? ` where ${ast.where}` : ''}`;
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
compileCreateIndex,
|
||
|
};
|