Current section
16 Versions
Jump to
Current section
16 Versions
Compare versions
11
files changed
+142
additions
-42
deletions
| @@ -0,0 +1,15 @@ | |
| 1 | + # Xarango |
| 2 | + |
| 3 | + Copyright (c) Aug 1 2018 - Today Rebhu Computing |
| 4 | + |
| 5 | + Copyright (c) Oct 26 2016 - Jul 31 2018 Michel Benevento |
| 6 | + |
| 7 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + you may not use this file except in compliance with the License. |
| 9 | + You may obtain a copy of the license at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.) |
| 10 | + |
| 11 | + Unless required by applicable law or agreed to in writing, software |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + See the License for the specific language governing permissions and |
| 15 | + limitations under the License. |
| \ No newline at end of file |
| @@ -1,10 +1,11 @@ | |
| 1 | + # **We are not supporting this library anymore. We have migrated to another CouchDB due to issues while scaling up. Hope you find this work by Beno, us, and others useful. The project has been archived** |
| 2 | + |
| 1 3 | # Xarango |
| 2 4 | |
| 3 5 | Elixir client library for [ArangoDB](https://www.arangodb.com). |
| 4 6 | |
| 5 7 | Xarango has a low level API that maps directly to the Arango REST API. On top of that sits a `Domain` API, intended for use in applications. Examples below. |
| 6 8 | |
| 7 | - |
| 8 9 | ## Usage |
| 9 10 | |
| 10 11 | Configure xarango in `config/config.exs`: |
| @@ -48,10 +49,8 @@ Article.update(ipsum, %{status: "review"}) | |
| 48 49 | Article.replace(lorem, %{author: "Author", text: "Foo"}) |
| 49 50 | |
| 50 51 | Article.destroy(ipsum) |
| 51 | - |
| 52 52 | ``` |
| 53 53 | |
| 54 | - |
| 55 54 | ## Graphs |
| 56 55 | |
| 57 56 | ```elixir |
| @@ -83,8 +82,6 @@ Vehicles.remove_made_by(impreza, subaru) | |
| 83 82 | Vehicles.remove(outback, :made_by, subaru) |
| 84 83 | |
| 85 84 | Car.search(:name, "imp") #=> [%Car{...}] |
| 86 | - |
| 87 | - |
| 88 85 | ``` |
| 89 86 | |
| 90 87 | ## Transactions |
| @@ -121,6 +118,7 @@ See tests for low level usage examples. | |
| 121 118 | - [x] Full text search |
| 122 119 | - [x] AQL support, query builder |
| 123 120 | - [ ] waitForSync option |
| 121 | + - [ ] VelocyStream API |
| 124 122 | |
| 125 123 | ## Installation |
| 126 124 | |
| @@ -130,7 +128,7 @@ The package can be installed as: | |
| 130 128 | |
| 131 129 | ```elixir |
| 132 130 | def deps do |
| 133 | - [{:xarango, "~> 0.6.1"}] |
| 131 | + [{:xarango, git: "https://gitlab.com/Rebhu_Computing/open-source/xarango.git"}] |
| 134 132 | end |
| 135 133 | ``` |
| 136 134 | |
| @@ -141,3 +139,17 @@ The package can be installed as: | |
| 141 139 | [applications: [:xarango]] |
| 142 140 | end |
| 143 141 | ``` |
| 142 | + |
| 143 | + ## Documentation |
| 144 | + |
| 145 | + You can generate the documentation by simply running `mix docs` |
| 146 | + |
| 147 | + ## Why isn't the library available on Hex |
| 148 | + |
| 149 | + The original author `Michel Benevento` published this project. We are looking for ways to publish this project on **hex**, if you have some insights then share them in the [issue #1](https://gitlab.com/Rebhu_Computing/open-source/xarango/issues/1). |
| 150 | + |
| 151 | + ## When will you add more features |
| 152 | + |
| 153 | + We are a 2 member team of developers here at Rebhu Computing. As a result, we cannot support the project full-time. We are supporting the library on best efforts basis. Our priority is adding mission critical features and removing bugs from the library. We will add more HTTP API features in the future. |
| 154 | + |
| 155 | + **If you need a particular feature urgently then please fork the library, add tests, put the code, and open pull requests. We are actively accepting well written and tested PRs.** Read `STYLE-GUIDE.md` and `CONTRIBUTING.md` for more about practices. |
| \ No newline at end of file |
| @@ -1,11 +1,13 @@ | |
| 1 1 | {<<"app">>,<<"xarango">>}. |
| 2 2 | {<<"build_tools">>,[<<"mix">>]}. |
| 3 | - {<<"description">>,<<"Client library for ArangoDB.">>}. |
| 4 | - {<<"elixir">>,<<"~> 1.3">>}. |
| 3 | + {<<"description">>, |
| 4 | + <<"Client library for ArangoDB which uses HTTP for communication">>}. |
| 5 | + {<<"elixir">>,<<"~> 1.7">>}. |
| 5 6 | {<<"files">>, |
| 6 | - [<<"lib/xarango.ex">>,<<"lib/xarango/aql.ex">>,<<"lib/xarango/client.ex">>, |
| 7 | - <<"lib/xarango/collection.ex">>,<<"lib/xarango/database.ex">>, |
| 8 | - <<"lib/xarango/document.ex">>,<<"lib/xarango/domain/document.ex">>, |
| 7 | + [<<"lib">>,<<"lib/xarango">>,<<"lib/xarango.ex">>,<<"lib/xarango/aql.ex">>, |
| 8 | + <<"lib/xarango/client.ex">>,<<"lib/xarango/collection.ex">>, |
| 9 | + <<"lib/xarango/database.ex">>,<<"lib/xarango/document.ex">>, |
| 10 | + <<"lib/xarango/domain">>,<<"lib/xarango/domain/document.ex">>, |
| 9 11 | <<"lib/xarango/domain/graph.ex">>,<<"lib/xarango/domain/node.ex">>, |
| 10 12 | <<"lib/xarango/edge.ex">>,<<"lib/xarango/error.ex">>, |
| 11 13 | <<"lib/xarango/graph.ex">>,<<"lib/xarango/index.ex">>, |
| @@ -15,17 +17,21 @@ | |
| 15 17 | <<"lib/xarango/traversal.ex">>,<<"lib/xarango/uri.ex">>, |
| 16 18 | <<"lib/xarango/user.ex">>,<<"lib/xarango/util.ex">>, |
| 17 19 | <<"lib/xarango/vertex.ex">>,<<"mix.exs">>,<<"README.md">>,<<"LICENSE">>]}. |
| 18 | - {<<"licenses">>,[<<"Apache 2.0">>]}. |
| 19 | - {<<"links">>,[{<<"GitHub">>,<<"https://github.com/beno/xarango">>}]}. |
| 20 | - {<<"maintainers">>,[<<"Michel Benevento">>]}. |
| 20 | + {<<"licenses">>,[<<"Apache License, Version 2.0">>]}. |
| 21 | + {<<"links">>, |
| 22 | + [{<<"GitHub">>,<<"https://github.com/beno/xarango">>}, |
| 23 | + {<<"GitLab">>, |
| 24 | + <<"https://gitlab.com/Rebhu_Computing/open-source/xarango">>}]}. |
| 21 25 | {<<"name">>,<<"xarango">>}. |
| 22 26 | {<<"requirements">>, |
| 23 27 | [[{<<"app">>,<<"poison">>}, |
| 24 28 | {<<"name">>,<<"poison">>}, |
| 25 29 | {<<"optional">>,false}, |
| 26 | - {<<"requirement">>,<<"> 0.0.0">>}], |
| 30 | + {<<"repository">>,<<"hexpm">>}, |
| 31 | + {<<"requirement">>,<<"~> 3.1">>}], |
| 27 32 | [{<<"app">>,<<"httpoison">>}, |
| 28 33 | {<<"name">>,<<"httpoison">>}, |
| 29 34 | {<<"optional">>,false}, |
| 30 | - {<<"requirement">>,<<"> 0.0.0">>}]]}. |
| 31 | - {<<"version">>,<<"0.6.1">>}. |
| 35 | + {<<"repository">>,<<"hexpm">>}, |
| 36 | + {<<"requirement">>,<<"~> 1.0">>}]]}. |
| 37 | + {<<"version">>,<<"0.7.0">>}. |
| @@ -4,7 +4,7 @@ defmodule Xarango.Client do | |
| 4 4 | |
| 5 5 | [:get, :post, :put, :patch, :delete, :head, :options] |
| 6 6 | |> Enum.map(fn method -> |
| 7 | - def unquote(method)(url, body\\"") do |
| 7 | + def unquote(method)(url, body \\ "") do |
| 8 8 | case do_request(unquote(method), url, body) do |
| 9 9 | {:ok, body} -> body |
| 10 10 | {:error, error} -> Util.do_error error[:errorMessage] |
| @@ -12,7 +12,7 @@ defmodule Xarango.Client do | |
| 12 12 | end |
| 13 13 | end) |
| 14 14 | |
| 15 | - def _url(path, options\\[]) do |
| 15 | + def _url(path, options \\ []) do |
| 16 16 | Xarango.Server.server.server <> path <> query_params(options) |
| 17 17 | end |
| @@ -68,6 +68,53 @@ defmodule Xarango.Domain.Document do | |
| 68 68 | |> to_document |
| 69 69 | end |
| 70 70 | |
| 71 | + @doc """ |
| 72 | + ## Wthin geo search in collection |
| 73 | + Make sure you have a geo index on collection module |
| 74 | + ``` |
| 75 | + defmodule Station do |
| 76 | + index :geo, :location |
| 77 | + end |
| 78 | + ``` |
| 79 | + First argument it's a list with lat & lon, |
| 80 | + Second argument represent the radius within arango will search |
| 81 | + Third argument define a new column with distance in meters (filled by arango) |
| 82 | + `Station.within([47.632014, -122.207210], 100, :distance)` |
| 83 | + """ |
| 84 | + def within(geo, radius \\ 0, column \\ :distance) |
| 85 | + def within({latitude, longitude}, radius, column) do |
| 86 | + within([latitude, longitude], radius, column) |
| 87 | + end |
| 88 | + def within([latitude, longitude], radius, column) do |
| 89 | + %Xarango.Query{query: "FOR doc IN WITHIN(#{_collection().name}, #{latitude}, #{longitude}, #{radius}, \"#{Atom.to_string(column)}\") RETURN doc", batchSize: 3} |
| 90 | + |> Xarango.Query.query(_database()) |
| 91 | + |> Map.get(:result) |
| 92 | + |> to_document |
| 93 | + end |
| 94 | + @doc """ |
| 95 | + ## Near geo search in collection |
| 96 | + Make sure you have a geo index on collection module |
| 97 | + ``` |
| 98 | + defmodule Station do |
| 99 | + index :geo, :location |
| 100 | + end |
| 101 | + ``` |
| 102 | + First argument it's a list with lat & lon, |
| 103 | + Second argument limit results to only first n results |
| 104 | + Third argument define a new column with distance in meters (filled by arango) |
| 105 | + `Station.near([47.632014, -122.207210], 10, :distance)` |
| 106 | + """ |
| 107 | + def near(geo, limit \\ 0, column \\ :distance) |
| 108 | + def near({latitude, longitude}, limit, column) do |
| 109 | + near([latitude, longitude], limit, column) |
| 110 | + end |
| 111 | + def near([latitude, longitude], limit, column) do |
| 112 | + %Xarango.Query{query: "FOR doc IN NEAR(#{_collection().name}, #{latitude}, #{longitude}, #{limit}, \"#{Atom.to_string(column)}\") RETURN doc", batchSize: 3} |
| 113 | + |> Xarango.Query.query(_database()) |
| 114 | + |> Map.get(:result) |
| 115 | + |> to_document |
| 116 | + end |
| 117 | + |
| 71 118 | def fetch(document, field) do |
| 72 119 | case field do |
| 73 120 | :id -> {:ok, document.doc._id} |
| @@ -88,10 +135,6 @@ defmodule Xarango.Domain.Document do | |
| 88 135 | defp to_document(doc) do |
| 89 136 | struct(__MODULE__, doc: Document.to_document(doc)) |
| 90 137 | end |
| 91 | - |
| 92 | - |
| 93 138 | end |
| 94 139 | end |
| 95 | - |
| 96 | - |
| 97 140 | end |
Loading more files…