Last active
June 7, 2021 04:24
-
-
Save proclaim/63c2dedf4d1cf40dc4f5460a7d74c2d2 to your computer and use it in GitHub Desktop.
typeorm delete multiple records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// assume entityIds is an array | |
connection.createQueryBuilder() | |
.delete() | |
.from(entity) | |
.where('entity.id IN (:...ids)', { ids: entityIds }) | |
.execute() | |
This way works.
This "...ids" is not "SQL" right ? it's seem like JS expression, So it's allowed to put expression there ?
I agree, not sure you can run the spread operator in that string since it will get translated to sql
getConnection()
.createQueryBuilder()
.delete()
.from(entity)
.where('id In(:id)', {
id: ['1','2'],
})
.execute();
This way works.
This "...ids" is not "SQL" right ? it's seem like JS expression, So it's allowed to put expression there ?
I agree, not sure you can run the spread operator in that string since it will get translated to sqlgetConnection() .createQueryBuilder() .delete() .from(entity) .where('id In(:id)', { id: ['1','2'], }) .execute();
that'll do! the code that I'm using will be compiled so it worked on my end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This "...ids" is not "SQL" right ? it's seem like JS expression, So it's allowed to put expression there ?