Skip to content

Commit 2022daf

Browse files
iteufelojourmel
authored andcommitted
Fixed code style
1 parent c62c500 commit 2022daf

File tree

3 files changed

+116
-117
lines changed

3 files changed

+116
-117
lines changed

lib/dialects/mssql/blocks.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,41 @@ module.exports = function(dialect) {
1919
});
2020

2121
dialect.blocks.set('returning', function(params) {
22-
var result = dialect.buildBlock('fields', {fields: params.returning});
22+
var result = dialect.buildBlock('fields', {fields: params.returning});
2323

24-
if (result) result = 'output ' + result;
24+
if (result) result = 'output ' + result;
2525

26-
return result;
27-
});
26+
return result;
27+
});
2828

2929
dialect.blocks.set('insert:values', function(params) {
30-
var values = params.values;
30+
var values = params.values;
3131

32-
if (!_.isArray(values)) values = [values];
32+
if (!_.isArray(values)) values = [values];
3333

34-
var fields = params.fields || _(values)
35-
.chain()
36-
.map(function(row) {
37-
return _(row).keys();
38-
})
39-
.flatten()
40-
.uniq()
41-
.value();
34+
var fields = params.fields || _(values)
35+
.chain()
36+
.map(function(row) {
37+
return _(row).keys();
38+
})
39+
.flatten()
40+
.uniq()
41+
.value();
4242

43-
return dialect.buildTemplate('insertValues', {
44-
fields: fields,
43+
return dialect.buildTemplate('insertValues', {
44+
fields: fields,
4545
returning: params.returning || undefined,
46-
values: _(values).map(function(row) {
47-
return _(fields).map(function(field) {
48-
return dialect.buildBlock('value', {value: row[field]});
49-
});
50-
})
51-
});
52-
});
46+
values: _(values).map(function(row) {
47+
return _(fields).map(function(field) {
48+
return dialect.buildBlock('value', {value: row[field]});
49+
});
50+
})
51+
});
52+
});
5353

5454
dialect.blocks.add('insertValues:values', function(params) {
55-
return _(params.values).map(function(row) {
56-
return '(' + row.join(', ') + ')';
57-
}).join(', ');
58-
});
55+
return _(params.values).map(function(row) {
56+
return '(' + row.join(', ') + ')';
57+
}).join(', ');
58+
});
5959
};

lib/dialects/mssql/templates.js

+43-44
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,27 @@ module.exports = function(dialect) {
4747
}
4848
});
4949

50-
5150
dialect.templates.add('insert', {
52-
pattern: '{with} {withRecursive} insert {or} into {table} {values} ' +
53-
'{condition}',
54-
validate: function(type, params) {
55-
templateChecks.onlyOneOfProps(type, params, ['with', 'withRecursive']);
56-
templateChecks.propType(type, params, 'with', 'object');
57-
templateChecks.propType(type, params, 'withRecursive', 'object');
51+
pattern: '{with} {withRecursive} insert {or} into {table} {values} ' +
52+
'{condition}',
53+
validate: function(type, params) {
54+
templateChecks.onlyOneOfProps(type, params, ['with', 'withRecursive']);
55+
templateChecks.propType(type, params, 'with', 'object');
56+
templateChecks.propType(type, params, 'withRecursive', 'object');
5857

59-
templateChecks.propType(type, params, 'or', 'string');
60-
templateChecks.propMatch(type, params, 'or', orRegExp);
58+
templateChecks.propType(type, params, 'or', 'string');
59+
templateChecks.propMatch(type, params, 'or', orRegExp);
6160

62-
templateChecks.requiredProp(type, params, 'table');
63-
templateChecks.propType(type, params, 'table', 'string');
61+
templateChecks.requiredProp(type, params, 'table');
62+
templateChecks.propType(type, params, 'table', 'string');
6463

65-
templateChecks.requiredProp(type, params, 'values');
66-
templateChecks.propType(type, params, 'values', ['array', 'object']);
64+
templateChecks.requiredProp(type, params, 'values');
65+
templateChecks.propType(type, params, 'values', ['array', 'object']);
6766

68-
templateChecks.propType(type, params, 'condition', ['array', 'object']);
67+
templateChecks.propType(type, params, 'condition', ['array', 'object']);
6968

70-
}
71-
});
69+
}
70+
});
7271

