Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enforced not to run update,delete query without condition ? #5300

Closed
hong-duc opened this issue Jan 8, 2020 · 6 comments
Closed

How to enforced not to run update,delete query without condition ? #5300

hong-duc opened this issue Jan 8, 2020 · 6 comments

Comments

@hong-duc
Copy link

hong-duc commented Jan 8, 2020

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)


Hi I am new to typeorm, as I learning how to use, I see that I can easily make a mistake (like typo, misunderstand api,...) when I write update or delete query using query builder and it run without where condition and end up with all data getting updated or deleted. So my question is that in typeorm is there any option or a hacky way that when a update or delete query running without a where condition it will throw error to prevent these kind of mistake for newbie ?. Thank you

@angelvega93
Copy link

If you run a delete query without conditions its normal to delete all data.

This is not a TypeORM problem, you need to validate before sending the query.

@hong-duc
Copy link
Author

@angelvega93 yes and that why this is a question, not bug report, thank you very much

@Destreyf
Copy link

@hong-duc To answer your question directly, TypeORM does not have any sort of developer safety functionality built into it, you could probably write your own validation/restriction logic, but this could end up being very cumbersome and ultimately may not make a lot of sense for your use case.

@hong-duc
Copy link
Author

@Destreyf thank you for your answer.
I know this is a naive question but I have my reason. Right now only me using typeorm, but I want my team to use it too. I can guarantee that some will make the same mistake as me. That is why I ask this question to make sure they fail with an error rather than a database delete

@anton-bot
Copy link

Just for context, it's possible to unintentionally delete the entire table by providing arguments to .delete() in a wrong format: #6620

@imnotjames
Copy link
Contributor

Duplicate of #3416

@imnotjames imnotjames marked this as a duplicate of #3416 Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants