From 7ee6cd3a5367db60dba89af3bdd1a206f9b10820 Mon Sep 17 00:00:00 2001 From: Ryan Schmukler Date: Tue, 24 Jan 2017 16:50:37 -0500 Subject: [PATCH] feat(): add count/1 --- lib/rox.ex | 12 ++++++++++++ test/rox_test.exs | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/rox.ex b/lib/rox.ex index a4eb161..671a298 100644 --- a/lib/rox.ex +++ b/lib/rox.ex @@ -276,4 +276,16 @@ defmodule Rox do Keyword.merge(rest, converted) 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 diff --git a/test/rox_test.exs b/test/rox_test.exs index fd5a78b..ea0b640 100644 --- a/test/rox_test.exs +++ b/test/rox_test.exs @@ -46,4 +46,12 @@ defmodule RoxTest do Rox.stream_keys(db) |> Enum.take(1) end + + test "count", %{db: db} do + count = + Rox.count(db) + + assert is_number(count) + assert count >= 0 + end end