Skip to main content
zerotal

Documentation


Documentation / @zerotal/audit / DatabaseDriver

Class: DatabaseDriver

Defined in: audit/src/drivers/DatabaseDriver.ts:26

Stores audit logs in a relational database table (default: audit_logs).

Create the table with:

await Schema.create("audit_logs", (table) => { table.id(); table.string("event"); table.string("auditable_type"); table.string("auditable_id").nullable(); table.string("actor_type").nullable(); table.integer("actor_id").nullable(); table.text("old_values").nullable(); table.text("new_values").nullable(); table.text("tags").nullable(); table.string("ip_address").nullable(); table.string("user_agent").nullable(); table.string("url").nullable(); table.timestamp("created_at"); });

Implements

Constructors

Constructor

new DatabaseDriver(table?): DatabaseDriver

Defined in: audit/src/drivers/DatabaseDriver.ts:27

Parameters

table?

string = "audit_logs"

Returns

DatabaseDriver

Methods

record()

record(payload): Promise<void>

Defined in: audit/src/drivers/DatabaseDriver.ts:29

Persist a single audit entry.

Parameters

payload

AuditPayload

Returns

Promise<void>

Implementation of

AuditDriver.record


forModel()

forModel(type, id, limit?): Promise<AuditRecord[]>

Defined in: audit/src/drivers/DatabaseDriver.ts:47

Return the most recent limit entries for a given model. Return an empty array if the driver does not support reads.

Parameters

type

string

id

string | number

limit?

number = 50

Returns

Promise<AuditRecord[]>

Implementation of

AuditDriver.forModel