How to store and retrieve binary data in orientdb using pyorient?

406 Views Asked by At

I was trying to follow the examples given in the github Readme of pyorient. I tried to insert a binary field using client.record_create and load the same using client.record_load.

>>> client.db_create('animals', pyorient.DB_TYPE_DOCUMENT, pyorient.STORAGE_TYPE_MEMORY )
>>> cluster_id = client.command("create class animal")
>>> rec = { '@animal': { 'accommodation': 'house1', 'work': 'office1', 'holiday': b'\xb8P\xa7\x00l|\xa7\x13\x8d\xc8\x80_M\xa0\x11V\xe3 ,G\x1d\xad \x08\xf5rZ\xafc\x16\x1c(' } }  
>>> rec_position = client.record_create( cluster_id[0], rec )
>>> loaded = client.record_load(rec_position._rid)
>>> loaded.oRecordData
{'holiday': None, 'work': 'office1', 'accommodation': 'house1'}

As you can see, the value of the binary field retrieved is None. Does pyorient support insertion of raw bytes? If not, is there some workaround?

1

There are 1 best solutions below

1
On

not sure if the result is correct, but you may try adding the " "

>>> rec = { '@animal': { 'accommodation': 'house1', 'work': 'office1', 'holiday': "b'\xb8P\xa7\x00l|\xa7\x13\x8d\xc8\x80_M\xa0\x11V\xe3 ,G\x1d\xad \x08\xf5rZ\xafc\x16\x1c('" } }