Class: Collection

Collection

Class representing the Collection of a Depot database.

Constructor

new Collection(config)

Create a new Collection instance.
Parameters:
Name Type Description
config Object The configuration options for the new Collection instance.
Source:

Members

(private) _insertCount :Integer

Count of inserts.
Type:
  • Integer
Source:

(private) _listenerCount :Integer

Count of registered watchers.
Type:
  • Integer
Source:

(private) _listeners :Object

The internal collection of registered watcher.
Type:
  • Object
Source:

(private) _records :Map

The internal collection of the records.
Type:
  • Map
Source:

(readonly) name :String

The name of the Collection instance.
Type:
  • String
Source:

Methods

find(query) → {Object|Array}

Find existing records.
Parameters:
Name Type Description
query Object The query to use to find all matching records. Passing an id in the query object will remove only the record matching that id regardless of the other fields provided.
Source:
Returns:
The matching records.
Type
Object | Array

insert(record) → {Object}

Insert a new record into a collection.
Parameters:
Name Type Description
record Object The record to insert into the collection.
Source:
Returns:
The inserted record.
Type
Object

remove(query) → {Integer}

Remove an existing record.
Parameters:
Name Type Description
query Object The query to use to find all matching records and remove them. Passing an id in the query object will remove only the record matching that id regardless of the other fields provided.
Source:
Returns:
The id of the record deleted.
Type
Integer

size() → {Integer}

Returns the number of records in the collection.
Source:
Returns:
The number of records in the collection.
Type
Integer

update(newRecord, The)

Update an existing record.
Parameters:
Name Type Description
newRecord Object The record to merge with the existing record, performing an update.
The Object resulting merged object.
Source:

watch(type, callback) → {Integer}

Register watchers for the *, add, remove, update events.
Parameters:
Name Type Description
type String One of the available types: *, add, remove, update.
callback function The callback to call when the event is triggered.
Source:
Returns:
The Id of the watcher.
Type
Integer