MCPcopy
hub / github.com/sequelize/sequelize / findByPk

Method findByPk

lib/model.js:1877–1895  ·  lib/model.js::Model.findByPk

* Search for a single instance by its primary key._ * * @param {number|string|Buffer} param The value of the desired instance's primary key. * @param {object} [options] find options * @param {Transaction} [options.transaction] Transaction to run q

(param, options)

Source from the content-addressed store, hash-verified

1875 * @returns {Promise<Model>}
1876 */
1877 static async findByPk(param, options) {
1878 class="cm">// return Promise resolved with null if no arguments are passed
1879 if ([null, undefined].includes(param)) {
1880 return null;
1881 }
1882
1883 options = Utils.cloneDeep(options) || {};
1884
1885 if (typeof param === class="st">'number' || typeof param === class="st">'string' || Buffer.isBuffer(param)) {
1886 options.where = {
1887 [this.primaryKeyAttribute]: param
1888 };
1889 } else {
1890 throw new Error(`Argument passed to findByPk is invalid: ${param}`);
1891 }
1892
1893 class="cm">// Bypass a possible overloaded findOne
1894 return await this.findOne(options);
1895 }
1896
1897 /**
1898 * Search for a single instance. Returns the first instance found, or null if none can be found.

Callers 15

findByPk.tsFile · 0.80
stuffFunction · 0.80
stuffTwoFunction · 0.80
doStuffFunction · 0.80
doStuffWithUserFunction · 0.80
doStuffFunction · 0.80
getMethod · 0.80
error.test.jsFile · 0.80
data-types.test.jsFile · 0.80
timezone.test.jsFile · 0.80
model.test.jsFile · 0.80

Calls 1

findOneMethod · 0.95

Tested by 2

verifyDeadlockFunction · 0.64