7372
dialect.templates.add('insertValues', {
7473
pattern: '({fields}) {returning} values {values}',
@@ -85,47 +84,47 @@ module.exports = function(dialect) {
8584
}
8685
});
8786

88-
dialect.templates.add('update', {
89-
pattern: '{with} {withRecursive} update {or} {table} {alias} {modifier} {returning} {condition} ',
90-
validate: function(type, params) {
91-
templateChecks.onlyOneOfProps(type, params, ['with', 'withRecursive']);
92-
templateChecks.propType(type, params, 'with', 'object');
93-
templateChecks.propType(type, params, 'withRecursive', 'object');
87+
dialect.templates.add('update', {
88+
pattern: '{with} {withRecursive} update {or} {table} {alias} {modifier} {returning} {condition} ',
89+
validate: function(type, params) {
90+
templateChecks.onlyOneOfProps(type, params, ['with', 'withRecursive']);
91+
templateChecks.propType(type, params, 'with', 'object');
92+
templateChecks.propType(type, params, 'withRecursive', 'object');
9493

95-
templateChecks.propType(type, params, 'or', 'string');
96-
templateChecks.propMatch(type, params, 'or', orRegExp);
94+
templateChecks.propType(type, params, 'or', 'string');
95+
templateChecks.propMatch(type, params, 'or', orRegExp);
9796

98-
templateChecks.requiredProp(type, params, 'table');
99-
templateChecks.propType(type, params, 'table', 'string');
97+
templateChecks.requiredProp(type, params, 'table');
98+
templateChecks.propType(type, params, 'table', 'string');
10099

101100
templateChecks.propType(type, params, 'returning', ['array', 'object']);
102101

103-
templateChecks.propType(type, params, 'alias', 'string');
102+
templateChecks.propType(type, params, 'alias', 'string');
104103

105-
templateChecks.requiredProp(type, params, 'modifier');
106-
templateChecks.propType(type, params, 'modifier', 'object');
104+
templateChecks.requiredProp(type, params, 'modifier');
105+
templateChecks.propType(type, params, 'modifier', 'object');
107106

108-
templateChecks.propType(type, params, 'condition', ['array', 'object']);
107+
templateChecks.propType(type, params, 'condition', ['array', 'object']);
109108

110-
}
111-
});
109+
}
110+
});
112111

113-
dialect.templates.add('remove', {
114-
pattern: '{with} {withRecursive} delete from {table} {returning} {alias} {condition} ',
115-
validate: function(type, params) {
116-
templateChecks.onlyOneOfProps(type, params, ['with', 'withRecursive']);
117-
templateChecks.propType(type, params, 'with', 'object');
118-
templateChecks.propType(type, params, 'withRecursive', 'object');
112+
dialect.templates.add('remove', {
113+
pattern: '{with} {withRecursive} delete from {table} {returning} {alias} {condition} ',
114+
validate: function(type, params) {
115+
templateChecks.onlyOneOfProps(type, params, ['with', 'withRecursive']);
116+
templateChecks.propType(type, params, 'with', 'object');
117+
templateChecks.propType(type, params, 'withRecursive', 'object');
119118

120-
templateChecks.requiredProp(type, params, 'table');
121-
templateChecks.propType(type, params, 'table', 'string');
119+
templateChecks.requiredProp(type, params, 'table');
120+
templateChecks.propType(type, params, 'table', 'string');
122121

123122
templateChecks.propType(type, params, 'returning', ['array', 'object']);
124123

125-
templateChecks.propType(type, params, 'alias', 'string');
124+
templateChecks.propType(type, params, 'alias', 'string');
126125

127-
templateChecks.propType(type, params, 'condition', ['array', 'object']);
126+
templateChecks.propType(type, params, 'condition', ['array', 'object']);
128127

129-
}
130-
});
128+
}
129+
});
131130
};

