release: v0.5.1 — 存储后端生产级硬化(CRC-32/全库加密/WAL分片/页面化存储/多标签页锁/e2e)+ 深度审查修复(假实现接线/死代码清理)
This commit is contained in:
+16
-2
@@ -135,14 +135,18 @@ export class SelectQueryBuilder {
|
||||
export class UpdateQueryBuilder {
|
||||
private _where: WhereCondition = {};
|
||||
private onWrite?: (table: string) => void;
|
||||
/** v0.5.1: CRUD hooks 触发回调 */
|
||||
private onHooks?: (hook: import('../constants').HookName, args: unknown[]) => Promise<void>;
|
||||
|
||||
constructor(
|
||||
private engine: IStorageEngine,
|
||||
private tableName: string,
|
||||
private _updates: Record<string, unknown>,
|
||||
onWrite?: (table: string) => void,
|
||||
onHooks?: (hook: import('../constants').HookName, args: unknown[]) => Promise<void>,
|
||||
) {
|
||||
this.onWrite = onWrite;
|
||||
this.onHooks = onHooks;
|
||||
}
|
||||
|
||||
where(condition: WhereCondition): this {
|
||||
@@ -151,8 +155,11 @@ export class UpdateQueryBuilder {
|
||||
}
|
||||
|
||||
async execute(): Promise<number> {
|
||||
const count = await this.engine.update(this.tableName, { table: this.tableName, where: this._where }, this._updates);
|
||||
const query = { table: this.tableName, where: this._where };
|
||||
await this.onHooks?.('beforeUpdate', [query, this._updates]);
|
||||
const count = await this.engine.update(this.tableName, query, this._updates);
|
||||
this.onWrite?.(this.tableName);
|
||||
await this.onHooks?.('afterUpdate', [query, this._updates, count]);
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -168,13 +175,17 @@ export class UpdateQueryBuilder {
|
||||
export class DeleteQueryBuilder {
|
||||
private _where: WhereCondition = {};
|
||||
private onWrite?: (table: string) => void;
|
||||
/** v0.5.1: CRUD hooks 触发回调 */
|
||||
private onHooks?: (hook: import('../constants').HookName, args: unknown[]) => Promise<void>;
|
||||
|
||||
constructor(
|
||||
private engine: IStorageEngine,
|
||||
private tableName: string,
|
||||
onWrite?: (table: string) => void,
|
||||
onHooks?: (hook: import('../constants').HookName, args: unknown[]) => Promise<void>,
|
||||
) {
|
||||
this.onWrite = onWrite;
|
||||
this.onHooks = onHooks;
|
||||
}
|
||||
|
||||
where(condition: WhereCondition): this {
|
||||
@@ -183,8 +194,11 @@ export class DeleteQueryBuilder {
|
||||
}
|
||||
|
||||
async execute(): Promise<number> {
|
||||
const count = await this.engine.delete(this.tableName, { table: this.tableName, where: this._where });
|
||||
const query = { table: this.tableName, where: this._where };
|
||||
await this.onHooks?.('beforeDelete', [query]);
|
||||
const count = await this.engine.delete(this.tableName, query);
|
||||
this.onWrite?.(this.tableName);
|
||||
await this.onHooks?.('afterDelete', [query, count]);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user