Skip to content

Latest commit

 

History

History
90 lines (76 loc) · 3.03 KB

README.md

File metadata and controls

90 lines (76 loc) · 3.03 KB

neo4j-kt

Hate writing queries in strings?

neo4j-kt is a DSL for Cypher query language for Kotlin and Neo4j graph database users.

When integrated with driver library for Java, neo4j-kt is a powerful tool for describing and executing queries to the graph database. Look at the Neo4j usage example.

Describing nodes, relationships and complex queries becomes as easy as a pie:

class Restaurant(val name: String, val food: String, val workers: Map<String, Int>)
val rest = Restaurant("Harakiri", "Sushi", mapOf("chefs" to 1, "cooks" to 10, "waiters" to 70))

val req = create {
    + node("rest", "Restaurant") {
        "name" value rest.name
        "food" value rest.food
        for ((k, v) in rest.workers)
            k value v
    }
}

Current available functions:

  1. Describing nodes
val node = node("cat", "Cat") {
    "livesAt" value "home"
}
  1. Describing relationships
val rel = relationship("m", "MARRIED") { "when" value "longAgo" }
  1. Describing patterns with different length and directions
val req = create {
    node("me") has relationship(type="KNOWS") [ANY upTo 2] to node("remoteFriend")
}
  1. Pattern for path series
val acted = relationship(type="ACTED_IN")
val filmed = relationship(type="FILMED")
val actor = node(label="Person")
val movie = node("movie", "Movie")
val hollywood = node("hollywood", "Hollywood")

val req = create {
    actor has acted to movie which filmed by hollywood
}
  1. Combining CREATE, MATCH, MERGE, OPTIONAL MATCH clauses
val req = match {
    + node("a", "Person")
    + node("b", "Person")
} where {
    + ("n.age" lessThan 30)
} and create {
        node("a") has relationship("r" , "RELTYPE") to node("b")
} returns "type(r)"
  1. WHERE clause
val req = match {
    + node("a")
    + node("b")
} where {
    + (("a.age" notEqualTo "b.age") and not(("a.name" contains "K") or ("b.age" greaterThan 2)))
}
  1. RETURN, ORDER BY, LIMIT requirements
val req = match {
    + node("n")
} where {
    + ("n.age" lessThan 30)
} returns "n.name" orderBy "n.name" limit 3

and other features to make life easier.

To be continued...