All Projects → jgaskins → neo4j.cr

jgaskins / neo4j.cr

Licence: MIT license
Pure-Crystal implementation of Neo4j's Bolt protocol

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to neo4j.cr

angular-neo4j
Neo4j Bolt driver wrapper for Angular
Stars: ✭ 18 (-37.93%)
Mutual labels:  neo4j, neo4j-driver, graph-database
seabolt
Neo4j Bolt Connector for C
Stars: ✭ 37 (+27.59%)
Mutual labels:  neo4j, neo4j-driver, graph-database
Neo4j 3d Force Graph
Experiments with Neo4j & 3d-force-graph https://github.com/vasturiano/3d-force-graph
Stars: ✭ 159 (+448.28%)
Mutual labels:  neo4j, graph-database
Neo4j Etl
Data import from relational databases to Neo4j.
Stars: ✭ 165 (+468.97%)
Mutual labels:  neo4j, graph-database
Helicalinsight
Helical Insight software is world’s first Open Source Business Intelligence framework which helps you to make sense out of your data and make well informed decisions.
Stars: ✭ 214 (+637.93%)
Mutual labels:  neo4j, graph-database
Neo4j Streams
Neo4j Kafka Integrations, Docs =>
Stars: ✭ 126 (+334.48%)
Mutual labels:  neo4j, graph-database
Reddit Detective
Play detective on Reddit: Discover political disinformation campaigns, secret influencers and more
Stars: ✭ 129 (+344.83%)
Mutual labels:  neo4j, graph-database
Bolt sips
Neo4j driver for Elixir
Stars: ✭ 204 (+603.45%)
Mutual labels:  neo4j, graph-database
Activegraph
An active model wrapper for the Neo4j Graph Database for Ruby.
Stars: ✭ 1,329 (+4482.76%)
Mutual labels:  neo4j, graph-database
database-journal
Databases: Concepts, commands, codes, interview questions and more...
Stars: ✭ 50 (+72.41%)
Mutual labels:  neo4j, graph-database
neo4j-jdbc
JDBC driver for Neo4j
Stars: ✭ 110 (+279.31%)
Mutual labels:  neo4j, neo4j-driver
Movies Javascript Bolt
Neo4j Movies Example with webpack-in-browser app using the neo4j-javascript-driver
Stars: ✭ 123 (+324.14%)
Mutual labels:  neo4j, graph-database
Libneo4j Client
neo4j-client -- Neo4j Command Line Interface (CLI)
Stars: ✭ 121 (+317.24%)
Mutual labels:  neo4j, graph-database
Neo4j Php Ogm
Neo4j Object Graph Mapper for PHP
Stars: ✭ 151 (+420.69%)
Mutual labels:  neo4j, graph-database
Neo4j Core
A simple unified API that can access both the server and embedded Neo4j database. Used by the neo4j gem
Stars: ✭ 99 (+241.38%)
Mutual labels:  neo4j, graph-database
Movies Python Bolt
Neo4j Movies Example application with Flask backend using the neo4j-python-driver
Stars: ✭ 197 (+579.31%)
Mutual labels:  neo4j, graph-database
OGMNeo
[No Maintenance] Neo4j nodeJS OGM(object-graph mapping) abstraction layer
Stars: ✭ 54 (+86.21%)
Mutual labels:  neo4j, neo4j-driver
Neo4j
Graphs for Everyone
Stars: ✭ 9,582 (+32941.38%)
Mutual labels:  neo4j, graph-database
Neo4j Apoc Procedures
Awesome Procedures On Cypher for Neo4j - codenamed "apoc"                     If you like it, please ★ above ⇧            
Stars: ✭ 1,291 (+4351.72%)
Mutual labels:  neo4j, graph-database
neo4j-faker
Use faker cypher functions to generate demo and test data with cypher
Stars: ✭ 30 (+3.45%)
Mutual labels:  neo4j, graph-database

neo4j.cr

Join the chat at https://gitter.im/jgaskins/neo4j.cr Check out the build on Travis CI

