Delete using Query Builder
Delete
DeleteYou can create DELETE queries using QueryBuilder. Examples:
import {getConnection} from "typeorm";
await getConnection()
.createQueryBuilder()
.delete()
.from(User)
.where("id = :id", { id: 1 })
.execute();This is the most efficient way in terms of performance to delete entities from your database.
Soft-Delete
Soft-DeleteApplying Soft Delete to QueryBuilder
import {createConnection} from "typeorm";
import {Entity} from "./entity";
createConnection(/*...*/).then(async connection => {
await connection
.getRepository(Entity)
.createQueryBuilder()
.softDelete()
}).catch(error => console.log(error));Restore-Soft-Delete
Restore-Soft-DeleteAlternatively, You can recover the soft deleted rows by using the restore() method:
Last updated
Was this helpful?