forked from 2do2go/json-sql
-
Notifications
You must be signed in to change notification settings - Fork 3
/
4_delete.js
58 lines (49 loc) · 1.26 KB
/
4_delete.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
'use strict';
var jsonSql = require('../lib')();
var expect = require('chai').expect;
describe('Delete', function() {
it('should be ok without `condition` property', function() {
var result = jsonSql.build({
type: 'remove',
table: 'users'
});
expect(result.query).to.be.equal('delete from "users";');
expect(result.values).to.be.eql({});
});
it('should be ok with `condition` property', function() {
var result = jsonSql.build({
type: 'remove',
table: 'users',
condition: {
a: 5
}
});
expect(result.query).to.be.equal('delete from "users" where "a" = 5;');
expect(result.values).to.be.eql({});
});
it('should be ok with `with` property', function() {
var result = jsonSql.build({
'with': [{
name: 't_1',
select: {
table: 't_1'
}
}],
type: 'remove',
table: 'users'
});
expect(result.query).to.be.equal('with "t_1" as (select * from "t_1") delete from "users";');
expect(result.values).to.be.eql({});
});
it('should be ok with `returning` property', function() {
var result = jsonSql.build({
type: 'remove',
table: 'users',
returning: ['users.*']
});
expect(result.query).to.be.equal(
'delete from "users" returning "users".*;'
);
expect(result.values).to.be.eql({});
});
});