Create internal db debugger

This commit is contained in:
Jamie Kyle
2025-08-20 13:00:14 -07:00
committed by GitHub
parent 31544d68a2
commit ae7c2c09a4
9 changed files with 130 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { Database } from '@signalapp/sqlcipher';
import type { Database, RowType } from '@signalapp/sqlcipher';
import type { ReadonlyDeep } from 'type-fest';
import { strictAssert } from '../util/assert';
@@ -894,6 +894,10 @@ type ReadableInterface = {
getMessageSampleForSchemaVersion: (
version: number
) => Array<MessageAttributesType>;
__dangerouslyRunAbitraryReadOnlySqlQuery: (
readOnlySqlQuery: string
) => ReadonlyArray<RowType<object>>;
};
type WritableInterface = {

View File

@@ -4,6 +4,7 @@
/* eslint-disable camelcase */
// TODO(indutny): format queries
import type { RowType } from '@signalapp/sqlcipher';
import SQL, { setLogger as setSqliteLogger } from '@signalapp/sqlcipher';
import { randomBytes } from 'crypto';
import { mkdirSync, rmSync } from 'node:fs';
@@ -477,6 +478,8 @@ export const DataReader: ServerReadableInterface = {
finishPageMessages,
getKnownDownloads,
getKnownConversationAttachments,
__dangerouslyRunAbitraryReadOnlySqlQuery,
};
export const DataWriter: ServerWritableInterface = {
@@ -8717,3 +8720,17 @@ function ensureMessageInsertTriggersAreEnabled(db: WritableDB): void {
}
})();
}
function __dangerouslyRunAbitraryReadOnlySqlQuery(
db: ReadableDB,
readOnlySqlQuery: string
): ReadonlyArray<RowType<object>> {
let results: ReadonlyArray<RowType<object>>;
try {
db.pragma('query_only = on');
results = db.prepare(readOnlySqlQuery).all();
} finally {
db.pragma('query_only = off');
}
return results;
}