Coder Social home page Coder Social logo

xarango's Introduction

Xarango

Elixir client library for ArangoDB.

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.

Usage

Configure xarango in config/config.exs:

    config :xarango, :db,
      server: "http://localhost:8529",
      database: "test_db",
      username: System.get_env("ARANGO_USER"),
      password: System.get_env("ARANGO_PASSWORD")

Set your credentials:

$ export ARANGO_USER=root
$ export ARANGO_PASSWORD=secret

Run tests:

mix test # <= beware: running tests will destroy all data in the configured database.

Documents

defmodule Article, do: use Xarango.Domain.Document

lorem = Article.create(%{author: "Author", text: "Lorem"})
ipsum = Article.create(%{author: "Author", text: "Ipsum"})

IO.inspect lorem[:text] #=> "Lorem"

Article.one(%{author: "Author"}) #=> %Article{...}
Article.list(%{author: "Author"}) #=> [%Article{...}, %Article{...}]

Article.update(ipsum, %{status: "review"})
Article.replace(lorem, %{author: "Author", text: "Foo"})

Article.destroy(ipsum)

Graphs

defmodule Brand, do: use Xarango.Domain.Node
defmodule Car, do: use Xarango.Domain.Node, graph: Vehicles
defmodule Vehicles do
  use Xarango.Domain.Graph
  
  relationship Car, :made_by, Brand
end

subaru = Brand.create(%{name: "Subaru"}, graph: Vehicles)
outback = Car.create(%{type: "Outback"})
impreza = Car.create(%{type: "Impreza"})

subaru[:name] #=> "Subaru"
outback[:type] #=> "Outback"

Vehicles.add_made_by(outback, subaru)
Vehicles.add(impreza, :made_by, subaru)

Vehicles.car_made_by(subaru) #=> [%Car{...}, %Car{...}] #outbound edges for car
Vehicles.get(Car, :made_by, subaru) #=> [%Car{...}, %Car{...}] 

Vehicles.made_by_brand(outback) #=> [%Brand{...}]
Vehicles.get(outback, :made_by, Brand) #=> [%Brand{...}

Vehicles.remove_made_by(impreza, subaru)
Vehicles.remove(outback, :made_by, subaru)

Transactions

defmodule Brand, do: use Xarango.Domain.Node, graph: Vehicles
defmodule Car, do: use Xarango.Domain.Node, graph: Vehicles
defmodule Vehicles do
  use Xarango.Domain.Graph

  relationship Car, :made_by, Brand
end

alias Xarango.Transaction

Transaction.begin(Vehicles)
|> Transaction.create(Car, %{name: "Foo"}, var: :car1)
|> Transaction.create(Car, %{name: "Bar"}, var: :car2)
|> Transaction.create(Brand, %{name: "Baz"}, var: :brand)
|> Transaction.add(:car1, :made_by, :brand)
|> Transaction.add(:car2, :made_by, :brand)
|> Transaction.get(Car, :made_by, :brand)
|> Transaction.execute #=> [%Car{vertex: ...}, %Car{vertex: ...}]

Low level API

See tests for low level usage examples.

Todo

  • Transactions
  • Graph operations
  • Sync/Async

Installation

The package can be installed as:

  1. Add xarango to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:xarango, "~> 0.4.1"}]
end
```
  1. Ensure xarango is started before your application:
```elixir
def application do
  [applications: [:xarango]]
end
```

xarango's People

Contributors

beno avatar pinx avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.