Merge branch 'master' of github.com:1602/jugglingdb

This commit is contained in:
Anatoliy Chakkaev 2012-03-16 18:44:48 +04:00
commit 66319b2c79
1 changed files with 18 additions and 2 deletions

View File

@ -109,7 +109,16 @@ function dateToPostgres(val) {
}
PG.prototype.toDatabase = function (prop, val) {
if (val === null) return 'NULL';
if (val === null) {
// Postgres complains with NULLs in not null columns
// If we have an autoincrement value, return DEFAULT instead
if( prop.autoIncrement ) {
return 'DEFAULT';
}
else {
return 'NULL';
}
}
if (val.constructor.name === 'Object') {
var operator = Object.keys(val)[0]
val = val[operator];
@ -119,7 +128,14 @@ PG.prototype.toDatabase = function (prop, val) {
}
if (prop.type.name === 'Number') return val;
if (prop.type.name === 'Date') {
if (!val) return 'NULL';
if (!val) {
if( prop.autoIncrement ) {
return 'DEFAULT';
}
else {
return 'NULL';
}
}
if (!val.toUTCString) {
val = new Date(val);
}