Skip to content

Dexie.Syncable.IDatabaseChange

David Fahlander edited this page Jun 10, 2014 · 33 revisions
Abstract Base Interface

interface IDatabaseChange {
Number type; // 1 = CREATE, 2 = UPDATE, 3 = DELETE
String table;
any key;
};

Sub Interface for CREATE

interface IDatabaseCreateChange : IDatabaseChange {
Object obj; // Created Object
};

Sub Interface for UPDATE

interface IDatabaseUpdateChange : IDatabaseChange {
Object mods; // Set of keyPaths and their altered values
};

Sub Interface for DELETE

interface IDatabaseDeleteChange : IDatabaseChange {
};

Description

Interface of a database change. The property 'type' tells whether the change is a creation (1), update (2) or deletion (3) of the given key in the given table.

If change is a creation, 'obj' will contain the created object.

If change is an update, 'mods' will contain a set of property paths and their altered values. A property path is the name of the property for root-properties. For nestled properties, the property path will be a dot-based path to the changed property.

Sample

Given the following object:

{
    id: "faec7477-aaff-4525-a2d8-b817f8197bf7",
    address: {
        street: "Elm Street",
        city: "New York"
    }
}

If street has been changed to "East 13:th Street", the IDatabaseUpdateChange would look like this:

{
    type: 2, // UPDATE
    table: "table",
    key: "faec7477-aaff-4525-a2d8-b817f8197bf7",
    mods: {
        "address.street": "East 13:th Street"
    }
}
Clone this wiki locally