Readable ⇐ Entity

Kind: global class
Extends: Entity

new Readable(spec)

A readable database entity (table or view).

Param Type Description
spec Object An {@linkcode Entity} specification representing a readable object:
spec.db Object A {@linkcode Database}.
spec.name String The table or view's name.
spec.schema String The name of the schema owning the table or view.
[spec.is_matview] Boolean Whether the object is a materialized view (default false).

readable.count(conditions, params) ⇒ Promise

Count rows matching criteria. There are two ways to use this method:

  1. find() style: db.mytable.count({field: value});
  2. where() style: db.mytable.count("field=$1", [value]);

Kind: instance method of Readable
Returns: Promise - Row count.

Param Type Description
conditions Object | String A criteria object or SQL predicate.
params Array Prepared statement parameters for use with raw SQL predicates.

readable.countDoc(criteria) ⇒ Promise

Count documents matching criteria. Unlike count, this function only supports criteria objects.

Kind: instance method of Readable
Returns: Promise - Number of matching documents.

Param Type Description
criteria Object A criteria object.

readable.find(criteria, [options]) ⇒ Promise

Find rows matching criteria.

Kind: instance method of Readable
Returns: Promise - An array containing any query results.

Param Type Description
criteria Object | UUID | Number A criteria object or primary key value.
[options] Object Select options.

readable.findDoc([criteria], [options]) ⇒ Promise

Find a document by searching in the body.

Kind: instance method of Readable
Returns: Promise - An array containing any query results.

Param Type Description
[criteria] Object | UUID | Number A criteria object or primary key value.
[options] Object Select options.

readable.findOne(criteria, [options]) ⇒ Promise

Return a single record.

Kind: instance method of Readable
Returns: Promise - An object representing the (first) record found, or null if no records match.

Param Type Description
criteria Object | UUID | Number A criteria object or primary key value.
[options] Object Select options.

readable.refresh([concurrently]) ⇒ Promise

Refresh a materialized view.

Kind: instance method of Readable
Returns: Promise - A query with no results.

Param Type Description
[concurrently] Boolean Do it without locking reads.

readable.isPkSearch(criteria) ⇒ Boolean

Determine whether criteria represent a search by primary key. If a number or uuid are passed, it is assumed to be a primary key value; if an object, it must have only one key, which must specify the primary key column.

Kind: instance method of Readable
Returns: Boolean - True if the criteria represent a primary key search.

Param Type Description
criteria Object | String | Number A criteria object or primitive to test.

readable.search(plan, [options]) ⇒ Promise

Perform a full-text search on queryable fields. If options.document is true, looks in the document body fields instead of the table columns.

Kind: instance method of Readable
Returns: Promise - An array containing any query results.

Param Type Description
plan Object Search definition.
plan.fields Array List of the fields to search.
plan.term String Search term.
[plan.where] Object Criteria object to filter results.
[options] Object Select options.

readable.searchDoc(plan, [options]) ⇒ Promise

Shortcut to perform a full text search on a document table.

Kind: instance method of Readable
Returns: Promise - An array containing any query results.

Param Type Description
plan Object Search definition.
[plan.fields] Array List of the document keys to search.
plan.term String Search term.
[plan.where] Object Criteria object to filter results.
[options] Object Select options.

readable.where(conditions, [params], [options]) ⇒ Promise

Run a query with a raw SQL predicate, eg:

db.mytable.where('id=$1', [123]).then(...);

Kind: instance method of Readable
Returns: Promise - An array containing any query results.

Param Type Description
conditions String A raw SQL predicate.
[params] Array Prepared statement parameters.
[options] Object Select options.