forked from brianc/node-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropIndex.js
More file actions
39 lines (30 loc) · 937 Bytes
/
dropIndex.js
File metadata and controls
39 lines (30 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
var Node = require('./');
module.exports = Node.define({
type: 'DROP INDEX',
constructor: function(table, indexName) {
if (!indexName) {
throw new Error('No index defined!');
} else if (Array.isArray(indexName) && (typeof indexName[0] === 'string')) {
indexName = indexName[0];
} else if (Array.isArray(indexName)) {
var columns = indexName.map(function(col) { return col.name; }).sort();
indexName = [table._name].concat(columns).join('_');
}
Node.call(this);
this.table = table;
this.options = { indexName: indexName };
},
indexName: function() {
var result = this.options.indexName;
if (!result) {
var columns = this.options.columns.map(function(col) {
return col.name;
}).sort();
result = [this.table._name];
result = result.concat(columns);
result = result.join('_');
}
return result;
}
});