Class: LocalTable

localtable/table~LocalTable(storage, tableName, options)

A class representing a table of similar rows.

Constructor

new LocalTable(storage, tableName, options)

Creates a new `LocalTable` instance.
Parameters:
Name Type Description
storage Storage Reference to the `Storage`-like object that will keep the data.
tableName string The name of the table.
options object The options for instantiating the table.
Source:

Members

fieldTypes

Mapping of field types to validation functions
Source:

idField

The name of the `id` in a row's data
Source:

lookupTypes

The available lookup types for basic filtering
Source:

Methods

all() → {array}

Returns all rows found in the table.
Source:
Returns:
An array of objects for all the rows
Type
array

count() → {integer}

Returns a count of the number of rows in the table.
Source:
Returns:
How many rows are in the table
Type
integer

create() → {null}

Creates the table (if not already present).
Source:
Returns:
Type
null

delete(id) → {null}

Deletes a row from the table.
Parameters:
Name Type Description
id any The identifier of the row. Typically an integer, but can be a string/UUID/etc.
Source:
Returns:
Type
null

drop() → {null}

Drops the table & all rows from the storage.
Source:
Returns:
Type
null

exists(id) → {boolean}

Checks if a row is in the table.
Parameters:
Name Type Description
id any The identifier of the row. Typically an integer, but can be a string/UUID/etc.
Source:
Returns:
True if present, else False.
Type
boolean

filter(filterBy) → {array}

Returns a filtered set of rows from the table.
Parameters:
Name Type Description
filterBy object | function Either a plain object of filters or a user-defined function to do the filtering.
Source:
Throws:
If invalid fields or lookup types are provided
Returns:
An array of objects of matched rows
Type
array

get(id) → {object}

Fetches a specific row from the table.
Parameters:
Name Type Description
id any The identifier of the row. Typically an integer, but can be a string/UUID/etc.
Source:
Throws:
If the provided ID is not present in the table.
Returns:
The detail data for the row
Type
object

insert(id, data) → {null}

Inserts a new row into the table.
Parameters:
Name Type Description
id any The identifier of the row. Typically an integer, but can be a string/UUID/etc.
data object The field data for the row
Source:
Throws:
If the id is already present in the table or the fields fail to validate
Returns:
Type
null

update(id, data) → {null}

Updates an existing row (or inserts a new row if not present) into the table.
Parameters:
Name Type Description
id any The identifier of the row. Typically an integer, but can be a string/UUID/etc.
data object The changed field data for the row
Source:
Throws:
If the fields fail to validate
Returns:
Type
null