-
Notifications
You must be signed in to change notification settings - Fork 4
/
mysql.js
37 lines (28 loc) · 954 Bytes
/
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
const assert = require('assert')
const FibKnex = require('../')
const knex = FibKnex({
client: 'mysql',
useNullAsDefault: true
})
describe('mysql', () => {
it('no exception: select', () => {
const sqlObj = knex('users')
.select(knex.raw('count(*) as user_count, status'))
.orWhere(knex.raw('status <> ?', [1]))
.groupBy('status')
})
it('insert', () => {
const sqlObj = knex('coords')
.insert([{x: 20}, {y: 30}, {x: 10, y: 20}])
assert.equal(
sqlObj.toString(),
"insert into `coords` (`x`, `y`) values (20, NULL), (NULL, 30), (10, 20)"
)
})
it('escape when insert', () => {
const sql = knex('users')
.insert({a: 1, b: 'text', c: `what's that?`})
.toString()
assert.equal(sql, "insert into `users` (`a`, `b`, `c`) values (1, 'text', 'what\\'s that?')")
})
})