Multi-Database Support
First-class PostgreSQL, MySQL, and SQLite with dialect-aware storage.
Go Audit ships with three dialect implementations. Each generates schema DDL, places parameter placeholders, and chooses a JSON storage strategy appropriate for its database.
PostgreSQL
JSONBforold_values,new_values,request_headers,request_body,response_body,metadata- GIN indexes on
old_valuesandnew_valuesfor JSON key lookups TIMESTAMPTZwithDEFAULT NOW()forcreated_atBIGSERIALprimary key- Parameter placeholders:
$1,$2, …
MySQL
JSONtype for JSON columns- B-tree indexes declared inline in
CREATE TABLE TIMESTAMPwithDEFAULT CURRENT_TIMESTAMPforcreated_atBIGINT UNSIGNED AUTO_INCREMENTprimary key- Table engine:
InnoDB, charsetutf8mb4 - Parameter placeholders:
?
SQLite
TEXTfor JSON (stored as JSON-encoded strings)- B-tree indexes
DATETIMEwithDEFAULT (datetime('now'))forcreated_atINTEGER PRIMARY KEY AUTOINCREMENT- Parameter placeholders:
?
Great for local development, embedded deployments, and tests.
Setting the Dialect
The dialect is explicit — there is no auto-detection based on the
driver. Pass the constant directly in Config:
audit.New(sqlDB, audit.Config{
Dialect: audit.PostgreSQL, // or audit.MySQL / audit.SQLite
// ...
})Valid values:
audit.PostgreSQL
audit.MySQL
audit.SQLiteCustom Dialects
You can register a custom dialect to support Aurora, AlloyDB, ClickHouse, or any other database. See the Dialect reference for the interface and registration call.
Record Shape
The stored record shape is identical across dialects — same columns,
same JSON structure, same index intent. You can migrate an audit
database from SQLite to PostgreSQL by copying rows and re-parsing the
JSON text into JSONB.