Note that there are some explanatory texts on larger screens.

plurals
  1. POSails.JS - Get the count of the number of objects/rows in the database
    primarykey
    data
    text
    <p>In Sails.js, a lot of work is done for you by generating the models and controllers. The controllers allow for access to the data through API's. It allows for easy pagination by passing the start/skip/offset and take/limit. But in order for me to determine the maximum page of a collection I need to know how many items are in a collection.</p> <p>I have tried to extend the blueprint in the generator to expose a new API method <code>count</code> and create the count action. According to the <a href="https://github.com/balderdashy/waterline">Waterline documentation</a>, <code>count</code> is an action that can be called on the model. When I call <code>User.count()</code>, I get this:</p> <pre><code>{ _context: { identity: 'user', adapter: { syncable: false, defaults: [Object], registerCollection: [Function], create: [Function], find: [Function], update: [Function], destroy: [Function], count: [Function], identity: 'odata', globalId: 'odata', config: [Object] }, attributes: {}, _cast: { _types: [Object] }, _schema: { context: [Circular], schema: [Object], hasSchema: true }, _validator: { validations: {} }, _callbacks: { beforeValidation: [Object], afterValidation: [Object], beforeUpdate: [Object], afterUpdate: [Object], beforeCreate: [Object], afterCreate: [Object], beforeDestroy: [Object], afterDestroy: [Object] }, _instanceMethods: {}, autoPK: true, autoCreatedAt: true, autoUpdatedAt: true, hasSchema: true, migrate: 'alter', _model: { [Function] extend: [Function], inject: [Function], __super__: {} }, _transformer: { _transformations: {} }, _tableName: 'user', _adapterDefs: [ [Object] ], _adapter: { adapter: [Object], adapterDefs: [Object], query: [Circular], collection: 'user' }, syncable: [Function], defaults: [Function], registerCollection: [Function], config: [Function], findOneById: [Function: dynamicMethod], findOneByIdIn: [Function: dynamicMethod], findOneByIdLike: [Function: dynamicMethod], findById: [Function: dynamicMethod], findByIdIn: [Function: dynamicMethod], findByIdLike: [Function: dynamicMethod], countById: [Function: dynamicMethod], countByIdIn: [Function: dynamicMethod], countByIdLike: [Function: dynamicMethod], idStartsWith: [Function: dynamicMethod], idContains: [Function: dynamicMethod], idEndsWith: [Function: dynamicMethod], findOneByCreatedAt: [Function: dynamicMethod], findOneByCreatedAtIn: [Function: dynamicMethod], findOneByCreatedAtLike: [Function: dynamicMethod], findByCreatedAt: [Function: dynamicMethod], findByCreatedAtIn: [Function: dynamicMethod], findByCreatedAtLike: [Function: dynamicMethod], countByCreatedAt: [Function: dynamicMethod], countByCreatedAtIn: [Function: dynamicMethod], countByCreatedAtLike: [Function: dynamicMethod], createdAtStartsWith: [Function: dynamicMethod], createdAtContains: [Function: dynamicMethod], createdAtEndsWith: [Function: dynamicMethod], findOneByUpdatedAt: [Function: dynamicMethod], findOneByUpdatedAtIn: [Function: dynamicMethod], findOneByUpdatedAtLike: [Function: dynamicMethod], findByUpdatedAt: [Function: dynamicMethod], findByUpdatedAtIn: [Function: dynamicMethod], findByUpdatedAtLike: [Function: dynamicMethod], countByUpdatedAt: [Function: dynamicMethod], countByUpdatedAtIn: [Function: dynamicMethod], countByUpdatedAtLike: [Function: dynamicMethod], updatedAtStartsWith: [Function: dynamicMethod], updatedAtContains: [Function: dynamicMethod], updatedAtEndsWith: [Function: dynamicMethod] }, _method: [Function], _criteria: {}, _values: null } </code></pre> <p>Note: I am using a custom adapter, but I have created a <code>count</code> method for the adapter.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload