Home Reference Source Test
import {CollectionTransaction} from 'kinto/lib/collection.js'
public class | source

CollectionTransaction

A Collection-oriented wrapper for an adapter's transaction.

This defines the high-level functions available on a collection. The collection itself offers functions of the same name. These will perform just one operation in its own transaction.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public
public
Private Members
private

_events: *[]

Method Summary

Public Methods
public

create(record,: Object): Object

Adds a record to the local database, asserting that none already exist with this ID.

public

delete(id: String, options: Object): Object

Deletes a record from the local database.

public

deleteAll(ids: Array): Object

Soft delete all records from the local database.

public

deleteAny(id: String): Object

Deletes a record from the local database, if any exists.

public

Emit queued events, to be called once every transaction operations have been executed successfully.

public

get(id: String, options: Object): Object

Retrieve a record by its id from the local database.

public

getAny(id: String): Object

Retrieve a record by its id from the local database, or undefined if none exists.

public

update(record: Object, options: Object): Object

Updates a record from the local database.

public

upsert(record: Object): Object

Upsert a record into the local database.

Private Methods
private

_queueEvent(action: *, payload: *)

private

_updateRaw(oldRecord:: Object, newRecord:: Object): Object

Lower-level primitive for updating a record while respecting _status and last_modified.

Public Constructors

public constructor() source

Public Members

public adapterTransaction: * source

public collection: * source

Private Members

private _events: *[] source

Public Methods

public create(record,: Object): Object source

Adds a record to the local database, asserting that none already exist with this ID.

Params:

NameTypeAttributeDescription
record, Object

which must contain an ID

Return:

Object

public delete(id: String, options: Object): Object source

Deletes a record from the local database.

Options:

  • {Boolean} virtual: When set to true, doesn't actually delete the record, update its _status attribute to deleted instead (default: true)

Params:

NameTypeAttributeDescription
id String

The record's Id.

options Object

The options object.

Return:

Object

public deleteAll(ids: Array): Object source

Soft delete all records from the local database.

Params:

NameTypeAttributeDescription
ids Array

Array of non-deleted Record Ids.

Return:

Object

public deleteAny(id: String): Object source

Deletes a record from the local database, if any exists. Otherwise, do nothing.

Params:

NameTypeAttributeDescription
id String

The record's Id.

Return:

Object

public emitEvents() source

Emit queued events, to be called once every transaction operations have been executed successfully.

public get(id: String, options: Object): Object source

Retrieve a record by its id from the local database.

Options:

  • {Boolean} includeDeleted: Include virtually deleted records.

Params:

NameTypeAttributeDescription
id String
options Object

Return:

Object

public getAny(id: String): Object source

Retrieve a record by its id from the local database, or undefined if none exists.

This will also return virtually deleted records.

Params:

NameTypeAttributeDescription
id String

Return:

Object

public update(record: Object, options: Object): Object source

Updates a record from the local database.

Options:

  • {Boolean} synced: Sets record status to "synced" (default: false)
  • {Boolean} patch: Extends the existing record instead of overwriting it (default: false)

Params:

NameTypeAttributeDescription
record Object
options Object

Return:

Object

public upsert(record: Object): Object source

Upsert a record into the local database.

This record must have an ID.

If a record with this ID already exists, it will be replaced. Otherwise, this record will be inserted.

Params:

NameTypeAttributeDescription
record Object

Return:

Object

Private Methods

private _queueEvent(action: *, payload: *) source

Params:

NameTypeAttributeDescription
action *
payload *

private _updateRaw(oldRecord:: Object, newRecord:: Object): Object source

Lower-level primitive for updating a record while respecting _status and last_modified.

Params:

NameTypeAttributeDescription
oldRecord: Object

the record retrieved from the DB

newRecord: Object

the record to replace it with

Return:

Object