0%

删除所有表数据

1
2
3
4
5
6
7
8
9
10
import { getConnection } from "typeorm";

export default async () => {
const connection = getConnection();
const entities = connection.entityMetadatas;
for (const entity of entities) {
const repository = getConnection().getRepository(entity.name); // Get repository
await repository.delete({}); // Clear each entity table's content
}
};