Skip to content

Commit

Permalink
fixed datatype other to correctly handle null values. removed entity …
Browse files Browse the repository at this point in the history
…cache from json tests to avoid testing cached values
  • Loading branch information
Robert Gaggl committed Apr 26, 2016
1 parent 4f096f2 commit ce377a6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
29 changes: 16 additions & 13 deletions lib/datatypes/other.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@
exports.get = function(resultSet, idx) {
var obj = resultSet.getObject(idx);

// Postgres special types not covered by JDBC
if (obj instanceof Packages.org.postgresql.util.PGobject) {
var type = obj.getType();
switch (type) {
case "json":
case "jsonb":
obj = JSON.parse(obj.toString());
break;
default:
throw new Error("Unsupported data type: " + type);
if (obj !== null) {
// Postgres special types not covered by JDBC
if (obj instanceof Packages.org.postgresql.util.PGobject) {
var type = obj.getType();
switch (type) {
case "json":
case "jsonb":
obj = JSON.parse(obj.toString());
break;
default:
throw new Error("Unsupported data type: " + type);
}
return obj;
} else {
throw new Error("Unsupported object data type: " + obj.toString());
}
return obj;
} else {
throw new Error("Unsupported object data type: " + obj.toString());
}
return obj;
};

/**
Expand Down
14 changes: 13 additions & 1 deletion test/postgresql/datatype_json_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var store, Event, EventB;

exports.setUp = function() {
store = new Store(Store.initConnectionPool(config.postgresql));
store.setEntityCache(new Cache());
Event = store.defineEntity("Event", MAPPING_EVENT_JSON);
EventB = store.defineEntity("EventB", MAPPING_EVENT_JSONB);
store.syncTables();
Expand Down Expand Up @@ -56,6 +55,19 @@ exports.testSaveObject = function() {
assert.strictEqual(EventB.all().length, 1);
};

exports.testGetSetNull = function() {
var values = [null, undefined];
for each (let value in values) {
let event = new Event({
"slog": "some event",
"data": value
});
event.save();
assert.isNotNull(Event.get(event.id, true));
assert.isNull(Event.get(event.id, true).data);
}
};

exports.testQueryObjects = function() {
// populate the tables
store.beginTransaction();
Expand Down

0 comments on commit ce377a6

Please sign in to comment.