summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ebin/fabric.app1
-rw-r--r--src/fabric.erl19
-rw-r--r--src/fabric_all_databases.erl36
3 files changed, 15 insertions, 41 deletions
diff --git a/ebin/fabric.app b/ebin/fabric.app
index 6750766b..716591d1 100644
--- a/ebin/fabric.app
+++ b/ebin/fabric.app
@@ -5,7 +5,6 @@
{vsn, "1.0"},
{modules, [
fabric,
- fabric_all_databases,
fabric_db_create,
fabric_db_delete,
fabric_db_doc_count,
diff --git a/src/fabric.erl b/src/fabric.erl
index 892673a5..9158b9e9 100644
--- a/src/fabric.erl
+++ b/src/fabric.erl
@@ -23,10 +23,21 @@
% db operations
all_dbs() ->
- fabric_all_databases:all_databases("").
-
-all_dbs(Customer) ->
- fabric_all_databases:all_databases(Customer).
+ all_dbs(<<>>).
+
+all_dbs(Prefix) when is_list(Prefix) ->
+ all_dbs(list_to_binary(Prefix));
+all_dbs(Prefix) when is_binary(Prefix) ->
+ Length = byte_size(Prefix),
+ MatchingDbs = ets:foldl(fun(#shard{dbname=DbName}, Acc) ->
+ case DbName of
+ <<Prefix:Length/binary, _/binary>> ->
+ [DbName | Acc];
+ _ ->
+ Acc
+ end
+ end, [], partitions),
+ {ok, lists:usort(MatchingDbs)}.
get_db_info(DbName) ->
fabric_db_info:go(dbname(DbName)).
diff --git a/src/fabric_all_databases.erl b/src/fabric_all_databases.erl
deleted file mode 100644
index e16429b1..00000000
--- a/src/fabric_all_databases.erl
+++ /dev/null
@@ -1,36 +0,0 @@
--module(fabric_all_databases).
-
--export([all_databases/1]).
-
--include("fabric.hrl").
--include_lib("mem3/include/mem3.hrl").
-
-%% @doc gets all databases in the cluster.
--spec all_databases(string()) -> {ok, [binary()]}.
-all_databases([]) ->
- Dbs = ets:foldl(fun(#shard{dbname=DbName}, AccIn) ->
- new_acc(DbName, AccIn)
- end, [], partitions),
- {ok, Dbs};
-all_databases(Customer) ->
- ?debugFmt("~nCustomer: ~p~n", [Customer]),
- Dbs = ets:foldl(fun(#shard{dbname=DbName}, AccIn) ->
- DbNameStr = binary_to_list(DbName),
- case string:str(DbNameStr, Customer) of
- 1 ->
- new_acc(DbNameStr, AccIn);
- _ -> AccIn
- end
- end, [], dbs_cache),
- {ok, Dbs}.
-
-
-%% =====================
-%% internal
-%% =====================
-
-new_acc(DbName, Acc) ->
- case lists:member(DbName, Acc) of
- true -> Acc;
- _ ->[DbName | Acc]
- end.