index.test.js
3.21 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict';
var Support = require(__dirname + '/../support')
, expectsql = Support.expectsql
, current = Support.sequelize
, sql = current.dialect.QueryGenerator
, current = Support.sequelize;
// Notice: [] will be replaced by dialect specific tick/quote character when there is not dialect specific expectation but only a default expectation
suite(Support.getTestDialectTeaser('SQL'), function() {
suite('addIndex', function () {
test('naming', function () {
expectsql(sql.addIndexQuery('table', ['column1', 'column2'], {}, 'table'), {
default: 'CREATE INDEX [table_column1_column2] ON [table] ([column1], [column2])'
});
if (current.dialect.supports.schemas) {
expectsql(sql.addIndexQuery('schema.table', ['column1', 'column2'], {}), {
default: 'CREATE INDEX [schema_table_column1_column2] ON [schema].[table] ([column1], [column2])'
});
expectsql(sql.addIndexQuery(sql.quoteTable(sql.addSchema({
schema: 'schema',
tableName: 'table'
})), ['column1', 'column2'], {}), {
default: 'CREATE INDEX [schema_table_column1_column2] ON [schema].[table] ([column1], [column2])'
});
}
});
test('POJO field', function () {
expectsql(sql.addIndexQuery('table', [{ attribute: 'column', collate: 'BINARY', length: 5, order: 'DESC'}], {}, 'table'), {
default: 'CREATE INDEX [table_column] ON [table] ([column] COLLATE [BINARY] DESC)',
mysql: 'CREATE INDEX `table_column` ON `table` (`column`(5) DESC)',
mssql: 'CREATE INDEX [table_column] ON [table] ([column] DESC)'
});
});
test('function', function () {
expectsql(sql.addIndexQuery('table', [current.fn('UPPER', current.col('test'))], { name: 'myindex'}), {
default: 'CREATE INDEX [myindex] ON [table] (UPPER([test]))'
});
});
if (current.dialect.supports.index.using === 2) {
test('USING', function () {
expectsql(sql.addIndexQuery('table', {
fields: ['event'],
using: 'gin'
}), {
postgres: 'CREATE INDEX "table_event" ON "table" USING gin ("event")'
});
});
}
if (current.dialect.supports.index.using === 2) {
test('WHERE', function () {
expectsql(sql.addIndexQuery('table', {
fields: ['type'],
where: {
type: 'public'
}
}), {
postgres: 'CREATE INDEX "table_type" ON "table" ("type") WHERE "type" = \'public\''
});
expectsql(sql.addIndexQuery('table', {
fields: ['type'],
where: {
type: {
$or: [
'group',
'private'
]
}
}
}), {
postgres: 'CREATE INDEX "table_type" ON "table" ("type") WHERE ("type" = \'group\' OR "type" = \'private\')'
});
});
}
if (current.dialect.supports.JSON) {
test('operator', function () {
expectsql(sql.addIndexQuery('table', {
fields: ['event'],
using: 'gin',
operator: 'jsonb_path_ops'
}), {
postgres: 'CREATE INDEX "table_event" ON "table" USING gin ("event" jsonb_path_ops)'
});
});
}
});
});