Code Monkey home page Code Monkey logo

neodsl's Introduction

NeoDSL

This is simple DSL/mapper for graph databases (neo4j in particular) written in scala.

It lets you build Cypher queries with easy to read DSL which are automatically validated at compilation phase. It also handles mapping of results to domain classes. All that is needed to start building your queries is to define classes extending DomainObject. You can define relationships using <--, -->, -- methods (respectively to define incoming, outgoing or without specified direction relationship). Once you're done with that. You can start composing patterns and whole queries.

Project is still under active development. It for sure has some bugs and doesn't cover all possible use cases but it aims to develop interesting way of searching in graph databases.

Summary of what it does:

  • Let you express complex patterns using friendly syntax that is automatically validated at compilation phase
  • Let you express simple conditions for returned nodes which are serialized into WHERE statements (Using basic Scala syntax for Boolean expressions, achieved using Scala Macros)
  • Map results from database to domain classes

And what it doesn't (yet!):

  • Won't help you create/update nodes, relationships
  • Won't let you define some advanced criteria for returned nodes (like expressing uniqueness)
  • Won't make you coffee (what a joke!)
  • And probably a lot more!

If you're bored with your life you may read paper (in polish) about this project at: https://github.com/mszygenda/neodsl/blob/master/doc/master-thesis.pdf?raw=true

Examples

Given following model classes

case class Person(name: String, age: Int) extends DomainObject[Person] {
  val knows = --[Person]("KNOWS")
  val wrote = -->[Comment]("WROTE")
  val likes = -->[Comment]("LIKES")
}

case class Comment(content: String) extends DomainObject[Comment] {
  val writtenBy = <--[Person]("WROTE")
}

Following snippet builds query to retrieve all John's friends of friends who like comments written by him and are at least 20 years old

val (friend, fof, comment) = (p[Person], p[Person], p[Comment])

{ john knows { friend knows fof } } and
{ fof likes { comment writtenBy john } } where {
  fof.age >= 20
} select(fof)

Such query translates to following cypher query:

START john=node(JOHN_ID)
MATCH john-[:KNOWS]->friend-[:KNOWS]->fof,
      fof-[:LIKES]->comment<-[:WROTE]-john
WHERE fof.age >= 20
RETURN fof.id, fof.name, fof.age

You can find more examples in: Social Network Example, QueriesExamples.scala

neodsl's People

Contributors

mszygenda avatar

Stargazers

Mirko Francuski avatar

Watchers

 avatar James Cloos 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.