Skip to content

Commit 0296b9e

Browse files
committed
feat(defaultValue): add advanced handling for defaultValues
This adds the possibility to pass raw defaultValues and special defaultValues such as CURRENT_TIMESTAMP. Signed-off-by: Tobias Gurtzick <magic@wizardtales.com>
1 parent 58c1ba1 commit 0296b9e

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

index.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@ var Base = Class.extend({
2828
throw new Error('not implemented');
2929
},
3030

31+
_translateSpecialDefaultValues: function(
32+
spec,
33+
options,
34+
tableName,
35+
columnName
36+
) {
37+
spec.defaultValue.prep = null;
38+
log.warn(
39+
'special default value ' +
40+
spec.defaultvalue.special +
41+
' is not supported by your driver. Setting to no defaultvalue instead.'
42+
);
43+
},
44+
45+
_prepareSpec: function(spec, options, tableName, columnName) {
46+
if (spec.defaultValue.raw) {
47+
spec.defaultValue.prep = spec.defaultValue.raw;
48+
} else if (spec.defaultValue.special) {
49+
this._translateSpecialDefaultValues(spec, options, tableName, columnName);
50+
}
51+
},
52+
3153
mapDataType: function(str) {
3254
switch (str) {
3355
case type.STRING:
@@ -233,6 +255,7 @@ var Base = Class.extend({
233255

234256
for (var columnName in columnSpecs) {
235257
var columnSpec = columnSpecs[columnName];
258+
this._prepareSpec(columnName, columnSpec, columnDefOptions, tableName);
236259
var constraint = this.createColumnDef(
237260
columnName,
238261
columnSpec,
@@ -303,9 +326,11 @@ var Base = Class.extend({
303326
},
304327

305328
addColumn: function(tableName, columnName, columnSpec, callback) {
329+
var columnSpec = this.normalizeColumnSpec(columnSpec)
330+
this._prepareSpec(columnName, columnSpec, columnDefOptions, tableName);
306331
var def = this.createColumnDef(
307332
columnName,
308-
this.normalizeColumnSpec(columnSpec),
333+
columnSpec,
309334
{},
310335
tableName
311336
);

0 commit comments

Comments
 (0)