Skip to content

Commit 93f1539

Browse files
committed
Remove support for javascript queries
1 parent 8e5c1df commit 93f1539

4 files changed

Lines changed: 0 additions & 75 deletions

File tree

lib/mongo_ecto/helpers.ex

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,6 @@ defmodule Mongo.Ecto.Helpers do
44
where you work with them. You'd probably want to import it.
55
"""
66

7-
@doc """
8-
Allows using inline JavaScript in queries in where clauses and inserting it
9-
as a value to the database.
10-
11-
The second argument acts as a context for the function. All values will be
12-
converted to valid BSON types.
13-
14-
Raises ArgumentError if any of the values cannot be converted.
15-
16-
## Usage in queries
17-
18-
from p in Post,
19-
where: ^javascript("this.value === value", value: 1)
20-
"""
21-
@spec javascript(String.t, Keyword.t) :: Mongo.Ecto.JavaScript.t
22-
def javascript(code, scope \\ []) do
23-
%Mongo.Ecto.JavaScript{code: code, scope: scope}
24-
end
25-
267
@doc """
278
Creates proper regex object that can be passed to the database.
289

lib/mongo_ecto/java_script.ex

Lines changed: 0 additions & 44 deletions
This file was deleted.

lib/mongo_ecto/normalized_query.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,6 @@ defmodule Mongo.Ecto.NormalizedQuery do
422422
end
423423
defp pair({:^, _, _} = expr, params, pk, query, place) do
424424
case value(expr, params, pk, query, place) do
425-
%BSON.JavaScript{} = js ->
426-
{:"$where", js}
427425
bool when is_boolean(bool) ->
428426
boolean_query_hack_pair(bool)
429427
_value ->

test/mongo_ecto_test.exs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ defmodule Mongo.EctoTest do
2121
assert [] == TestRepo.all(Post)
2222
end
2323

24-
# TODO: The ecto library requires that we pass a keyword list to the where
25-
# clause. Fix this once I understand more how this works.
26-
test "javascript in query" do
27-
TestRepo.insert!(%Post{visits: 1})
28-
29-
js = javascript("this.visits == count", count: 1)
30-
31-
assert [%Post{}] = TestRepo.all(from p in Post, where: ^js)
32-
end
33-
3424
test "regex in query" do
3525
p1 = TestRepo.insert!(%Post{title: "some text"})
3626
p2 = TestRepo.insert!(%Post{title: "other text"})

0 commit comments

Comments
 (0)