-
Notifications
You must be signed in to change notification settings - Fork 2
Node CRUD
Michel Perez edited this page Oct 18, 2015
·
4 revisions
Let's create a simple case class to persist it as a Node on the database:
case class MyUser(id: String, name: String, age: Int)
For persisting this class we need to create and make implicit a Mapper and a NeoNode for the class:
import com.kreattiewe.mapper.macros.Mappable
implicit val myUserMapper = Mapper.build[MyUser]
implicit val userNode = NeoNode("user", "id", (user: MyUser) => user.id)
Be sure to import the Mappable macro that is used by the Mapper.Build method.
The NeoNode.apply method takes the label for the node, the unique column and a function that receives an Instance of my user and returns a string that represents the unique key in the database for the node.
import com.kreattiewe.neo4s.orm.NeoNodeOperations._
val node1 = MyUser("1", "Michel Perez", 27)
node1.save()
By importing the NeoNodeOperations we can use the CRUD operations on our nodes. That way we can call the methods save, update, delete, deleteWithRelations, methods on the case class node.