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

Method findAndCountAll

lib/model.js:2093–2113  ·  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

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

Callers 12

model.tsFile · 0.80
testFunction · 0.80
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
count.test.jsFile · 0.80

Calls 3

countMethod · 0.95
findAllMethod · 0.95
allMethod · 0.80

Tested by 1

testFunction · 0.64