Code Monkey home page Code Monkey logo

neo4j_sips's Introduction

Neo4j.Sips

A simple Elixir driver using the Neo4j graph database REST API. Compatible with the following Neo4j servers: 2.x/3.0.x/3.1.x

Build Status Deps Status Hex.pm Hexdocs.pm

Documentation: hexdocs.pm/neo4j_sips/

You can also look at: Bolt.Sips - Elixir driver using the Bolt protocol; Neo4j's newest network protocol, designed for high-performance.

Install

Available in Hex. Edit the mix.ex file and add the neo4j_sips dependency to the deps/1 function:

def deps do
  [{:neo4j_sips, "~> 0.2"}]
end

or from Github:

def deps do
  [{:neo4j_sips, github: "florinpatrascu/neo4j_sips"}]
end

If you're using a local development copy:

def deps do
  [{:neo4j_sips, path: "../neo4j_sips"}]
end

Then add the neo4j_sips dependency the applications list:

def application do
  [applications: [:logger, :neo4j_sips],
   mod: {Neo4j.Sips.Application, []}]
end

Edit the config/config.exs and describe a Neo4j server endpoint, example:

config :neo4j_sips, Neo4j,
  url: "http://localhost:7474",
  pool_size: 5,
  max_overflow: 2,
  timeout: 15_000  # milliseconds!

Run mix do deps.get, deps.compile

If your server requires basic authentication, add this to your config file:

  basic_auth: [username: "foo", password: "bar"]

Or:

  token_auth: "bmVvNGo6dGVzdA==" # if using an authentication token?!

You can also specify the authentication in the url config:

  url: "http://neo4j:neo4j@localhost:7474"

Example

With a minimalist setup configured as above, and a Neo4j server running, we can connect to the server and run some queries using Elixir’s interactive shell (IEx):

$ cd <my_mix_project>
$ iex -S mix
Erlang/OTP 19 [erts-8.0.2] [source] [64-bit] ...

