Skip to content
This repository
Browse code

Fix fucking datetime-parsing

  • Loading branch information...
commit b1a86a0cb982fd4177ba4e2b1ecba09e6da39cf8 1 parent 78dd440
Matthew Eernisse authored August 20, 2012
3  lib/adapters/sql/postgres.js
@@ -130,7 +130,7 @@ utils.mixin(Adapter.prototype, new (function () {
130 130
             ' = ';
131 131
 
132 132
             // FIXME: Is special-casing this the right way to go?
133  
-            if (prop === null || prop === undefined) {
  133
+            if (prop === null || prop === undefined || prop == '') {
134 134
               update += 'NULL';
135 135
             }
136 136
             else {
@@ -147,6 +147,7 @@ utils.mixin(Adapter.prototype, new (function () {
147 147
         sql += 'WHERE ' + this._serializeConditions(query.conditions);
148 148
         sql += ';'
149 149
 
  150
+        utils.log(sql);
150 151
         this.exec(sql, function (err, res) {
151 152
           if (err) {
152 153
             callback(err, null);
15  lib/datatypes.js
@@ -58,11 +58,11 @@ _quoteize = function (val) {
58 58
 
59 59
 // Scrub input for basic SQL injection protection
60 60
 _escape = function (s) {
61  
-  return s.replace(/'/g, "\'\'\'\'");
  61
+  return s.replace(/'/g, "''");
62 62
 };
63 63
 
64  
-_unescape = function (s) {
65  
-  return s.replace(/''/g, "\'");
  64
+tunescape = function (s) {
  65
+  return s.replace(/''/g, "'");
66 66
 };
67 67
 
68 68
 /*
@@ -255,7 +255,8 @@ datatypes = {
255 255
   , serialize: function (input, options) {
256 256
       var val
257 257
         , opts = options || {};
258  
-      val = utils.date.strftime(input, '%F');
  258
+      val = utils.date.toUTC(input);
  259
+      val = utils.date.strftime(val, '%F');
259 260
       return _serialize(val, opts);
260 261
     }
261 262
   }
@@ -279,7 +280,8 @@ datatypes = {
279 280
   , serialize: function (input, options) {
280 281
       var val
281 282
         , opts = options || {};
282  
-      val = utils.date.toISO8601(input);
  283
+      val = utils.date.toUTC(input);
  284
+      val = utils.date.toISO8601(val, {utc: true});
283 285
       return _serialize(val, options);
284 286
     }
285 287
   }
@@ -305,7 +307,8 @@ datatypes = {
305 307
   , serialize: function (input, options) {
306 308
       var val
307 309
         , opts = options || {};
308  
-      val = utils.date.strftime(input, '%T');
  310
+      val = utils.date.toUTC(input);
  311
+      val = utils.date.strftime(val, '%T');
309 312
       return _serialize(val, opts);
310 313
     }
311 314
   }
4  lib/index.js
@@ -377,6 +377,10 @@ utils.mixin(model, new (function () {
377 377
         , opts = args.shift() || {}
378 378
         , adapt;
379 379
 
  380
+      if (typeof query == 'string' || typeof query == 'number') {
  381
+        query = {id: query};
  382
+      }
  383
+
380 384
       query = new Query(model[name], query, opts);
381 385
 
382 386
       adapt = model.adapters[name];

0 notes on commit b1a86a0

Please sign in to comment.
Something went wrong with that request. Please try again.