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

Function resetMySql

drizzle-seed/src/index.ts:867–884  ·  view source on GitHub ↗
(
	db: MySqlDatabase<any, any>,
	schema: { [key: string]: MySqlTable },
)

Source from the content-addressed store, hash-verified

865
866// MySql-----------------------------------------------------------------------------------------------------
867const resetMySql = async (
868 db: MySqlDatabase<any, any>,
869 schema: { [key: string]: MySqlTable },
870) => {
871 const tablesToTruncate = Object.entries(schema).map(([_tsTableName, table]) => {
872 const dbTableName = getTableName(table);
873 return dbTableName;
874 });
875
876 await db.execute(sql.raw('SET FOREIGN_KEY_CHECKS = 0;'));
877
878 for (const tableName of tablesToTruncate) {
879 const sqlQuery = `truncate \`${tableName}\`;`;
880 await db.execute(sql.raw(sqlQuery));
881 }
882
883 await db.execute(sql.raw('SET FOREIGN_KEY_CHECKS = 1;'));
884};
885
886const filterMysqlTables = (schema: {
887 [key: string]:

Callers 1

resetFunction · 0.85

Calls 2

getTableNameFunction · 0.90
executeMethod · 0.45

Tested by

no test coverage detected