* 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)
| 2091 | * @returns {Promise<{count: number | number[], rows: Model[]}>} |
| 2092 | */ |
| 2093 | static async findAndCountAll(options) { |
| 2094 | if (options !== undefined && !_.isPlainObject(options)) { |
| 2095 | 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'); |
| 2096 | } |
| 2097 | |
| 2098 | const countOptions = Utils.cloneDeep(options); |
| 2099 | |
| 2100 | if (countOptions.attributes) { |
| 2101 | countOptions.attributes = undefined; |
| 2102 | } |
| 2103 | |
| 2104 | const [count, rows] = await Promise.all([ |
| 2105 | this.count(countOptions), |
| 2106 | this.findAll(options) |
| 2107 | ]); |
| 2108 | |
| 2109 | return { |
| 2110 | count, |
| 2111 | rows: count === 0 ? [] : rows |
| 2112 | }; |
| 2113 | } |
| 2114 | |
| 2115 | /** |
| 2116 | * Find the maximum value of field |