Add logging for deleted prekeys and other records

Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
Jamie Kyle 2023-10-19 14:52:35 -07:00 committed by GitHub
parent 0c896ca1f2
commit ba0fa4904b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 213 additions and 51 deletions

View file

@ -323,37 +323,39 @@ export function getById<Key extends string | number, Result = unknown>(
export function removeById<Key extends string | number>(
db: Database,
table: TableType,
tableName: TableType,
id: Key | Array<Key>
): void {
): number {
const table = sqlConstant(tableName);
if (!Array.isArray(id)) {
db.prepare<Query>(
`
const [query, params] = sql`
DELETE FROM ${table}
WHERE id = $id;
`
).run({ id });
return;
WHERE id = ${id};
`;
return db.prepare(query).run(params).changes;
}
if (!id.length) {
throw new Error('removeById: No ids to delete!');
}
let totalChanges = 0;
const removeByIdsSync = (ids: ReadonlyArray<string | number>): void => {
db.prepare<ArrayQuery>(
`
const [query, params] = sql`
DELETE FROM ${table}
WHERE id IN ( ${id.map(() => '?').join(', ')} );
`
).run(ids);
WHERE id IN (${sqlJoin(ids, ', ')});
`;
totalChanges += db.prepare(query).run(params).changes;
};
batchMultiVarQuery(db, id, removeByIdsSync);
return totalChanges;
}
export function removeAllFromTable(db: Database, table: TableType): void {
db.prepare<EmptyQuery>(`DELETE FROM ${table};`).run();
export function removeAllFromTable(db: Database, table: TableType): number {
return db.prepare<EmptyQuery>(`DELETE FROM ${table};`).run().changes;
}
export function getAllFromTable<T>(db: Database, table: TableType): Array<T> {