Skip to content

Commit 830a0c2

Browse files
mango-database: add partition paths
1 parent 1f7d7a2 commit 830a0c2

1 file changed

Lines changed: 24 additions & 20 deletions

File tree

test/elixir/test/support/mango_database.ex

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -165,29 +165,33 @@ defmodule MangoDatabase do
165165
r: 1,
166166
conflicts: false,
167167
explain: false,
168-
return_raw: false
168+
return_raw: false,
169+
partition: false,
169170
]
170171
options = Keyword.merge(defaults, opts)
171172

172-
path =
173-
case options[:explain] do
174-
true -> "/#{db}/_explain"
175-
_ -> "/#{db}/_find"
176-
end
177-
178-
resp = Couch.post(path, body: %{
179-
"selector" => selector,
180-
"use_index" => options[:use_index],
181-
"skip" => options[:skip],
182-
"limit" => options[:limit],
183-
"r" => options[:r],
184-
"conflicts" => options[:conflicts]
185-
}
186-
|> put_if_set("sort", options, :sort)
187-
|> put_if_set("fields", options, :fields)
188-
|> put_if_set("execution_stats", options, :executionStats)
189-
|> put_if_set("allow_fallback", options, :allow_fallback)
190-
)
173+
ppath =
174+
if options[:partition],
175+
do: "_partition/#{options[:partition]}/",
176+
else: ""
177+
178+
suffix = if options[:explain], do: "_explain", else: "_find"
179+
path = "/#{db}/#{ppath}#{suffix}"
180+
181+
resp =
182+
Couch.post(path, body: %{
183+
"selector" => selector,
184+
"use_index" => options[:use_index],
185+
"skip" => options[:skip],
186+
"limit" => options[:limit],
187+
"r" => options[:r],
188+
"conflicts" => options[:conflicts]
189+
}
190+
|> put_if_set("sort", options, :sort)
191+
|> put_if_set("fields", options, :fields)
192+
|> put_if_set("execution_stats", options, :executionStats)
193+
|> put_if_set("allow_fallback", options, :allow_fallback)
194+
)
191195

192196
case {(options[:explain] or options[:return_raw]), resp.status_code} do
193197
{false, 200} -> {:ok, resp.body["docs"]}

0 commit comments

Comments
 (0)