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. |
Members
fieldTypes
Mapping of field types to validation functions
idField
The name of the `id` in a row's data
lookupTypes
The available lookup types for basic filtering
Methods
all() → {array}
Returns all rows found in the table.
Returns:
An array of objects for all the rows
- Type
- array
count() → {integer}
Returns a count of the number of rows in the table.
Returns:
How many rows are in the table
- Type
- integer
create() → {null}
Creates the table (if not already present).
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. |
Returns:
- Type
- null
drop() → {null}
Drops the table & all rows from the storage.
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. |
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. |
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. |
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 |
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 |
Throws:
If the fields fail to validate
Returns:
- Type
- null