A Persistence Framework for Scala and NoSQL

View project on GitHub

schema creation

Most back ends will need to perform some sort of schema creation routine before the repositories are ready to use. The behavior of using the repositories without schema creation will vary dramatically, depending on the back end. The cassandra back end will not run at all. MongoDB is more forgiving, and the repositories will function without any schema creation, but performance will suffer due to the lack of indexes. (You will also fail to get any exceptions due to duplicate key values, as discussed in the section on method Repo.create.) For the in-memory back end, schema creation is a no-op.

You can create the requisite schema by calling Repo.createSchema. This method returns an F[Unit] - that is, the completion of the effect will only indicate success or failure.

An alternative way to generate schema is to set the configuration flag longevity.autoCreateSchema to true. In this case, schema will be generated when the connection is opened. Schema autogeneration is a convenient feature for testing or development work, but will incur an overhead for every program run.

Schema generation is always a non-destructive process, and you will never lose any data when generating schema.

prev: opening and closing the connection
up: the repository
next: the persistent state