longevity

A Persistence Framework for Scala and NoSQL

View project on GitHub

sqlite translation

Every SQLite table has at least one column: A column named p, which stores the persistent object translated into JSON. If the write timestamps configuration is turned on, then created_timestamp and modified_timestamp columns are added. If optimistic locking is turned on, then a row_version column is also added.

More columns are added to support any keys or indexes for the persistent type. Every property used in a key or index is expanded in to a sequence of property components that all have basic types. These property components are stored in columns, and all have names prefixed with prop_.

The property components that make up your primary key are included in a PRIMARY KEY clause in the CREATE TABLE statement. If you do not define a primaryKey for your PType, longevity will create a column named id, of type text, and use that as the primary key. The primary key values will be random UUID values as generated by java.util.UUID.randomUUID().

All your non-primary keys and indexes will be backed by SQLite indexes, built up from the property components described above. The indexes for non-primary keys will be unique, and the SQLite indexes for longevity indexes will be non-unique.

The property component columns are used to back calls to Repo.retrieve, as well as query retrievals. Please note that queries constructed using properties that are not part of a longevity key or index will fail.

SQLite table names are generated by underscoring the camel-cased name of the persistent class.

prev: mongodb keys
up: translating persistents to the database
next: integration points