Add Model.exists()
to allow efficient checking of at least one matching row
#17300
Open
2 of 6 tasks
Labels
pending-approval
Bug reports that have not been verified yet, or feature requests that have not been accepted yet
type: feature
For issues and PRs. For new features. Never breaking changes.
Feature Description
Describe the feature you'd like to see implemented
Add a new
exists
method on model, taking the same parameters asfindOne
, which returns a boolean of whether at least one matching row exists in the database.Example usage:
Under the hood this would execute a count query limited to 1 and coerce to a boolean, so that it's efficient on the database and network.
Describe why you would like this feature to be added to Sequelize
This is a convenience method. I recently needed this to avoid O(NM) complexity in a check. I ended up using
findOne
instead and checking for a null, but didn't need the resulting model instance.The limit of 1 is more efficient for large queries.
The API mirrors a Django's QuerySet.exists
Is this feature dialect-specific?
Would you be willing to resolve this issue by submitting a Pull Request?
Indicate your interest in the addition of this feature by adding the 👍 reaction. Comments such as "+1" will be removed.
The text was updated successfully, but these errors were encountered: