forked from knex/knex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.js
91 lines (84 loc) · 2.65 KB
/
mysql.js
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
'use strict';
const expect = require('chai').expect;
const knex = require('../../../knex');
describe('MySQL unit tests', () => {
const qb = knex({
client: 'mysql',
connection: {
port: 1433,
host: '127.0.0.1',
password: 'yourStrong(!)Password',
user: 'sa',
},
});
it('should pass with plain values or with emtpy raw bindings', () => {
expect(qb('users').select('*').where('id', '=', 1).toString()).to.equal(
'select * from `users` where `id` = 1'
);
expect(qb('users').select('*').where({ id: 1 }).toString()).to.equal(
'select * from `users` where `id` = 1'
);
expect(qb('users').select('*').whereRaw('?? = ?').toString()).to.equal(
'select * from `users` where ?? = ?'
);
});
it('should fail if provided value is array in basic where query #1227', () => {
try {
qb('users').select('*').where('id', '=', [0]).toString();
throw new Error('Should not reach this point');
} catch (error) {
expect(error.message).to.equal(
'The values in where clause must not be object or array.'
);
}
});
it('should fail if provided value is object in basic where query #1227', () => {
try {
qb('users').select('*').where('id', '=', { test: 'test ' }).toString();
throw new Error('Should not reach this point');
} catch (error) {
expect(error.message).to.equal(
'The values in where clause must not be object or array.'
);
}
});
it('should fail if provided raw query with array value in bindings #1227', () => {
try {
qb('users')
.select('*')
.where(qb.raw('?? = ?', ['id', [0]]))
.toString();
throw new Error('Should not reach this point');
} catch (error) {
expect(error.message).to.equal(
'The values in where clause must not be object or array.'
);
}
});
it('should fail if provided raw query with object value in bindings #1227', () => {
try {
qb('users')
.select('*')
.where(qb.raw('?? = ?', ['id', { a: 1 }]))
.toString();
throw new Error('Should not reach this point');
} catch (error) {
expect(error.message).to.equal(
'The values in where clause must not be object or array.'
);
}
});
it('should fail if value in bindings is object in whereRaw #1227', () => {
try {
qb('users')
.select('*')
.whereRaw('?? = ?', ['id', { test: 'test' }])
.toString();
throw new Error('Should not reach this point');
} catch (error) {
expect(error.message).to.equal(
'The values in where clause must not be object or array.'
);
}
});
});