mirror of https://github.com/poanetwork/rox.git
feat(): add put
This commit is contained in:
parent
33d65794ab
commit
0cf7b74375
37
lib/rox.ex
37
lib/rox.ex
|
@ -4,6 +4,9 @@ defmodule Rox do
|
||||||
@type compaction_style :: :level | :universal | :fifo | :none
|
@type compaction_style :: :level | :universal | :fifo | :none
|
||||||
@type compression_type :: :snappy | :zlib | :bzip2 | :lz4 | :lz4h | :none
|
@type compression_type :: :snappy | :zlib | :bzip2 | :lz4 | :lz4h | :none
|
||||||
|
|
||||||
|
@type key :: String.t | binary
|
||||||
|
@type value :: String.t | binary
|
||||||
|
|
||||||
@type db_handle :: binary
|
@type db_handle :: binary
|
||||||
@type cf_handle :: binary
|
@type cf_handle :: binary
|
||||||
@type itr_handle :: binary
|
@type itr_handle :: binary
|
||||||
|
@ -122,17 +125,17 @@ defmodule Rox do
|
||||||
]
|
]
|
||||||
|
|
||||||
@type write_actions :: [
|
@type write_actions :: [
|
||||||
{:put, key :: binary, value :: binary} |
|
{:put, key, value} |
|
||||||
{:put, cf_handle, key :: binary, value :: binary} |
|
{:put, cf_handle, key, value} |
|
||||||
{:delete, key :: binary} |
|
{:delete, key} |
|
||||||
{:delete, cf_handle, key :: binary} |
|
{:delete, cf_handle, key} |
|
||||||
:clear
|
:clear
|
||||||
]
|
]
|
||||||
|
|
||||||
@type iterator_action :: :first | :last | :next | :prev | binary
|
@type iterator_action :: :first | :last | :next | :prev | binary
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Open a RocksDB with the specified read options
|
Open a RocksDB with the specified read options and column family options
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@spec open(path :: file_path, db_opts :: db_options, cf_opts :: cf_options) :: {:ok, db_handle} | {:error, any}
|
@spec open(path :: file_path, db_opts :: db_options, cf_opts :: cf_options) :: {:ok, db_handle} | {:error, any}
|
||||||
|
@ -140,6 +143,30 @@ defmodule Rox do
|
||||||
:erocksdb.open(to_charlist(path), sanitize_opts(db_opts), sanitize_opts(cf_opts))
|
:erocksdb.open(to_charlist(path), sanitize_opts(db_opts), sanitize_opts(cf_opts))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Put a key/value pair into the default column family handle
|
||||||
|
"""
|
||||||
|
|
||||||
|
@spec put(db_handle, key, value) :: :ok | {:error, any}
|
||||||
|
def put(db, key, value), do:
|
||||||
|
:erocksdb.put(db, key, value, [])
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Put a key/value pair into the default column family handle with the provided
|
||||||
|
write options
|
||||||
|
"""
|
||||||
|
|
||||||
|
@spec put(db_handle, key, value, write_options) :: :ok | {:error, any}
|
||||||
|
def put(db, key, value, write_opts) when is_list(write_opts), do:
|
||||||
|
:erocksdb.put(db, key, value, write_opts)
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Put a key/value pair into the specified column family with optional `write_options`
|
||||||
|
"""
|
||||||
|
@spec put(db_handle, cf_handle, key, value, write_options) :: :ok | {:error, any}
|
||||||
|
def put(db, cf, key, value, write_opts \\ []), do:
|
||||||
|
:erocksdb.put(db, cf, key, value, write_opts)
|
||||||
|
|
||||||
defp sanitize_opts(opts) do
|
defp sanitize_opts(opts) do
|
||||||
[ raw, rest ] = Keyword.split(opts, @opts_to_convert_to_bitlists)
|
[ raw, rest ] = Keyword.split(opts, @opts_to_convert_to_bitlists)
|
||||||
converted = Enum.map(raw, fn {k, val} -> {k, to_charlist(val)} end)
|
converted = Enum.map(raw, fn {k, val} -> {k, to_charlist(val)} end)
|
||||||
|
|
Loading…
Reference in New Issue