I would like to use OrientDB as a database for .csv files and store these in the original form in a binary field of a record using OrientJS. Additionally, I would like to store a name and a description as Strings. I worked through the documentation and was able to store raw binary records via
var fs = require('fs');
var testcsv = fs.readFile('test.csv',
function(error, data){
if(error) throw error;
var binary = new Buffer(data);
binary['@type'] = 'b';
binary['@class']='CSV';
db.record.create(binary);
})
However, I have found no way to store a record with a field of the type "Binary". I tried several ways, all of which do not seem to work. E.g.:
var fs = require('fs');
var testcsv = fs.readFile('test.csv',
function(error, data){
if(error) throw error;
var binary = new Buffer(data);
binary['@type'] = 'b';
binary['@class']='CSV';
db.record.create({
'@class': 'Test',
'file': binary,
'name': 'X',
'description': 'Y'
});
})
If 'field' is not declared as 'Binary' it gets set to the type 'Embedded' by default and the .csv is "stored". If 'field' is declared as 'Binary' an error is thrown:
Unhandled rejection OrientDB.RequestError: Error on unmarshalling field 'file' in record #22:-1 with value: file: ...
DB name="mydb"
at child.Operation.parseError (...node_modules\orientjs\lib\transport\binary\protocol33\operation.js:864:13)
at child.Operation.consume (...node_modules\orientjs\lib\transport\binary\protocol33\operation.js:455:35)
at Connection.process (...node_modules\orientjs\lib\transport\binary\connection.js:399:17)
at Connection.handleSocketData (...node_modules\orientjs\lib\transport\binary\connection.js:290:20)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)
As I tried many other ways I am left clueless. Am I misunderstanding something? Help is greatly appreciated!