fix: event-loop freezes, plugin-install boot crash, tmux attach/scrollbar, Codex transcripts
- GET /api/workflows: one LEAD() window pass in a read worker (read-pool.js, workflow-stats.js); idx_events_session restored, idx_events_tool added - compat-sqlite gains function/pluck/readonly so a plugin install without a better-sqlite3 build boots again; antigravity-usage uses db.js's Database - install-hooks adds no checkout hooks while the agenthub plugin is enabled (events were doubled) - terminal attach runs the live tmux server's own binary; the pane scrollbar gets a visible 2-column style, and claude panes start with CLAUDE_CODE_DISABLE_ALTERNATE_SCREEN=1 so tmux keeps history to scroll - Codex sessions' conversation in GET /api/sessions/:id/transcript - Codex/Antigravity sessions claimed by their workspace without hooks - UI-audit follow-ups, docs and OpenAPI
This commit is contained in:
+28
-4
@@ -7,15 +7,20 @@
|
||||
* On older Node versions, require() will throw and the caller should
|
||||
* handle the error (e.g. show an informative message).
|
||||
*
|
||||
* @file This module exports a Database class that wraps node:sqlite's DatabaseSync to provide a better-sqlite3-like API.
|
||||
* @file This module exports a Database class that wraps node:sqlite's DatabaseSync to provide a better-sqlite3-like API: `pragma`, `transaction`, `function`, `stmt.pluck()` and the `readonly`/`fileMustExist` options. A plugin install has no better-sqlite3 build, so there this IS the driver.
|
||||
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const { DatabaseSync } = require("node:sqlite");
|
||||
|
||||
class Database {
|
||||
constructor(filePath) {
|
||||
this._db = new DatabaseSync(filePath);
|
||||
/** better-sqlite3's `readonly` and `fileMustExist` options, mapped. */
|
||||
constructor(filePath, { readonly = false, fileMustExist = false } = {}) {
|
||||
if (fileMustExist && !fs.existsSync(filePath)) {
|
||||
throw new Error(`unable to open database file: ${filePath} does not exist`);
|
||||
}
|
||||
this._db = new DatabaseSync(filePath, { readOnly: readonly });
|
||||
}
|
||||
|
||||
exec(sql) {
|
||||
@@ -36,7 +41,26 @@ class Database {
|
||||
}
|
||||
|
||||
prepare(sql) {
|
||||
return this._db.prepare(sql);
|
||||
const stmt = this._db.prepare(sql);
|
||||
// better-sqlite3's pluck(): get/all/iterate yield the first column only.
|
||||
stmt.pluck = () => {
|
||||
const first = (row) => (row === undefined ? undefined : Object.values(row)[0]);
|
||||
const { get, all, iterate } = stmt;
|
||||
stmt.get = (...a) => first(get.apply(stmt, a));
|
||||
stmt.all = (...a) => all.apply(stmt, a).map(first);
|
||||
stmt.iterate = function* (...a) {
|
||||
for (const row of iterate.apply(stmt, a)) yield first(row);
|
||||
};
|
||||
return stmt;
|
||||
};
|
||||
return stmt;
|
||||
}
|
||||
|
||||
/** better-sqlite3's db.function(name, [options], fn): a SQL function. */
|
||||
function(name, options, fn) {
|
||||
if (typeof options === "function") [fn, options] = [options, {}];
|
||||
this._db.function(name, options, fn);
|
||||
return this;
|
||||
}
|
||||
|
||||
transaction(fn) {
|
||||
|
||||
Reference in New Issue
Block a user