list()

Shortcut for listing entities from a Model. For complete control (pagination, start, end...) use the @google-cloud queries. When you configure a list() shortcut query on a Schema, you can then later quickly fetch entities with pre-configured settings, like the order by or limit (those settings can be overridden later on).

1. Configure "list" query options on the Schema

entitySchema.queries('list', options);

options

The options object accepts the following "queries" properties

  • limit

  • order

  • select

  • ancestors

  • filters (default operator is "=" and does not need to be passed)

  • start

  • offset

INFO: "order", "select" & "filters" can also be Arrays of settings (see example below).

Additional configuration The options accepts also the following properties

  • namespace {string}

  • readAll {boolean} true | false

  • format {string} "JSON" | "ENTITY" (default: "JSON")

  • showKey {boolean} true | false

  • cache {boolean} true | false

  • ttl {number | object}

  • consistency {'strong' | 'eventual'}

namespace Overrides the default gstore instance namespace.

showKey (default: false)

Adds a "__key" property to the entity data with the complete Key information from the Datastore.

cache (default: the "global" cache configuration) "true" = read from the cache and prime the cache with the query response.

ttl (default: the cache.ttl.queries value) Custom TTL value for the cache. For multi-store it can be an object of TTL values.

consistency Specify either "strong" or "eventual". If not specified, default values are chosen by Datastore for the operation. Learn more about strong and eventual consistency here.

Example:

2. Use anywhere

MyModel.list(options /*optional*/)

@Returns: the response is an object with 2 properties:

  • entities

  • nextPageCursor // only present if there are more results to fetch

The nextPageCursor is for pagination and can be used in a future call to MyModel.list({ start: pageCursor })

Example:

Example with Arrays of values (order, select, filters)

Filters

The value of a filter can also be a function that returns a value. This function will be executed on each request. Useful for dynamic value for example when retrieving the current date.

Example

Override settings

The global configuration set on the Schema can be overridden anytime by passing a new options object. Model.list(options)

Last updated

Was this helpful?