Logo

neotype - a type specimen that is selected subsequent to the description of a species to replace a preexisting type that has been lost or destroyed.

Build status Scaladex Gitter chat Scala Steward

neotypes

Scala lightweight, type-safe, asynchronous driver (not opinionated on effect systems) for Neo4j

  • Scala - the driver provides you with support for all standard Scala types without the need to convert Scala <-> Java types back and forth and you can easily add support for your own types.
  • Lightweight - the core module of the driver only depends the Neo4j Java driver, and the generic module only depends on Shapeless.
  • Type-safe - the driver leverages typeclasses to derive all needed conversions at the compile time.
  • Asynchronous - the driver sits on top of asynchronous Java driver.
  • Not opinionated on side-effect implementation - you can use it with any effect system of your preference (Future, typelevel, ZIO, Monix) by implementing a simple typeclass.

Setup

Supports Scala 2.13 and 3.3  
"io.github.neotypes" %% "neotypes-core" % version core functionality. Supports scala.concurrent.Future.
"io.github.neotypes" %% "neotypes-generic" % version auto & semiauto derivation of mappers for case classes.
"io.github.neotypes" %% "neotypes-cats-effect" % version cats.effect.Async[F] implementation.
"io.github.neotypes" %% "neotypes-monix" % version monix.eval.Task implementation.
"io.github.neotypes" %% "neotypes-zio" % version zio.Task implementation.
"io.github.neotypes" %% "neotypes-akka-stream" % version result streaming for Akka Streams.
"io.github.neotypes" %% "neotypes-pekko-stream" % version result streaming for Pekko Streams.
"io.github.neotypes" %% "neotypes-fs2-stream" % version result streaming for FS2.
"io.github.neotypes" %% "neotypes-monix-stream" % version result streaming for Monix Observables.
"io.github.neotypes" %% "neotypes-zio-stream" % version result streaming for ZIO ZStreams.
"io.github.neotypes" %% "neotypes-refined" % version support to insert and retrieve refined values.
"io.github.neotypes" %% "neotypes-cats-data" % version support to insert and retrieve cats.data values.
"io.github.neotypes" %% "neotypes-enumeratum" % version support to insert and retrieve Enumeratum enums.

Showcase

import neotypes.GraphDatabase
import neotypes.mappers.ResultMapper
import neotypes.syntax.all._
import org.neo4j.driver.AuthTokens
import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

val driver =
  GraphDatabase.asyncDriver[Future]("bolt://localhost:7687", AuthTokens.basic("neo4j", "****"))

val peopleTuple =
  "MATCH (p: Person) RETURN p.name, p.born LIMIT 10"
    .query(ResultMapper.tuple[String, Int])
    .list(driver)

Await.result(peopleTuple, 1.second)
// res: Seq[(String, Int)] = ArrayBuffer(
//   (Charlize Theron, 1975),
//   (Keanu Reeves, 1964),
//   (Carrie-Anne Moss, 1967),
//   (Laurence Fishburne, 1961),
//   (Hugo Weaving, 1960),
//   (Lilly Wachowski, 1967),
//   (Lana Wachowski, 1965),
//   (Joel Silver,1952),
//   (Emil Eifrem,1978),
//   (Charlize Theron,1975)
// )

final case class Person(id: Long, born: Int, name: Option[String], notExists: Option[Int])

val peopleCaseClass =
  "MATCH (p: Person) RETURN p LIMIT 10"
    .query(ResultMapper.fromFunction(Person.apply _))
    .list(driver)

Await.result(peopleCaseClass, 1.second)
// res: Seq[Person] = ArrayBuffer(
//   Person(0, 1975, Some(Charlize Theron), None),
//   Person(1, 1964, Some(Keanu Reeves), None),
//   Person(2, 1967, Some(Carrie-Anne Moss), None),
//   Person(3, 1961, Some(Laurence Fishburne), None),
//   Person(4, 1960, Some(Hugo Weaving), None),
//   Person(5, 1967, Some(Lilly Wachowski), None),
//   Person(6, 1965, Some(Lana Wachowski), None),
//   Person(7, 1952, Some(Joel Silver), None),
//   Person(8, 1978, Some(Emil Eifrem), None),
//   Person(9, 1975, Some(Charlize Theron), None)
// )

Await.ready(driver.close, 1.second)

Compatibility matrix

Java driver version Neotypes version
5.y.x >= 0.23
4.y.x >= 0.14
1.7.x <= 0.13

For info on the compatibility with Java runtimes or Neo4j servers, please check the the Java driver docs.

Note: Since 0.23.0 the artifacts are published for Java 17 only, since that is what the 5.x series of the Java driver requires.
Note: Since 0.23.1 the minimum supported version of the Java driver is 5.3.0