MCPcopy
hub / github.com/sequelize/sequelize / findOne

Method findOne

lib/model.js:1909–1931  ·  lib/model.js::Model.findOne

* Search for a single instance. Returns the first instance found, or null if none can be found. * * @param {object} [options] A hash of options to describe the scope of the search * @param {Transaction} [options.transaction] Transaction to run query under * @param {string}

(options)

Source from the content-addressed store, hash-verified

1907 * @returns {Promise<Model|null>}
1908 */
1909 static async findOne(options) {
1910 if (options !== undefined && !_.isPlainObject(options)) {
1911 throw new Error(class="st">'The argument passed to findOne must be an options object, use findByPk if you wish to pass a single primary key value');
1912 }
1913 options = Utils.cloneDeep(options);
1914
1915 if (options.limit === undefined) {
1916 const uniqueSingleColumns = _.chain(this.uniqueKeys).values().filter(c => c.fields.length === 1).map(class="st">'column').value();
1917
1918 class="cm">// Don't add limit if querying directly on the pk or a unique column
1919 if (!options.where || !_.some(options.where, (value, key) =>
1920 (key === this.primaryKeyAttribute || uniqueSingleColumns.includes(key)) &&
1921 (Utils.isPrimitive(value) || Buffer.isBuffer(value))
1922 )) {
1923 options.limit = 1;
1924 }
1925 }
1926
1927 class="cm">// Bypass a possible overloaded findAll.
1928 return await this.findAll(_.defaults(options, {
1929 plain: true
1930 }));
1931 }
1932
1933 /**
1934 * Run an aggregation method on the specified field

Callers 15

findByPkMethod · 0.95
findOrBuildMethod · 0.95
findOrCreateMethod · 0.95
findCreateFindMethod · 0.95
where.tsFile · 0.80
model.tsFile · 0.80
testFunction · 0.80
testUntypedFunction · 0.80
findOne.tsFile · 0.80
testFunction · 0.80
doStuffWithUserModelFunction · 0.80
reloadMethod · 0.80

Calls 1

findAllMethod · 0.95

Tested by 3

testFunction · 0.64
testFunction · 0.64
executeTestFunction · 0.64