tests/6_dialects/1_mssql.js

+46-46
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
'use strict';
22

33
var jsonSql = require('../../lib')({
4-
dialect: 'mssql',
5-
namedValues: false
4+
dialect: 'mssql',
5+
namedValues: false
66
});
77
var expect = require('chai').expect;
88

99
describe('MSSQL dialect', function() {
10-
describe('limit', function() {
11-
it('should be ok with `limit` property', function() {
12-
var result = jsonSql.build({
13-
table: 'test',
14-
fields: ['user'],
10+
describe('limit', function() {
11+
it('should be ok with `limit` property', function() {
12+
var result = jsonSql.build({
13+
table: 'test',
14+
fields: ['user'],
1515
limit: 1,
16-
condition: {
17-
'name': {$eq: 'test'}
18-
}
19-
});
20-
expect(result.query).to.be.equal('select top(1) "user" from "test" where "name" = $1;');
21-
});
16+
condition: {
17+
'name': {$eq: 'test'}
18+
}
19+
});
20+
expect(result.query).to.be.equal('select top(1) "user" from "test" where "name" = $1;');
21+
});
2222

2323
it('should be ok with `limit` and `offset` properties', function() {
24-
var result = jsonSql.build({
25-
table: 'test',
26-
fields: ['user'],
24+
var result = jsonSql.build({
25+
table: 'test',
26+
fields: ['user'],
2727
limit: 4,
2828
offset: 2,
29-
condition: {
30-
'name': {$eq: 'test'}
31-
}
32-
});
33-
expect(result.query).to.be.equal('select "user" from "test" where "name" = $1 order by 1 offset 2 rows fetch next 4 rows only;');
34-
});
29+
condition: {
30+
'name': {$eq: 'test'}
31+
}
32+
});
33+
expect(result.query).to.be.equal('select "user" from "test" where "name" = $1 order by 1 offset 2 rows fetch next 4 rows only;');
34+
});
35+
});
36+
describe('returning', function() {
37+
it('should be ok with `remove` type', function() {
38+
var result = jsonSql.build({
39+
type: 'remove',
40+
table: 'test',
41+
returning: ['DELETED.*'],
42+
condition: {
43+
Description: {$eq: 'test'}
44+
}
45+
});
46+
expect(result.query).to.be.equal('delete from "test" output "DELETED".* where "Description" = $1;');
47+
});
48+
it('should be ok with `insert` type', function() {
49+
var result = jsonSql.build({
50+
type: 'insert',
51+
table: 'test',
52+
returning: ['INSERTED.*'],
53+
values: {
54+
Description: 'test',
55+
}
56+
});
57+
expect(result.query).to.be.equal('insert into "test" ("Description") output "INSERTED".* values ($1);');
58+
});
3559
});
36-
describe('returning', function() {
37-
it('should be ok with `remove` type', function() {
38-
var result = jsonSql.build({
39-
type: 'remove',
40-
table: 'test',
41-
returning: ['DELETED.*'],
42-
condition: {
43-
Description: {$eq: 'test'}
44-
}
45-
});
46-
expect(result.query).to.be.equal('delete from "test" output "DELETED".* where "Description" = $1;');
47-
});
48-
it('should be ok with `insert` type', function() {
49-
var result = jsonSql.build({
50-
type: 'insert',
51-
table: 'test',
52-
returning: ['INSERTED.*'],
53-
values: {
54-
Description: 'test',
55-
}
56-
});
57-
expect(result.query).to.be.equal('insert into "test" ("Description") output "INSERTED".* values ($1);');
58-
});
59-
});
6060
});

0 commit comments

Comments
 (0)