offset-limit.test.js
2.12 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
'use strict';
const Support = require(__dirname + '/../support'),
util = require('util'),
expectsql = Support.expectsql,
current = Support.sequelize,
sql = current.dialect.QueryGenerator;
// 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'), () => {
suite('offset/limit', () => {
const testsql = function(options, expectation) {
const model = options.model;
test(util.inspect(options, {depth: 2}), () => {
return expectsql(
sql.addLimitAndOffset(
options,
model
),
expectation
);
});
};
testsql({
limit: 10, //when no order by present, one is automagically prepended, test its existence
model: {primaryKeyField: 'id', name: 'tableRef'}
}, {
default: ' LIMIT 10',
mssql: ' ORDER BY [tableRef].[id] OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'
});
testsql({
limit: 10,
order: [
['email', 'DESC'] // for MSSQL
]
}, {
default: ' LIMIT 10',
mssql: ' OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'
});
testsql({
limit: 10,
offset: 20,
order: [
['email', 'DESC'] // for MSSQL
]
}, {
default: ' LIMIT 20, 10',
postgres: ' LIMIT 10 OFFSET 20',
mssql: ' OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY'
});
testsql({
limit: "';DELETE FROM user",
order: [
['email', 'DESC'] // for MSSQL
]
}, {
default: " LIMIT ''';DELETE FROM user'",
mysql: " LIMIT '\\';DELETE FROM user'",
mssql: " OFFSET 0 ROWS FETCH NEXT N''';DELETE FROM user' ROWS ONLY"
});
testsql({
limit: 10,
offset: "';DELETE FROM user",
order: [
['email', 'DESC'] // for MSSQL
]
}, {
sqlite: " LIMIT ''';DELETE FROM user', 10",
postgres: " LIMIT 10 OFFSET ''';DELETE FROM user'",
mysql: " LIMIT '\\';DELETE FROM user', 10",
mssql: " OFFSET N''';DELETE FROM user' ROWS FETCH NEXT 10 ROWS ONLY"
});
});
});