From 09f3c1d1e04eed8fdca6e9582433e048dfed32e0 Mon Sep 17 00:00:00 2001 From: Michael Pollmeier Date: Sat, 8 Sep 2018 09:47:24 +0200 Subject: [PATCH] update test/readme re https://github.com/mpollmeier/gremlin-scala/issues/158#issuecomment-419481835 --- README.md | 6 +++++- .../gremlin/scala/MarshallableSpec.scala | 20 +++++++++---------- version.sbt | 1 - 3 files changed, 14 insertions(+), 13 deletions(-) delete mode 100644 version.sbt diff --git a/README.md b/README.md index bb03bbac..dbc2d6b1 100644 --- a/README.md +++ b/README.md @@ -226,7 +226,11 @@ g.V.has(age).order(By(age, Order.decr)) More working examples in [TraversalSpec](https://github.com/mpollmeier/gremlin-scala/blob/master/gremlin-scala/src/test/scala/gremlin/scala/TraversalSpec.scala). ### Mapping vertices from/to case classes -You can save and load case classes as a vertex - implemented with a [blackbox macro](http://docs.scala-lang.org/overviews/macros/blackbox-whitebox.html). You can optionally annotate the id and label of your case class. Scala's `Option` types will be automatically unwrapped, i.e. a `Some[A]` will be stored as the value of type `A` in the database, or `null` if it's `None`. If we wouldn't unwrap it, the database would have to understand Scala's Option type itself. The same goes for value classes, i.e. a `case class ShoeSize(value: Int) extends AnyVal` will be stored as an Integer. Note: your classes must be defined outside the scope where they are being used (e.g. in the code below the class `Example` cannot be inside `object Main`). +You can save and load case classes as a vertex - implemented with a [blackbox macro](http://docs.scala-lang.org/overviews/macros/blackbox-whitebox.html). You can optionally annotate the id and label of your case class. Scala's `Option` types will be automatically unwrapped, i.e. a `Some[A]` will be stored as the value of type `A` in the database, or `null` if it's `None`. If we wouldn't unwrap it, the database would have to understand Scala's Option type itself. The same goes for value classes, i.e. a `case class ShoeSize(value: Int) extends AnyVal` will be stored as an Integer. + +Note: your classes must be defined outside the scope where they are being used (e.g. in the code below the class `Example` cannot be inside `object Main`). + +Note: you cannot specify the id when adding a vertex like this. Using `@id` only works when retrieving the vertex back from the graph. ```scala // this does _not_ work in a REPL diff --git a/gremlin-scala/src/test/scala/gremlin/scala/MarshallableSpec.scala b/gremlin-scala/src/test/scala/gremlin/scala/MarshallableSpec.scala index cb51fd6b..928d0ff4 100644 --- a/gremlin-scala/src/test/scala/gremlin/scala/MarshallableSpec.scala +++ b/gremlin-scala/src/test/scala/gremlin/scala/MarshallableSpec.scala @@ -20,9 +20,8 @@ case class CCWithOptionIdNested(s: String, @id id: Option[Int], i: MyValueClass) case class CCWithLabel(s: String) @label("the_label") -case class CCWithLabelAndId( +case class ComplexCC( s: String, - @id id: Int, l: Long, o: Option[String], seq: Seq[String], @@ -125,9 +124,8 @@ class MarshallableSpec extends WordSpec with Matchers { } "use @label and @id annotations" in new Fixture { - val ccWithLabelAndId = CCWithLabelAndId( + val cc = ComplexCC( "some string", - id = Int.MaxValue, Long.MaxValue, Some("option type"), Seq("test1", "test2"), @@ -135,16 +133,16 @@ class MarshallableSpec extends WordSpec with Matchers { NestedClass("nested") ) - val v = graph + ccWithLabelAndId + val v = graph + cc val vl = graph.V(v.id).head vl.label shouldBe "the_label" - vl.valueMap should contain("s" -> ccWithLabelAndId.s) - vl.valueMap should contain("l" -> ccWithLabelAndId.l) - vl.valueMap should contain("o" -> ccWithLabelAndId.o.get) - vl.valueMap should contain("seq" -> ccWithLabelAndId.seq) - vl.valueMap should contain("map" -> ccWithLabelAndId.map) - vl.valueMap should contain("nested" -> ccWithLabelAndId.nested) + vl.valueMap should contain("s" -> cc.s) + vl.valueMap should contain("l" -> cc.l) + vl.valueMap should contain("o" -> cc.o.get) + vl.valueMap should contain("seq" -> cc.seq) + vl.valueMap should contain("map" -> cc.map) + vl.valueMap should contain("nested" -> cc.nested) } "have an Option @id annotation" in new Fixture { diff --git a/version.sbt b/version.sbt deleted file mode 100644 index 73fa549d..00000000 --- a/version.sbt +++ /dev/null @@ -1 +0,0 @@ -version in ThisBuild := "3.3.3.5-SNAPSHOT"