Storage

WORK IN PROGRESS

RingoJS provides a storage framework that allows developers to provide different database backends while exposing the same interface to the application developer.

Store implementations provide two interfaces: The application facing interface that provides a defineEntity() method to define persistent object constructors that can be used to create, retrieve, update, and delete persistent objects, and the internal Store API implementing the actual store functionality.

Depending on the store implementation, the store's defineEntity() method takes one or two arguments: the name of the persistent class, and optionally an object describing the mapping of the persistent type.

For example, the store implementations that are part of RingoJS core modules only take a type name as argument and will automatically persist any properties on persistent objects.

var Person = store.defineEntity('Person');

On the other hand, the ringo-hibernate package expects an object as second argument describing the mapping to a relational database table:

var Person = store.defineEntity('Person', {
    table: 'persons',
    cacheable: false,
    properties: {
        firstName: {type: 'string', nullable: false},
        lastName: {type: 'string', nullable: false},
        birthDate: {type: 'timestamp', nullable: false},
        birthYear: {type: 'integer'},
        ssn: {type: 'string', unique: true},
        vitae: {column: 'resume', type: 'text'}
    }
});

edit this page | list all pages | go home