forked from TokyoFarmer/node-sql-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateIndex.js
More file actions
63 lines (49 loc) · 1.22 KB
/
createIndex.js
File metadata and controls
63 lines (49 loc) · 1.22 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
var Node = require('./');
var sliced = require('sliced');
module.exports = Node.define({
type: 'CREATE INDEX',
constructor: function(table, indexName) {
Node.call(this);
this.table = table;
this.options = { indexName: indexName, columns: [] };
},
unique: function() {
this.options.type = 'unique';
return this;
},
spatial: function() {
this.options.type = 'spatial';
return this;
},
fulltext: function() {
this.options.type = 'fulltext';
return this;
},
using: function(algorithm) {
this.options.algorithm = algorithm;
return this;
},
on: function() {
var args = sliced(arguments);
this.options.columns = this.options.columns.concat(args);
return this;
},
withParser: function(parser) {
this.options.parser = parser;
return this;
},
indexName: function() {
var result = this.options.indexName;
if (!result) {
var columns = this.options.columns.map(function(col) {
var column = col.name ? col.name : col.value.name;
return column;
}).sort();
result = [this.table._name];
result = result.concat(columns);
result = result.join('_');
}
return result;
}
});