Interactive Elixir (1.3.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> alias Neo4j.Sips, as: Neo4j

iex(2)> Neo4j.start_link(url: "http://localhost:7474")
{:ok, #PID<0.204.0>}

iex(3)> cypher = """
  CREATE (n:Neo4jSips {title:'Elixir sipping from Neo4j', released:2015, 
    license:'MIT', neo4j_sips_test: true})
"""

iex(4)> Neo4j.query(Neo4j.conn, cypher)
{:ok, []}

iex(5)> n = Neo4j.query!(Neo4j.conn, "match (n:Neo4jSips {title:'Elixir sipping from Neo4j'}) where n.neo4j_sips_test return n")
[%{"n" => %{"license" => "MIT", "neo4j_sips_test" => true, "released" => 2015,
     "title" => "Elixir sipping from Neo4j"}}]

For more examples, see the test suites.

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Test (mix test)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

Contributors

As reported by Github: contributions to master, excluding merge commits

Author

Florin T.PATRASCU (@florinpatrascu, @florin on Twitter)

License

  • Neo4j.Sips - MIT, check LICENSE file for more information.
  • Neo4j - Dual free software/commercial license, see http://neo4j.org/

neo4j_sips's People

Contributors

0chroma avatar dotdotdotpaul avatar florinpatrascu avatar johnhamelink avatar rrrene avatar sntran avatar suddenrushofsushi avatar tpunt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neo4j_sips's Issues

Ecto adapter

New to Elixir but interested in working on an Ecto adapter with this neo4j_sips as the foundation. Is there anything that needs to be added here before getting started?

Also would love some guidance on what the next steps for that would be.

Thanks

Production?

Is it realistic to assume that this project could be used in production within the next couple of months?

getting hex dependency conflict

Hi,
I am using latest phoenix versions and I am getting dependency conflict on "poison".
Pasting the error and my dependencies below:

Conflict on poison 2.1.0
mix.lock: 2.1.0
neo4j_sips 0.1.11, 0.1.12: ~> 1.5.0
phoenix 1.1.4: ~> 1.5 or ~> 2.0

** (Mix) Hex dependency resolution failed, relax the version requirements or unlock dependencies

I tried to resolve it by cloning the neo4j_sips repo and bumping the version of poison, but there is another dependency -
{:inch_ex, "~> 0.4.0", only: :docs}
which requires the specific version of poison.

Can't connect to Neo4j after update from 3.0 to 3.1

Hi,

I can't seem to connect to Neo4j after updating from 3.0 to 3.1.
The errors I get are ...

** (Mix) Could not start application p8: P8.start(:normal, []) returned an error: shutdown: failed to start child: P8.ServiceSup
    ** (EXIT) shutdown: failed to start child: P8.Services.Neo4j
        ** (EXIT) an exception was raised:
            ** (ArgumentError) argument error
                :erlang.binary_to_existing_atom("bolt", :utf8)
                (poison) lib/poison/parser.ex:114: Poison.Parser.object_name/2
                (poison) lib/poison/parser.ex:95: Poison.Parser.object_pairs/4
                (poison) lib/poison/parser.ex:37: Poison.Parser.parse/2
                (poison) lib/poison/parser.ex:51: Poison.Parser.parse!/2
                (neo4j_sips) lib/neo4j_sips/server.ex:96: Neo4j.Sips.Server.init/1
                (neo4j_sips) lib/neo4j_sips.ex:57: Neo4j.Sips.start_link/1
                (p8) lib/p8/services/neo4j.ex:13: P8.Services.Neo4j.init/1

I have updated Neo4j.Sips to the latest version using

mix deps.update --all

But still no luck :(

Any help would be greatly appreciated.

Thnx in advance,

Neil.

Models: how to create properties on relationships

Is is possible to add properties to relationships when creating a node via models?

Person.create(name: "Jane DOE", email: "[email protected]",
                                   age: 25, enable_validations: true, doe_family: true,
                                   married_to: john)

In this example, I'd want to add a since property on the married_to relationship.

TODO List

Thanks for making this! It's been really helpful so far. Do you have a roadmap or a todo list for this project? @ascrookes said this in the other issue, I just wanted to make another issue to discuss it.

I'm still really new to Elixir but I'd love to help out any way I can!

Basic auth doesn't seem to work properly?

Hi there,

I’m using neo4j_sips for an elixir project I’m trying to get into production currently. The last thing stopping me from getting the project into production is basic auth with neo4_sips - no matter what I try, the server seems to come back as unauthorized.

I’m already using the same config with a ruby API using neo4jrb, so I know that the credentials are correct.

Futhermore, if I use curl to access the Neo4j API in the format of “http://:@host” then I get past authorization. Turning off the auth requirement on the server also allows me to connect.

Has this feature been used successfully elsewhere?

I'm using Neo4j enterprise 2.3.2

Best,
JH


prod.exs:

config :neo4j_sips, Neo4j,
  basic_auth: [
    username: "neo4j",
    password: "<password>"
  ],
  url: "http://<host>:7474",
  pool_size: 5,
  max_overflow: 2,
  timeout: 30
ubuntu@10:~$ sudo -u www-data /opt/app/api/bin/api console
Using /opt/app/api/releases/0.0.11/api.sh
Exec: /opt/app/api/erts-7.2/bin/erlexec -boot /opt/app/api/releases/0.0.11/api -boot_var ERTS_LIB_DIR /opt/app/api/erts-7.2/../lib -env ERL_LIBS /opt/app/api/lib -config /opt/app/api/running-config/sys.config -pa /opt/app/api/lib/api-0.0.10/consolidated /opt/app/api/lib/api-0.0.11/consolidated -args_file /opt/app/api/running-config/vm.args -user Elixir.IEx.CLI -extra --no-halt +iex -- console
Root: /opt/app/api
/opt/app/api
Erlang/OTP 18 [erts-7.2] [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]

{"Kernel pid terminated",application_controller,"{application_start_failure,neo4j_sips,{{shutdown,{failed_to_start_child,neo4j_sips_pool,{{badmatch,{error,{bad_return_value,{error,<<\"Cannot connect to the server at url: http://<host>:7474. Reason: Invalid Authorization\">>}}}},[{poolboy,new_worker,1,[{file,\"src/poolboy.erl\"},{line,275}]},{poolboy,prepopulate,3,[{file,\"src/poolboy.erl\"},{line,296}]},{poolboy,init,3,[{file,\"src/poolboy.erl\"},{line,145}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,328}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,240}]}]}}},{'Elixir.Neo4j.Sips',start,[normal,[]]}}}"}

Crash dump is being written to: erl_crash.dump...done
Kernel pid terminated (application_controller) ({application_start_failure,neo4j_sips,{{shutdown,{failed_to_start_child,neo4j_sips_pool,{{badmatch,{error,{bad_return_value,{error,<<"Cannot connect t

tx_commit/1 doesn't appear to work, transactions generally wonky

Something seems very wrong with transactions. I think part of it is code, part of it might be Neo4j itself, but I'm not sure. I've forked the repo and done a little twiddling in transaction.ex, and then added to the transaction test to see if the main Neo4j connection can "see" the transactional changes before they're committed -- unfortunately, that seems to be the case.

Please take a look at https://github.com/dotdotdotpaul/neo4j_sips

One problem I noticed is that if you call tx_commit(conn) (with nothing else), the code would generate a server error during the commit, because it tries to execute a statement "" (empty string). I think my refactoring fixed that (using nil to indicate "no statements") but I still kept getting some odd behavior with regards to things persisting after a rollback...

So I expanded the test to check to see if the Neo4j.conn "sees" the changes made by the transactional conn -- and it does. That's concerning. But I also can't tell if that particular problem is due to Neo4j or to something in this library...

...Paul

Injection?

I'm wondering if this library is safe from user injection attacks?

Thanks!

Multiple Endpoints

First, I just want to say I'm glad you are tackling this! If you have a list of TODOs I would love to help out.

Second, is there a way to us multiple endpoints? Ideally I would be able to send read requests and write requests to different instances.

** (MatchError) no match of right hand side value: {:error, {:error, :invalid}}

No matter how I configure this library, I can't seem to execute any queries. I keep getting:

** (MatchError) no match of right hand side value: {:error, {:error, :invalid}}
    (neo4j_sips) lib/neo4j_sips/query.ex:12: Neo4j.Sips.Query.query/2
    (neo4j_sips) lib/neo4j_sips/query.ex:30: Neo4j.Sips.Query.query!/2

conn gives me

iex(1)> Neo4j.Sips.conn()
%Neo4j.Sips.Connection{commit_url: "", options: nil,
 server: %Neo4j.Sips.Server{bolt: nil,
  data: %{batch: "http://neo4j:7474/db/data/batch",
    constraints: "http://neo4j:7474/db/data/schema/constraint",
    cypher: "http://neo4j:7474/db/data/cypher", extensions: %{},
    extensions_info: "http://neo4j:7474/db/data/ext",
    indexes: "http://neo4j:7474/db/data/schema/index", neo4j_version: "3.1.3",
    node: "http://neo4j:7474/db/data/node",
    node_index: "http://neo4j:7474/db/data/index/node",
    node_labels: "http://neo4j:7474/db/data/labels",
    relationship: "http://neo4j:7474/db/data/relationship",
    relationship_index: "http://neo4j:7474/db/data/index/relationship",
    relationship_types: "http://neo4j:7474/db/data/relationship/types",
    transaction: "http://neo4j:7474/db/data/transaction"},
  data_url: "http://neo4j:7474/db/data/",
  management_url: "http://neo4j:7474/db/manage/",
  server_url: "http://neo4j:7474", timeout: 5000}, server_version: "3.1.3",
 transaction_url: "http://neo4j:7474/db/data/transaction"}

I've configured multiple ways:

supervisor(Neo4j.Sips, [[url: "http://neo4j:7474", basic_auth: [username: "neo4j", password: "super-secret"]]]),

and through config.exs

config :neo4j_sips, Neo4j,
  url: "http://neo4j:super-secret@neo4j:7474", 
  pool_size: 5,
  max_overflow: 2,
  timeout: 30

Cypher query builder

Not sure if this is the best place to discuss :)

I spoke with @arpieb and because my focus is on neo4j exclusively, he suggested we collaborate some. For my own project, I needed to prototype a Cypher query builder.

Take a look at the tests:
https://gist.github.com/venkatd/03282106e369784e70d3

There are some things that are hacked at the moment. For example, placeholders are not locally bound, so if you compose queries without unique variable names, it could cause conflicts.

Let me know what you think!

abstractions for node/relationships

I don't see any abstractions for nodes or relationships, but it would convenient to for instance create neo4j nodes from elixir hashes instead of raw cypher text. Do you have plans to add anything like this, or are you interested in pull requests for such things?

Cannot run anything from Neo4j.Sips

Hi,
Am getting an issue when running Neo4j.Sips.
My config.exs file contains ...

config :neo4j_sips, Neo4j,
  url: "http://localhost:7474",
  pool_size: 5,
  max_overflow: 2,
  timeout: 30
iex(2)> Neo4j.Sips.config
** (MatchError) no match of right hand side value: []
    (con_cache) lib/con_cache/registry.ex:18: ConCache.Registry.get/1
    (con_cache) lib/con_cache.ex:143: ConCache.get/2
iex(2)> Neo4j.Sips.conn
** (MatchError) no match of right hand side value: []
    (con_cache) lib/con_cache/registry.ex:18: ConCache.Registry.get/1
    (con_cache) lib/con_cache.ex:143: ConCache.get/2
iex(2)>

Any help with this would be greatly appreciated.

Thnx.

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.