DynamicRecord

Constructor

new DynamicRecord()

(DEPRECATED - Use createInstance() instead)

Creates a new DynamicRecord instance.

Parameters:

  • options: object
  • options.tableSlug: string - The slug of the table. Must be lowercase only and not containing any whitespace

Methods

closeConnection

Close the connection to the database server. Only used to terminate the running node instance.

findBy → Promise

Find the latest entry in the table that match the query.

Parameters:

  • query: object - A key value pair that will be used to match for entry in the database

Returns:

Promise - Return promise of DynamicRecord.Model instance or null

where → Promise

Find all the entries in the table that match the query.

You can sort the returned data by providing a string key to sort the data by or a sorting function to manually sort the data. By default they are sorted in the order they are in in the database.

Parameters:

  • query: object - A key value pair that will be used to match for entries
  • options: object - Query options object
  • options.limit: number - Limit the number of maximum returned entries
  • options.offset: number - Number of entries to offset by before starting query
  • options.sort: object - Sorting order of returned entries. Defined by providing the column to sort by as key and "ASC" "DESC" as value for ascending and descending respectively.

Returns:

Promise - Return promise of DynamicCollection instance

all → Promise

Return all entries from the table.

Returns:

Promise - Return promise of DynamicCollection instance

first → Promise

Return the first entry in the table. If provided query option 'limit', it will return the first nth entry in the database wrapped in a Promise of DynamicCollection from first inserted forward.

Parameters:

  • options: object - Query options object
  • options.limit: number - Specify the number of entries to return. If not defined, defaults to 1.
  • options.offset: number - Number of entries to offset by before starting query
  • options.sort: object - Sorting order of returned entries. Defined by providing the column to sort by as key and "ASC" "DESC" as value for ascending and descending respectively.

Returns:

Promise - Return promise of DynamicRecord.Model instance, DynamicCollection instance, or null

last → Promise

Return the last entry in the table. If provided query option 'limit', it will return the last nth entry in the database wrapped in a Promise of DynamicCollection from last inserted backward.

Parameters:

  • options: object - Query options object
  • options.limit: number - Specify the number of entries to return. If not defined, defaults to 1.
  • options.offset: number - Number of entries to offset by before starting query
  • options.sort: object - Sorting order of returned entries. Defined by providing the column to sort by as key and "ASC" "DESC" as value for ascending and descending respectively.

Returns:

Promise - Return promise of DynamicRecord.Model instance, DynamicCollection instance, or null