mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-28 08:21:15 +00:00
* refactor(sqlite): remove unused async Kysely driver Co-authored-by: Sarah Fortune <sarah.fortune@gmail.com> * refactor(media): share promise memoization * chore(sqlite): prune stale Kysely guardrails * chore(media): lower runner LOC baseline * style(shared): format promise memo tests * chore(deadcode): refresh main export baseline --------- Co-authored-by: Sarah Fortune <sarah.fortune@gmail.com>
74 lines
2.1 KiB
TypeScript
74 lines
2.1 KiB
TypeScript
// Build-only node:sqlite dialect for the synchronous execution helpers.
|
|
import type {
|
|
DatabaseConnection,
|
|
DatabaseIntrospector,
|
|
Dialect,
|
|
DialectAdapter,
|
|
Driver,
|
|
Kysely,
|
|
QueryCompiler,
|
|
TransactionSettings,
|
|
} from "kysely";
|
|
import { SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler } from "kysely";
|
|
|
|
/** Kysely dialect that compiles node:sqlite queries without executing them. */
|
|
export class NodeSqliteKyselyDialect implements Dialect {
|
|
createDriver(): Driver {
|
|
return new CompileOnlySqliteDriver();
|
|
}
|
|
|
|
createQueryCompiler(): QueryCompiler {
|
|
return new SqliteQueryCompiler();
|
|
}
|
|
|
|
createAdapter(): DialectAdapter {
|
|
return new CompileOnlySqliteAdapter();
|
|
}
|
|
|
|
createIntrospector(db: Kysely<unknown>): DatabaseIntrospector {
|
|
return new SqliteIntrospector(db);
|
|
}
|
|
}
|
|
|
|
class CompileOnlySqliteDriver implements Driver {
|
|
async init(): Promise<void> {}
|
|
|
|
async acquireConnection(): Promise<DatabaseConnection> {
|
|
throw createCompileOnlyExecutionError();
|
|
}
|
|
|
|
async beginTransaction(
|
|
_connection: DatabaseConnection,
|
|
_settings: TransactionSettings,
|
|
): Promise<void> {
|
|
throw createCompileOnlyExecutionError();
|
|
}
|
|
|
|
async commitTransaction(_connection: DatabaseConnection): Promise<void> {
|
|
throw createCompileOnlyExecutionError();
|
|
}
|
|
|
|
async rollbackTransaction(_connection: DatabaseConnection): Promise<void> {
|
|
throw createCompileOnlyExecutionError();
|
|
}
|
|
|
|
async releaseConnection(_connection: DatabaseConnection): Promise<void> {}
|
|
|
|
async destroy(): Promise<void> {}
|
|
}
|
|
|
|
function createCompileOnlyExecutionError(): Error {
|
|
return new Error(
|
|
"getNodeSqliteKysely() returns a compile-only Kysely facade; use executeSqliteQuerySync() to execute node:sqlite queries.",
|
|
);
|
|
}
|
|
|
|
class CompileOnlySqliteAdapter extends SqliteAdapter {
|
|
override get supportsMultipleConnections(): boolean {
|
|
// Kysely's SQLite adapter installs a single-connection mutex. This facade
|
|
// never opens a real connection, so direct execution should reject from
|
|
// acquisition without leaving controlled transaction calls wedged.
|
|
return true;
|
|
}
|
|
}
|