Open twolfson opened 9 years ago
I have added the datatype via defineType
and it looks like it's working great:
// Add in the JSON data type (`object` works with binary/string columns)
// https://github.com/dresende/node-orm2/wiki/Model-Properties#custom-types
db.defineType('json', {
datastoreType: function (prop) {
return 'JSON';
},
// https://github.com/dresende/node-orm2/blob/v2.1.20/lib/Drivers/DML/postgres.js#L247-L256
valueToProperty: function (value, prop) {
if (typeof value !== 'object') {
try {
value = JSON.parse(value);
} catch (err) {
value = null;
}
}
return value;
},
// https://github.com/dresende/node-orm2/blob/v2.1.20/lib/Drivers/DML/postgres.js#L317-L321
propertyToValue: function (value, prop) {
if (value !== null) {
value = JSON.stringify(value);
}
return value;
}
});
I am trying to get
orm
setup on an existing database that leverages JSON columns. It looks like theobject
type is saving to hexadecimal values. However, Postgres 9.3 doesn't like this. Can we remove this buffer escaping (prob not since we have #378) or add a new type calledjson
which doesn't encode into hex (a la #381)?