Open kapouer opened 10 years ago
There is a binary type, you can do this:
var Person = db.define("person", {
photo: Buffer
});
Okay, Buffer is for binary. But then i don't understand why object is handled the same as binary.
Also, "Object" cannot always be serialized. "JSON" might be a better name.
It was initially called "object" because you could use Object
to define it (instead of "type": "object"
) and because actually JSON is a simplified javascript object. :)
They are usually handled the same way (when storing them) because databases don't support it, but as you said mongo does. As for postgresql, if you know a way of detecting if the server has native support we could change it. An alternative is using a custom type (see test/integration/property-custom.js
for an example).
At least it should be impossible to put a Buffer instance inside a column accepting objects; so it will eventually be possible to make the distinction between json and binary blobs.
Note that {mycol: JSON} would have worked instead of {mycol: Object}. That's less important ;)
There seems to be a confusion in the definition of types: Object represents both JSON or Buffer. They are really different: JSON can be stringified, or in some cases is even a supported database type (postgres 9.3 and of course mongo) while Buffer calls for a binary representation. I suggest orm provides two distinct types, allowing for better usage of existing types in underlying databases. It also improves readability of data in the database itself.