io.github.erictsangx:kotlin-neo4j

kotlin-neo4j is a wrapper of 'org.neo4j.driver:neo4j-java-driver' and written by Kotlin.

License

License

Categories

Categories

Kotlin Languages Neo4J Data Databases
GroupId

GroupId

io.github.erictsangx
ArtifactId

ArtifactId

kotlin-neo4j
Last Version

Last Version

0.0.6
Release Date

Release Date

Type

Type

jar
Description

Description

io.github.erictsangx:kotlin-neo4j
kotlin-neo4j is a wrapper of 'org.neo4j.driver:neo4j-java-driver' and written by Kotlin.
Project URL

Project URL

https://github.com/erictsangx/kotlin-neo4j
Source Code Management

Source Code Management

https://github.com/erictsangx/kotlin-neo4j

Download kotlin-neo4j

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.erictsangx/kotlin-neo4j/ -->
<dependency>
    <groupId>io.github.erictsangx</groupId>
    <artifactId>kotlin-neo4j</artifactId>
    <version>0.0.6</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.erictsangx/kotlin-neo4j/
implementation 'io.github.erictsangx:kotlin-neo4j:0.0.6'
// https://jarcasting.com/artifacts/io.github.erictsangx/kotlin-neo4j/
implementation ("io.github.erictsangx:kotlin-neo4j:0.0.6")
'io.github.erictsangx:kotlin-neo4j:jar:0.0.6'
<dependency org="io.github.erictsangx" name="kotlin-neo4j" rev="0.0.6">
  <artifact name="kotlin-neo4j" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.erictsangx', module='kotlin-neo4j', version='0.0.6')
)
libraryDependencies += "io.github.erictsangx" % "kotlin-neo4j" % "0.0.6"
[io.github.erictsangx/kotlin-neo4j "0.0.6"]

Dependencies

runtime (4)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.3.21
org.jetbrains.kotlin : kotlin-reflect jar 1.3.21
org.slf4j : slf4j-api jar 1.7.26
org.neo4j.driver : neo4j-java-driver jar 1.7.3

test (9)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-test jar 1.3.21
org.junit.jupiter : junit-jupiter-api jar 5.3.1
io.github.erictsangx : kotlin-random jar 0.0.1
io.github.microutils : kotlin-logging jar 1.4
ch.qos.logback : logback-core jar 1.1.7
ch.qos.logback : logback-classic jar 1.1.7
org.neo4j : neo4j-slf4j jar 3.5.4
org.neo4j.community : it-test-support jar 3.5.4
com.fasterxml.jackson.module : jackson-module-kotlin jar 2.9.7

Project Modules

There are no modules declared in this project.

kotlin-neo4j

kotlin-neo4j is a wrapper of 'org.neo4j.driver:neo4j-java-driver' and written by Kotlin.

  • Easy to use with Kotlin: declarative style
  • Kotlin std naming styles: stringOrNull, int("key")
  • Support Sl4j Logger

Gradle

implementation "io.github.erictsangx:kotlin-neo4j:0.0.6"

Maven

<dependency>
  <groupId>io.github.erictsangx</groupId>
  <artifactId>kotlin-neo4j</artifactId>
  <version>0.0.6</version>
</dependency>

Examples

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import github.etx.neo4j.DefaultNeoSerializer
import github.etx.neo4j.NeoLogging
import github.etx.neo4j.NeoQuery
import github.etx.neo4j.destruct
import org.neo4j.driver.v1.AuthTokens
import org.neo4j.driver.v1.Config
import org.neo4j.driver.v1.GraphDatabase
import org.slf4j.LoggerFactory


data class User(val name: String, val age: Int?)

class HelloWorld {
    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            val logger = LoggerFactory.getLogger(HelloWorld::class.java)

            val driver = GraphDatabase.driver(
                "bolt://127.0.0.1",
                AuthTokens.basic("neo4j", "neo4j")
                , Config.build().withLogging(NeoLogging(logger)).toConfig()
            )

            val neo = NeoQuery(driver, DefaultNeoSerializer())

            neo.submit("CREATE (u:User { name: {name}, age: {age} })", User("Alice", 18).destruct())
            neo.submit("CREATE (u:User { name: {name}, age: {age} })", User("Bob", null).destruct())

            val alice = neo.submit("MATCH (u:User { name:{name} }) RETURN u", mapOf("name" to "Alice"))
                .map { it.unwrap("u") }
                .map { User(it.string("name"), it.intOrNull("age")) }
                .singleOrNull()
            println(alice) //User(name=Alice, age=18)

            //or
            val aliceB = neo.submit("MATCH (u:User { name:{name} }) RETURN u", mapOf("name" to "Alice"))
                .unwrap("u")
                .let {
                    User(it.string("name"), it.intOrNull("age"))
                }
            println(aliceB) //User(name=Alice, age=18)


            //You can use with Jackson
            val mapper = ObjectMapper().registerModule(KotlinModule())
            val users = neo.submit("MATCH (u:User) WHERE u.age IS NULL RETURN u")
                .map { it.unwrap("u") }
                .map { mapper.convertValue(it.asMap(), User::class.java) }
                .toList()
            println(users) //[User(name=Bob, age=null)]

            driver.close()
        }
    }
}

Versions

Version
0.0.6
0.0.5
0.0.3
0.0.2
0.0.1