Crystal implementation of a Neo4j driver using the Bolt protocol.

Installation

Add this to your application's shard.yml:

dependencies:
  neo4j:
    github: jgaskins/neo4j.cr

Usage

First you need to set up a connection:

require "neo4j"

neo4j_uri = URI.parse("bolt://neo4j:password@localhost:7687")

# The `ssl` option defaults to `true` so you don't accidentally send the
# password to your production DB in cleartext.
driver = Neo4j.connect(neo4j_uri, ssl: false)

This will return a cluster driver or a direct driver depending on whether you provided a neo4j:// or bolt:// URI, respectively. neo4j:// can also be specified as bolt+routing://. Both drivers expose the same interface, but the cluster driver will route queries to a different server based on whether you specify that the query is a read or write query.

struct Person
  include Neo4j::Serializable::Node

  getter id: UUID
  getter name: String
  getter email: String
end

driver.session do |session|
  session.read_transaction do |read|
    query = <<-CYPHER
      MATCH (person:Person { name: $name })
      RETURN person
    CYPHER

    read.exec_cast(query, {Person}, name: "Jamie") do |(person)|
      pp person
    end
  end

  session.write_transaction do |write|
    write.execute <<-CYPHER, name: "Jamie"
      MATCH (person:Person { name: $name })
      SET person.login_count = person.login_count + 1
    CYPHER
  end
end

Neo4j::Result

  • type : (Neo4j::Success | Neo4j::Ignored)
    • If you get an Ignored result, it probably means an error occurred. Call connection#reset to get it back to working order.
    • If a query results in a Neo4j::Failure, an exception is raised rather than wrapping it in a Result.
  • data : Array(Array(Neo4j::Type))
    • This is the list of result values. For example, if you RETURN a, b, c from your query, then this will be an array of [a, b, c].

The Result object itself is an Enumerable. Calling Result#each will iterate over the data for you.

Neo4j::Node

These have a 1:1 mapping to nodes in your graph.

  • id : Int32: the node's internal id
    • WARNING: Do not store this id anywhere. These ids can be reused by the database. If you need an application-level unique id, store a UUID on the node. It is useful in querying nodes connected to this one when you already have it in memory, but not beyond that.
  • labels : Array(String): the labels stored on your node
  • properties : Hash(String, Neo4j::Type): the properties assigned to this node

Neo4j::Relationship

  • id: Int32: the relationship's internal id
  • type : String: the type of relationship
  • start : Int32: the internal id for the node on the starting end of this relationship
  • end : Int32: the internal id of the node this relationship points to
  • properties : Hash(String, Neo4j::Type): the properties assigned to this relationship

Neo4j::Value

Represents any data type that can be stored in a Neo4j database and communicated via the Bolt protocol. It's a shorthand for this union type:

Nil |
Bool |
String |
Int8 |
Int16 |
Int32 |
Int64 |
Float64 |
Time |
Neo4j::Point2D |
Neo4j::Point3D |
Neo4j::LatLng |
Array(Neo4j::Value) |
Hash(String, Neo4j::Value) |
Neo4j::Node |
Neo4j::Relationship |
Neo4j::UnboundRelationship |
Neo4j::Path

Mapping to Domain Objects

Similar to JSON.mapping in the Crystal standard library, you can map nodes and relationships to domain objects. For example:

require "uuid"

class User
  include Neo4j::Serializable::Node

  getter uuid : UUID
  getter email : String
  getter name : String
  getter registered_at : Time
end

class Product
  include Neo4j::Serializable::Node

  getter uuid : UUID
  getter name : String
  getter description : String
  getter price : Int32
  getter created_at : Time
end

class CartItem
  include Neo4j::Serializable::Relationship

  getter quantity : Int32
  getter price : Int32
end

Acknowledgements/Credits

The implementation of the wire protocol is heavily based on the MessagePack shard to understand how to serialize and deserialize a binary protocol in Crystal.

Contributing

  1. Fork it ( https://github.com/jgaskins/neo4j.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • jgaskins Jamie Gaskins - creator, maintainer
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].