Skip to content

Commit

Permalink
Microsite (#3)
Browse files Browse the repository at this point in the history
* Github pages

* Github pages

* Github pages
  • Loading branch information
dimafeng committed Dec 17, 2018
1 parent 5c225c7 commit db347e4
Show file tree
Hide file tree
Showing 10 changed files with 841 additions and 65 deletions.
18 changes: 17 additions & 1 deletion .travis.yml
Expand Up @@ -10,8 +10,24 @@ services:

script:
- ./sbt +test
- ./sbt "project microsite" makeMicrosite

cache:
directories:
- $HOME/.ivy2/cache
- $HOME/.sbt
- $HOME/.sbt

install:
- rvm use 2.2.5 --install --fuzzy
- gem update --system
- gem install sass
- gem install ruby_dep -v 1.3.1
- gem install jekyll -v 3.4.3

deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: docs/target/site
on:
branch: master
61 changes: 1 addition & 60 deletions README.md
Expand Up @@ -13,7 +13,7 @@

For early adopters: `"com.dimafeng" % "neotypes_2.12" % "0.2.0"`

**Scala lightweight and type-safe asynchronous driver (not opinionated on side-effect implementation) for neo4j**.
**Scala lightweight, type-safe, asynchronous driver (not opinionated on side-effect implementation) 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 your types.
* **Lightweight** - the driver depends on `shapeless` and `neo4j Java driver`
Expand All @@ -31,37 +31,6 @@ The project aims to provide seamless integration with most popular scala infrast
* Java 8+
* neo4j 3.4.*+

## Overview and philosophy
`neotypes` adds an extension method (`.asScala[F[_]: Async]`) to `org.neo4j.driver.v1.Session` that allows to build a `neotypes`'s session wrapper. You can
parametrize `asScala` by any type that you have a typeclass `neotypes.Async` implementation for. The typeclass implementation for `scala.concurrent.Future` is
built-in. Please node that you have to make sure that the session is properly closed at the end of the application execution.

Once you have a session constructed, you can start querying the database. The import `neotypes.implicits._` adds an extension method `query[T]` to each
string literal in its scope or you can use string interpolation. Type parameter `[T]` specifies a resulted return type.
```scala
"create (p:Person {name: $name, born: $born})".query[Unit].execute(s)
"create (p:Person {name: $name, born: $born})".query[Unit].withParams(Map("name" -> "John", "born" -> 1980)).execute(s)

val name = "John"
val born = 1980
c"create (p:Person {name: $name, born: $born})".query[Unit].execute(s) // Query with string interpolation

```
A query can be run in three different ways:
* `execute(s)` - executes a query that has no return data. Query can be parametrized by `org.neo4j.driver.v1.summary.ResultSummary` or `Unit`. If you need to support your return types for this
type of queries, you can provide an implementation of `ExecutionMapper` for any custom type.
* `single(s)` - runs a query and return single result.
* `list(s)` - runs a query and returns list of results.

```scala
"match (p:Person {name: 'Charlize Theron'}) return p.name".query[String].single(s)
"match (p:Person {name: 'Charlize Theron'}) return p".query[Person].single(s)
"match (p:Person {name: 'Charlize Theron'}) return p".query[Map[String, Value]].single(s)
"match (p:Person {name: '1243'}) return p.born".query[Option[Int]].single(s)
"match (p:Person {name: 'Charlize Theron'})-[]->(m:Movie) return p,m".query[Person :: Movie :: HNil].list(s)
"match (p:Person {name: 'Charlize Theron'})-[]->(m:Movie) return p,m".query[(Person, Movie)].list(s)
```

## Showcase

```scala
Expand Down Expand Up @@ -99,34 +68,6 @@ scala> Await.result(peopleCC, 1 second)
res1: Seq[Person] = ArrayBuffer(Person(0,1975,Some(Charlize Theron),None), Person(4,1964,Some(Keanu Reeves),None), Person(5,1967,Some(Carrie-Anne Moss),None), Person(6,1961,Some(Laurence Fishburne),None), Person(7,1960,Some(Hugo Weaving),None), Person(8,1967,Some(Lilly Wachowski),None), Person(9,1965,Some(Lana Wachowski),None), Person(10,1952,Some(Joel Silver),None), Person(11,1978,Some(Emil Eifrem),None), Person(15,1975,Some(Charlize Theron),None))
```

## Supported types


| Type | Query result | Field of a case class | Query parameter |
| ----------------------------------------- |:--------------:| :--------------------:|:-----------------|
| `scala.Int ` ||||
| `scala.Long ` ||||
| `scala.Double ` ||||
| `scala.Float ` ||||
| `java.lang.String ` ||||
| `scala.Option[T] ` ||||
| `scala.Boolean ` |||`*`|
| `scala.Array[Byte] ` ||||
| `scala.Map[String, T: ValueMapper] ` || |`**`|
| `java.time.LocalDate ` ||||
| `java.time.LocalTime ` ||||
| `java.time.LocalDateTime ` ||||
| `org.neo4j.driver.v1.Value ` || ||
| `org.neo4j.driver.v1.types.Node ` ||||
| `org.neo4j.driver.v1.types.Relationship` ||||
| `shapeless.HList ` || ||
| `neotypes.types.Path ` || ||
| `Tuple (1-22) ` || ||
| `User defined case class ` || ||

* `*` - `None` is converted into `null`
* `**` - scala.Map[String, Any]

## Side-effect implementation

In order to support your implementation of side-effects, you need to implement `neotypes.Async[YourIO]` and add to the implicit scope.
Expand Down
22 changes: 19 additions & 3 deletions build.sbt
Expand Up @@ -17,8 +17,8 @@ lazy val root = (project in file("."))
scalaVersion in ThisBuild := "2.12.2",
crossScalaVersions := Seq("2.12.2"),
name := "neotypes",
// compileScalastyle := scalastyle.in(Compile).toTask("").value,
// test in Test := (test in Test).dependsOn(compileScalastyle in Compile).value,
// compileScalastyle := scalastyle.in(Compile).toTask("").value,
// test in Test := (test in Test).dependsOn(compileScalastyle in Compile).value,

/**
* Dependencies
Expand All @@ -36,7 +36,7 @@ lazy val root = (project in file("."))
),

parallelExecution in ThisBuild := false,

/**
* Publishing
*/
Expand All @@ -63,3 +63,19 @@ lazy val root = (project in file("."))
pushChanges
)
)

lazy val microsite = (project in file("docs"))
.settings(moduleName := "docs")
.enablePlugins(MicrositesPlugin)
.settings(
micrositeName := "neotypes",
micrositeDescription := "Scala lightweight, type-safe, asynchronous driver for neo4j",
micrositeAuthor := "dimafeng",
micrositeHighlightTheme := "atom-one-light",
micrositeHomepage := "http://todo",
micrositeDocumentationUrl := "docs.html",
micrositeGithubOwner := "neotypes",
micrositeGithubRepo := "neotypes",
ghpagesNoJekyll := false,
fork in tut := true
)

0 comments on commit db347e4

Please sign in to comment.