Skip to content

Commit

Permalink
Merge pull request #46 from dovadi/master
Browse files Browse the repository at this point in the history
Remove aliases with/1 so it will compile with Elixir 1.2
  • Loading branch information
robconery committed Jan 2, 2016
2 parents dc95ec4 + 5991b75 commit 9ea745c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 38 deletions.
5 changes: 0 additions & 5 deletions lib/moebius/document_query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ defmodule Moebius.DocumentQuery do
def db(table),
do: %Moebius.DocumentCommand{table_name: table}

@doc """
An alias for db
"""
def with(table), do: db(table)

@doc """
This is analagous to `filter` with the Query module, however this method is highly optimized for JSONB as it uses the `@` (contains)
operator. This flexes the GIN index created for your table (see above).
Expand Down
26 changes: 0 additions & 26 deletions lib/moebius/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,6 @@ defmodule Moebius.Query do
def db(table),
do: %Moebius.QueryCommand{table_name: table}


@doc """
Specifies the table or view you want to query and is an alias for the `db/1` function using
a string or atom as a table name. This is useful for specifying a table within a schema.
"table" - the name of the table you want to query, such as `membership.users`
:table - the name of the table you want to query, such as `:users`
Example
```
result = with("membership.users")
|> to_list
result = with(:users)
|> to_list
```
"""
def with(table) when is_atom(table),
do: db(table)

def with(table),
do: db(table)



@doc """
Searches for a record based on an `id` primary key.
Expand Down
6 changes: 3 additions & 3 deletions test/moebius/document_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ defmodule Moebius.DocTest do
test "executes a transaction" do

transaction fn(pid) ->
with(:monkies)
db(:monkies)
|> save(pid, name: "Peaches", company: "Microsoft")

with(:cars)
db(:cars)
|> save(pid, name: "Toyota")

with(:user_docs)
db(:user_docs)
|> save(pid, name: "bubbles")

end
Expand Down
8 changes: 4 additions & 4 deletions test/moebius/transaction_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ defmodule Moebius.TransactionTest do

result = transaction fn(pid) ->

new_user = with(:users)
new_user = db(:users)
|> insert(pid, email: "[email protected]")

with(:logs)
db(:logs)
|> insert(pid, user_id: new_user.id, log: "Hi Frodo")

new_user
Expand All @@ -40,10 +40,10 @@ defmodule Moebius.TransactionTest do
assert{:error, "insert or update on table \"logs\" violates foreign key constraint \"logs_user_id_fkey\""}
= transaction fn(pid) ->

new_user = with(:users)
new_user = db(:users)
|> insert(pid,email: "[email protected]")

with(:logs)
db(:logs)
|> insert(pid,user_id: 22222, log: "Hi Bilbo")

new_user
Expand Down

0 comments on commit 9ea745c

Please sign in to comment.