# Delete using Query Builder

# Delete

You can create DELETE queries using QueryBuilder. Examples:

await myDataSource
    .createQueryBuilder()
    .delete()
    .from(User)
    .where("id = :id", { id: 1 })
    .execute()
1
2
3
4
5
6

This is the most efficient way in terms of performance to delete entities from your database.

# Soft-Delete

Applying Soft Delete to QueryBuilder

await dataSource.getRepository(Entity).createQueryBuilder().softDelete()
1

# Restore-Soft-Delete

Alternatively, You can recover the soft deleted rows by using the restore() method:

await dataSource.getRepository(Entity).createQueryBuilder().restore()
1