-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathindex.js
51 lines (39 loc) · 1.18 KB
/
index.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
'use strict';
var BaseDialect = require('../base');
var _ = require('underscore');
var util = require('util');
var templatesInit = require('./templates');
var blocksInit = require('./blocks');
var Dialect = module.exports = function(builder) {
builder._pushValue = function(value) {
if (_.isUndefined(value) || _.isNull(value)) {
return 'null';
} else if (_.isBoolean(value)) {
return String(Number(value));
} else if (_.isNumber(value)) {
return String(value);
} else if (_.isString(value) || _.isDate(value)) {
if (this.options.separatedValues) {
var placeholder = this._getPlaceholder();
if (this.options.namedValues) {
this._values[placeholder] = value;
} else {
this._values.push(value);
}
return this._wrapPlaceholder(placeholder);
} else {
if (_.isDate(value)) value = value.toISOString();
return '\'' + value + '\'';
}
} else {
throw new Error('Wrong value type "' + (typeof value) + '"');
}
};
BaseDialect.call(this, builder);
// init templates
templatesInit(this);
// init blocks
blocksInit(this);
};
util.inherits(Dialect, BaseDialect);
Dialect.prototype.config = _({}).extend(BaseDialect.prototype.config, {});