mirror of https://github.com/poanetwork/rox.git
feat(): add count/1
This commit is contained in:
parent
07bfefc49a
commit
7ee6cd3a53
12
lib/rox.ex
12
lib/rox.ex
|
@ -276,4 +276,16 @@ defmodule Rox do
|
||||||
|
|
||||||
Keyword.merge(rest, converted)
|
Keyword.merge(rest, converted)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Return the approximate number of keys in the default column family.
|
||||||
|
|
||||||
|
Implemented by calling GetIntProperty with `rocksdb.estimate-num-keys`
|
||||||
|
|
||||||
|
"""
|
||||||
|
@spec count(db_handle) :: non_neg_integer | {:error, any}
|
||||||
|
def count(db) do
|
||||||
|
:erocksdb.count(db)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,4 +46,12 @@ defmodule RoxTest do
|
||||||
|
|
||||||
Rox.stream_keys(db) |> Enum.take(1)
|
Rox.stream_keys(db) |> Enum.take(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "count", %{db: db} do
|
||||||
|
count =
|
||||||
|
Rox.count(db)
|
||||||
|
|
||||||
|
assert is_number(count)
|
||||||
|
assert count >= 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue