Skip to content

Latest commit

 

History

History
128 lines (81 loc) · 3.52 KB

File metadata and controls

128 lines (81 loc) · 3.52 KB

Table

A table is created from a database instance using Database::createTable method. All data manipulation operations are transactional i.e until saved, none of the mutative queries are executed

Methods

Insert rows

Queues a query to insert the given rows.

table.insert(row[, row, ...rows]);
Param Required Type Default Description
...rows Yes Object list None One or more objects to be inserted into the table

Throws

  • When one or more rows is not provided.
  • When one of the rows is not an object.

Returns

The current instance of Table.

Notes

  • Does not mutate the table until Table::save is called.
  • Can be reverted before saving using Table::revert.

Query rows

Queries rows matched by the filter.

table.query([filter]);
Param Required Type Default Description
filter No one of
  • Number
  • Array
  • Function
[Function: () => true] Takes in an id or an array of ids or a filter function that will be matched against row

Returns

A Promise that resolves to a an array of rows that is matched by the given filter.

Update rows

Queues a query to update the rows that are matched by the given filter, and run given update on each of the filtered row to get the updated row.

table.update(update[, filter]);
Param Required Type Default Description
update Yes Function None A non mutative function that will be run on each row
filter No one of
  • Number
  • Array
  • Function
[Function: () => true] Takes in an id or an array of ids or a filter function that will be matched against row

Throws

  • When udpate is not a function.
  • When udpate might mutate the row.
  • When udpate might return a value other than an Object.

Returns

The current instance of Table.

Notes

  • Does not mutate the table until Table::save is called.
  • Can be reverted before saving using Table::revert.

Delete rows

Queues a query to delete the rows that are matched by the given filter.

table.delete([filter]);
Param Required Type Default Description
filter No one of
  • Number
  • Array
  • Function
[Function: () => true] Takes in an id or an array of ids or a filter function that will be matched against row

Returns

The current instance of Table.

Notes

  • Does not mutate the table until Table::save is called.
  • Can be reverted before saving using Table::revert.

Save queries

Saves queued queries to the table. Once done, it empties the query queue.

table.save();

Returns

A Promise that would resolve once the queries are successfully saved to table.

Revert queries

Empties the pending query queue.

table.revert();

Returns

The current instance of Table.