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

Method findByPk

src/model.js:1937–1956  ·  view source on GitHub ↗

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

(param, options)

Source from the content-addressed store, hash-verified

1935 * @returns {Promise<Model>}
1936 */
1937 static async findByPk(param, options) {
1938 // return Promise resolved with null if no arguments are passed
1939 if ([null, undefined].includes(param)) {
1940 return null;
1941 }
1942
1943 options = Utils.cloneDeep(options) || {};
1944
1945 if (typeof param === 'number' || typeof param === 'bigint' || typeof param === 'string' || Buffer.isBuffer(param)) {
1946 options.where = {
1947 [this.primaryKeyAttribute]: param
1948 };
1949 } else {
1950 throw new Error(`Argument passed to findByPk is invalid: ${param}`);
1951 }
1952
1953 // Bypass a possible overloaded findOne
1954 // note: in v6, we don't bypass overload https://github.com/sequelize/sequelize/issues/14003
1955 return await this.findOne(options);
1956 }
1957
1958 /**
1959 * Search for a single instance. Returns the first instance found, or null if none can be found.

Callers 15

error.test.jsFile · 0.80
data-types.test.jsFile · 0.80
timezone.test.jsFile · 0.80
model.test.jsFile · 0.80
verifyDeadlockFunction · 0.80
sequelize.test.jsFile · 0.80
instance.test.jsFile · 0.80
dao.test.jsFile · 0.80

Calls 1

findOneMethod · 0.95

Tested by 2

verifyDeadlockFunction · 0.64