Skip to content

Commit

Permalink
add tx logs
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed May 17, 2024
1 parent bdf02a6 commit 81c77d3
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 13 deletions.
24 changes: 16 additions & 8 deletions lib/DboBuilder/DboBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,23 @@ export class DboBuilder {
return jp;
}

getTX = (cb: TxCB) => {
return this.db.tx(t => {
const dbTX: DbTxTableHandlers & Pick<DBHandlerServer, "sql"> = {};
this.tablesOrViews?.map(tov => {
dbTX[tov.name] = new (tov.is_view ? ViewHandler : TableHandler)(this.db, tov, this, { t, dbTX }, this.shortestJoinPaths);
getTX = async (cb: TxCB) => {
try {
const transaction = await this.db.tx(t => {
const dbTX: DbTxTableHandlers & Pick<DBHandlerServer, "sql"> = {};
this.tablesOrViews?.map(tov => {
dbTX[tov.name] = new (tov.is_view ? ViewHandler : TableHandler)(this.db, tov, this, { t, dbTX }, this.shortestJoinPaths);
});
dbTX.sql = (q, args, opts, localP) => this.runSQL(q, args, opts, { tx: { dbTX, t }, ...(localP ?? {}) })

return cb(dbTX, t);
});
dbTX.sql = (q, args, opts, localP) => this.runSQL(q, args, opts, { tx: { dbTX, t }, ...(localP ?? {}) })

return transaction;

return cb(dbTX, t);
});
} catch (e) {
console.error("Error in getTX", e);
throw e;
}
}
}
13 changes: 12 additions & 1 deletion lib/DboBuilder/ViewHandler/ViewHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,18 @@ export class ViewHandler {
return;
}
const sid = this.dboBuilder.prostgles.authHandler?.getSIDNoError(localParams);
return this.dboBuilder.prostgles.opts.onLog?.({ type: "table", sid, socketId: localParams?.socket?.id, tableName: this.name, command, data, localParams, duration, error });
return this.dboBuilder.prostgles.opts.onLog?.({
type: "table",
command,
duration,
error,
txInfo: this.tx?.t.ctx,
sid,
socketId: localParams?.socket?.id,
tableName: this.name,
data,
localParams,
});
}

getRowHashSelect(allowedFields: FieldFilter, alias?: string, tableAlias?: string): string {
Expand Down
1 change: 1 addition & 0 deletions lib/Logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export namespace EventTypes {
type: "table";
tableName: string;
command: keyof TableHandler;
txInfo: AnyObject | undefined;
data: AnyObject;
localParams: LocalParams | undefined;
};
Expand Down
3 changes: 3 additions & 0 deletions lib/PubSubManager/getInitQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ BEGIN
$$ LANGUAGE plpgsql;
COMMENT ON FUNCTION ${DB_OBJ_NAMES.schema_watch_func} IS 'Prostgles internal function used to notify when schema has changed';
ELSE
DELETE FROM prostgles.app_triggers;
END IF;
END
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.2.66",
"version": "4.2.67",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion tests/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 81c77d3

Please sign in to comment.