Database

Database

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
Name Type Attributes Description
tags string <optional>

Tag filter string

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
Name Type Attributes Description
tags string <optional>

Tag filter string

Returns:

A random matching model, or undefined if none found

Type
*

Database

new Database(optionsopt)

Description:
  • Creates a new Database instance.

Source:
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Configuration options

Properties
Name Type Attributes Description
parser function <optional>

Parser function to process configuration data before adding it to the database. If not provided, configuration is passed directly to the model

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
Name Type Attributes Description
tags string <optional>

Tag filter string

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
Name Type Attributes Description
tags string <optional>

Tag filter string

Returns:

A random matching model, or undefined if none found

Type
*