* Find all the rows matching your query, within a specified offset / limit, and get the total number of rows matching your query. This is very useful for paging * * @example * const result = await Model.findAndCountAll({ * where: ..., * limit: 12, * offset: 12 * }); *
(options)
| 2170 | * @returns {Promise<{count: number | number[], rows: Model[]}>} |
| 2171 | */ |
| 2172 | static async findAndCountAll(options) { |
| 2173 | if (options !== undefined && !_.isPlainObject(options)) { |
| 2174 | throw new Error('The argument passed to findAndCountAll must be an options object, use findByPk if you wish to pass a single primary key value'); |
| 2175 | } |
| 2176 | |
| 2177 | const countOptions = Utils.cloneDeep(options); |
| 2178 | |
| 2179 | if (countOptions.attributes) { |
| 2180 | countOptions.attributes = undefined; |
| 2181 | } |
| 2182 | |
| 2183 | const [count, rows] = await Promise.all([ |
| 2184 | this.count(countOptions), |
| 2185 | this.findAll(options) |
| 2186 | ]); |
| 2187 | |
| 2188 | return { |
| 2189 | count, |
| 2190 | rows: count === 0 ? [] : rows |
| 2191 | }; |
| 2192 | } |
| 2193 | |
| 2194 | /** |
| 2195 | * Find the maximum value of field |