MCPcopy
hub / github.com/drizzle-team/drizzle-orm / resetSqlite

Function resetSqlite

drizzle-seed/src/index.ts:1188–1205  ·  view source on GitHub ↗
(
	db: BaseSQLiteDatabase<any, any>,
	schema: { [key: string]: SQLiteTable },
)

Source from the content-addressed store, hash-verified

1186
1187// Sqlite------------------------------------------------------------------------------------------------------------------------
1188const resetSqlite = async (
1189 db: BaseSQLiteDatabase<any, any>,
1190 schema: { [key: string]: SQLiteTable },
1191) => {
1192 const tablesToTruncate = Object.entries(schema).map(([_tsTableName, table]) => {
1193 const dbTableName = getTableName(table);
1194 return dbTableName;
1195 });
1196
1197 await db.run(sql.raw('PRAGMA foreign_keys = OFF'));
1198
1199 for (const tableName of tablesToTruncate) {
1200 const sqlQuery = `delete from \`${tableName}\`;`;
1201 await db.run(sql.raw(sqlQuery));
1202 }
1203
1204 await db.run(sql.raw('PRAGMA foreign_keys = ON'));
1205};
1206
1207const filterSqliteTables = (schema: {
1208 [key: string]:

Callers 1

resetFunction · 0.85

Calls 2

getTableNameFunction · 0.90
runMethod · 0.45

Tested by

no test coverage detected