Set Meta Data to badger


(vladimir) #1

Hello.
Can somebody add examples?
How I can add metadata to method set to badger.
And how I can get metadata from key in db.
Regards.


(Daniel Mai) #2

Does the documentation for SetWithMeta help? https://github.com/dgraph-io/badger#setting-time-to-livettl-and-user-metadata-on-keys

As well as the docstring and implementation for SetWithMeta? https://github.com/dgraph-io/badger/blob/ed2529abad4cd69c354144dc811206960bb4173c/transaction.go#L305-L317


(vladimir) #3

Thank’s.
But meta is byte. Can I add some string data to meta?
For example, I have:
key - “string” & value - map[string]string or map[int]int (with json.Marshal)
I need to add type of map to meta (map[int]string). How I can do this?
How I can get meta from key-value pair?


(Daniel Mai) #4

What you can do is set bit fields that indicate the type of the value, e.g.,

mapStringString = 0x01
mapStringInt = 0x02

and then use those for value type checking.