MCPcopy
hub / github.com/sequelize/sequelize / findAndCountAll

Method findAndCountAll

src/model.js:2172–2192  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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

Callers 12

include.test.jsFile · 0.80
has-many.test.jsFile · 0.80
belongs-to.test.jsFile · 0.80
schema.test.jsFile · 0.80
findAll.test.jsFile · 0.80
searchPath.test.jsFile · 0.80
model.tsFile · 0.80
testFunction · 0.80
count.test.jsFile · 0.80

Calls 3

countMethod · 0.95
findAllMethod · 0.95
allMethod · 0.80

Tested by 1

testFunction · 0.64