new Database()
- Description:
A generic database class for storing and querying models. Subclasses can implement more specific logic around each model (particularly, the code to convert configuration data into specific models...each model type can have its own compact serialization format).
- Source:
Members
models :Array
- Description:
Array of models stored in the database.
- Source:
Array of models stored in the database.
Type:
- Array
parser :function
- Description:
Parser function used to process data before passing it to the model constructor
- Source:
Parser function used to process data before passing it to the model constructor
Type:
- function
Methods
add(…data) → {Database}
- Description:
Adds one or more data items to the database.
- Source:
Example
database.add(item1, item2, item3);
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
data |
* |
<repeatable> |
Data items to add to the database |
Returns:
Returns this instance for method chaining
- Type
- Database
findAll(optionsopt) → {Array}
- Description:
Finds all models that match the specified criteria. Subclasses may add additional search parameters, but all models support searching by tags.
- Source:
Example
database.findAll({ tags: "weapon firearm" });
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
{}
|
Search criteria Properties
|
Returns:
Array of matching models
- Type
- Array
findOne(optionsopt) → {*}
- Description:
Finds a random model that matches the specified criteria. Subclasses may add additional search parameters, but all models support searching by tags.
- Source:
Example
database.findOne({ tags: "weapon firearm" });
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
{}
|
Search criteria Properties
|
Returns:
A random matching model, or undefined if none found
- Type
- *