experimental gremlin pacer like graph traversals
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
lib
test
LICENSE
README.md
TODO
mix.exs

README.md

Trabant

** naive graph traversal for erlang and some backends like digraph dynamodb and mdigraph

Setup

  • configure your configs

1. config/dev.exs

use Mix.Config

config :ex_aws,
  dynamodb: [
    host: "localhost",
    scheme: "http://",
    port: "8000"
    ],
  access_key_id: "abc #{__MODULE__}#{Mix.env}",
  secret_access_key: "abc #{__MODULE__}#{Mix.env}"

2. add httpoison to applications in mix.exs

def application do
    [mod: {BlogTrabant, []},
     applications: [:phoenix, :phoenix_html, :cowboy, :logger,:httpoison]]
  end

3. Add dependencies in mix.exs

  defp deps do
    [
      {:timex, "~> 0.19.2"}
      {:trabant,github: "jschoch/trabant"}
    ]
  end

4. add the backend config to your config

config/config.ex

config Trabant, backend: Ddb

5. setup your tests to clean up your db if you want

  import Trabant
  setup_all do
    Trabant.backend(Ddb)
  end
  setup do
    case Mix.env do
      :prod -> raise "can't delete prod for tests fool"
      _ ->
        delete_graph
        new
    end
    :ok
  end
    
    # change the backend, this one uses mnesia
    Trabant.backend(Mdigraph)

    #populate the graph
    graph = Hel.createG

    # pull some maps from the graph
    [alcmene] = graph |> v_id(9) |> data
    [jupiter] = graph |> v_id(2) |> data
    [pluto] = graph |> v_id(10) |> data

  
    # get all neighbors with inbound edges
    # graph is a map with info about our stuff and traversal
    # v_id(id) fetches a vertex by ID and puts it into the stream
    ins = graph |> v_id(2) 
      # in is used in Elixir.Kernel so we use inn
      |> inn 
      # [data](https://github.com/jschoch/trebant/blob/master/lib/trabant.ex#L123-L126) is a shortcut for res(graph).data
      # it grabs graph.stream and process it
      |> data

    #  get the herculese map
    [herc] = graph |> v_id(2) |> inn(%{type: :demigod}) |> data
    assert herc.id == 5

random thoughts:

thoughts on binary key conventions

id

<< id_type :: binary-size(1), id :: binary-size(16), post :: binary-size(1) >>

id_types:

atom description
:node normal node
:out_edge id for an outbound edge V --:outbound_from_V--> X
:in_edge id for an inbound edge X <--:inbound_from_v-- V
:label special node for grouping normal nodes
:in_neighbor
:out_neightbor
:default the default type

origin idgon.com my technology blog