Skip to content

Support for arbitrary keys and values #19

@dodoplus

Description

@dodoplus

It seems that this module only supports Vector{UInt8} keys and values, which makes it pretty unusable.

Why not add support for general types?

E.g. something like:

using LevelDB
using Serialization

function obj2buf(t::T) where T
    io = IOBuffer()
    serialize(io, t)
    return take!(io)
end

buf2obj(v::Vector{UInt8}) = deserialize(IOBuffer(v))

Base.setindex!(db::LevelDB.DB, i::T, v::S) where {T,S} = Base.setindex!(db, obj2buf(i), obj2buf(v))
Base.getindex(db::LevelDB.DB, i::T) where T = buf2obj(Base.getindex(db, obj2buf(i)))

...

db = LevelDB.DB("level.db", create_if_missing = true)
db["aa"] = "bb"
db["aa"]
# "aa"

Obviously, a faster/more stable serialization should be used -- e.g. code from JLD2 could be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions