Skip to content

Commit

Permalink
Rename Query.create/1 to Query.build/1
Browse files Browse the repository at this point in the history
  • Loading branch information
whitfin committed Sep 14, 2024
1 parent e81dc03 commit 74efdec
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions lib/cachex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1242,21 +1242,21 @@ defmodule Cachex do
{:entry, "c", 1519015805679, nil, 3},
{:entry, "a", 1519015794445, nil, 1}]
iex> query = Cachex.Query.create(output: :key)
iex> query = Cachex.Query.build(output: :key)
iex> :my_cache |> Cachex.stream!(query) |> Enum.to_list
["b", "c", "a"]
iex> query = Cachex.Query.create(output: :value)
iex> query = Cachex.Query.build(output: :value)
iex> :my_cache |> Cachex.stream!(query) |> Enum.to_list
[2, 3, 1]
iex> query = Cachex.Query.create(output: {:key, :value})
iex> query = Cachex.Query.build(output: {:key, :value})
iex> :my_cache |> Cachex.stream!(query) |> Enum.to_list
[{"b", 2}, {"c", 3}, {"a", 1}]
"""
@spec stream(Cachex.t(), any, Keyword.t()) :: {status, Enumerable.t()}
def stream(cache, query \\ Q.create(where: Q.unexpired()), options \\ [])
def stream(cache, query \\ Q.build(where: Q.unexpired()), options \\ [])
when is_list(options),
do: Router.route(cache, {:stream, [query, options]})

Expand Down
2 changes: 1 addition & 1 deletion lib/cachex/actions/count.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Cachex.Actions.Count do
"""
def execute(cache(name: name), _options) do
filter = Query.unexpired()
clause = Query.create(where: filter, output: true)
clause = Query.build(where: filter, output: true)

{:ok, :ets.select_count(name, clause)}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cachex/actions/export.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Cachex.Actions.Export do
to the memory overhead involved, as well as the large concatenations.
"""
def execute(cache() = cache, _options) do
with {:ok, stream} <- CachexStream.execute(cache, Query.create(), []) do
with {:ok, stream} <- CachexStream.execute(cache, Query.build(), []) do
{:ok, Enum.to_list(stream)}
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/cachex/actions/inspect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule Cachex.Actions.Inspect do
# number of expired records which have already been purged or removed.
def execute(cache(name: name), {:expired, :count}, _options) do
filter = Query.expired()
clause = Query.create(where: filter, output: true)
clause = Query.build(where: filter, output: true)

{:ok, :ets.select_count(name, clause)}
end
Expand All @@ -96,7 +96,7 @@ defmodule Cachex.Actions.Inspect do
# an expensive call and should really only be used when debugging.
def execute(cache(name: name), {:expired, :keys}, _options) do
filter = Query.expired()
clause = Query.create(where: filter, output: :key)
clause = Query.build(where: filter, output: :key)

{:ok, :ets.select(name, clause)}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cachex/actions/keys.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Cachex.Actions.Keys do
"""
def execute(cache(name: name), _options) do
filter = Query.unexpired()
clause = Query.create(where: filter, output: :key)
clause = Query.build(where: filter, output: :key)

{:ok, :ets.select(name, clause)}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cachex/actions/purge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Cachex.Actions.Purge do
def execute(cache(name: name) = cache, _options) do
Locksmith.transaction(cache, [], fn ->
filter = Query.expired()
clause = Query.create(where: filter, output: true)
clause = Query.build(where: filter, output: true)

{:ok, :ets.select_delete(name, clause)}
end)
Expand Down
2 changes: 1 addition & 1 deletion lib/cachex/actions/save.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule Cachex.Actions.Save do

# Use a local stream to lazily walk through records on a local cache.
defp init_stream(local, router, cache, batch) when local or router == Local,
do: CachexStream.execute(cache, Query.create(), batch_size: batch)
do: CachexStream.execute(cache, Query.build(), batch_size: batch)

# Generate an export of all nodes in a distributed cluster via `Cachex.export/2`
defp init_stream(_local, _router, cache, _batch),
Expand Down
2 changes: 1 addition & 1 deletion lib/cachex/policy/lrw.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Cachex.Policy.LRW do
alias Cachex.Services.Informant

# compile our match to avoid recalculating
@ets_match Query.create(output: {:key, :modified})
@ets_match Query.build(output: {:key, :modified})

####################
# Policy Behaviour #
Expand Down
4 changes: 2 additions & 2 deletions lib/cachex/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ defmodule Cachex.Query do
`:expired` flag for convenience.
"""
@spec create(options :: Keyword.t()) :: [{tuple, [tuple], [any]}]
def create(options \\ []),
@spec build(options :: Keyword.t()) :: [{tuple, [tuple], [any]}]
def build(options \\ []),
do: [
{
@header,
Expand Down
4 changes: 2 additions & 2 deletions test/cachex/actions/stream_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ defmodule Cachex.Actions.StreamTest do
filter = Cachex.Query.unexpired()

# create two test queries
query1 = Cachex.Query.create(where: filter, output: {:key, :value})
query2 = Cachex.Query.create(where: filter, output: :key)
query1 = Cachex.Query.build(where: filter, output: {:key, :value})
query2 = Cachex.Query.build(where: filter, output: :key)

# create cache streams
{:ok, stream1} = Cachex.stream(cache, query1)
Expand Down
16 changes: 8 additions & 8 deletions test/cachex/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defmodule Cachex.QueryTest do

test "creating basic queries" do
# create a query with not filter
query1 = Cachex.Query.create()
query2 = Cachex.Query.create(output: :key)
query1 = Cachex.Query.build()
query2 = Cachex.Query.build(output: :key)

# verify the mapping of both queries
assert [{{:_, :"$1", :"$2", :"$3", :"$4"}, _, _}] = query1
Expand All @@ -25,9 +25,9 @@ defmodule Cachex.QueryTest do
filter2 = Cachex.Query.expired(false)

# create a couple of expired queries
clause1 = Cachex.Query.create(where: filter1)
clause2 = Cachex.Query.create(where: filter1, output: :key)
clause3 = Cachex.Query.create(where: filter2)
clause1 = Cachex.Query.build(where: filter1)
clause2 = Cachex.Query.build(where: filter1, output: :key)
clause3 = Cachex.Query.build(where: filter2)

# verify the mapping of both queries
assert [{{:_, :"$1", :"$2", :"$3", :"$4"}, _, _}] = clause1
Expand Down Expand Up @@ -56,9 +56,9 @@ defmodule Cachex.QueryTest do
filter2 = Cachex.Query.unexpired(false)

# create a couple of unexpired queries
clause1 = Cachex.Query.create(where: filter1)
clause2 = Cachex.Query.create(where: filter1, output: :key)
clause3 = Cachex.Query.create(where: filter2)
clause1 = Cachex.Query.build(where: filter1)
clause2 = Cachex.Query.build(where: filter1, output: :key)
clause3 = Cachex.Query.build(where: filter2)

# verify the mapping of both queries
assert [{{:_, :"$1", :"$2", :"$3", :"$4"}, _, _}] = clause1
Expand Down

0 comments on commit 74efdec

Please sign in to comment.