import { sql } from "drizzle-orm";

//#region src/dolt/diff.ts
/**
* Get diff between two commits/branches
*/
const doltDiff = (db) => async (params) => {
	return (await db.execute(sql.raw(`SELECT * FROM DOLT_DIFF('${params.fromRevision}', '${params.toRevision}', '${params.tableName}')`))).rows;
};
/**
* Get diff summary between two commits/branches
*/
const doltDiffSummary = (db) => async (params) => {
	let query;
	if (params.tableName) query = sql.raw(`SELECT * FROM DOLT_DIFF_SUMMARY('${params.fromRevision}', '${params.toRevision}', '${params.tableName}')`);
	else query = sql.raw(`SELECT * FROM DOLT_DIFF_SUMMARY('${params.fromRevision}', '${params.toRevision}')`);
	return (await db.execute(query)).rows;
};

//#endregion
export { doltDiff, doltDiffSummary };