longevity

A Persistence Framework for Scala and NoSQL

View project on GitHub

persistent objects

As longevity is primarily a persistence framework, the common currency of the longevity API is the persistent object. Persistent objects are part of your domain model, and they are also the persistence unit - something that you can create, retrieve, update or delete with a longevity repository.

Persistent objects are Scala case classes that meet some basic criteria. Those criteria are laid out in the chapters that follow.

Here’s a simple example:

case class User(
  username: String,
  firstName: String,
  lastName: String)

To tell longevity that this is a persistent object, we simply mark the class with a persistent annotation. At a minimum, we need to provide a keySet to the persistent annotation. For now, we can provide an empty set of keys, like so:

import longevity.model.annotations.persistent

@persistent(keySet = emptyKeySet)
case class User(
  username: String,
  firstName: String,
  lastName: String)

Here is how you would do the same thing without the annotation:

import longevity.model.PType

case class User(
  username: String,
  firstName: String,
  lastName: String)

object User extends PType[User] {
  object props {
    // ...
  }
  val keySet = emptyKeySet
}
prev: the domain model
up: the domain model
next: basic values