// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: audit.sql package postgresdb import ( "context" "time" ) const auditForRecords = `-- name: AuditForRecords :many SELECT id, at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id FROM sys_audit WHERE table_name = $1::text AND record_key = ANY($2::text[]) ORDER BY id DESC LIMIT $3::bigint ` type AuditForRecordsParams struct { TableName string RecordKeys []string EntryLimit int64 } type AuditForRecordsRow struct { ID int64 At time.Time TableName string RecordKey string Field string OldValue []byte NewValue []byte RecordVersion int64 Actor string Source string RequestID string } func (q *Queries) AuditForRecords(ctx context.Context, arg AuditForRecordsParams) ([]AuditForRecordsRow, error) { rows, err := q.db.Query(ctx, auditForRecords, arg.TableName, arg.RecordKeys, arg.EntryLimit) if err != nil { return nil, err } defer rows.Close() var items []AuditForRecordsRow for rows.Next() { var i AuditForRecordsRow if err := rows.Scan( &i.ID, &i.At, &i.TableName, &i.RecordKey, &i.Field, &i.OldValue, &i.NewValue, &i.RecordVersion, &i.Actor, &i.Source, &i.RequestID, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const insertAudit = `-- name: InsertAudit :exec INSERT INTO sys_audit (at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id, org_id) VALUES (now(), $1::text, $2::text, $3::text, $4::jsonb, $5::jsonb, $6::bigint, $7::text, $8::text, $9::text, $10::text) ` type InsertAuditParams struct { TableName string RecordKey string Field string OldValue []byte NewValue []byte RecordVersion int64 Actor string Source string RequestID string OrgID string } // The generic write for tables that are not control-plane resources. Callers // pass the table's own name as table_name; old_value is nil for a create and // new_value nil for a delete. func (q *Queries) InsertAudit(ctx context.Context, arg InsertAuditParams) error { _, err := q.db.Exec(ctx, insertAudit, arg.TableName, arg.RecordKey, arg.Field, arg.OldValue, arg.NewValue, arg.RecordVersion, arg.Actor, arg.Source, arg.RequestID, arg.OrgID, ) return err } const insertResourceAudit = `-- name: InsertResourceAudit :exec INSERT INTO sys_audit (at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id, org_id) SELECT $1::timestamptz, 'resources', $2::text, d.field, d.old_value, d.new_value, $3::bigint, $4::text, $5::text, $6::text, $7::text FROM audit_json_diff( (SELECT convert_from(h.value, 'UTF8')::jsonb FROM resource_history h WHERE h.org_id = $7::text AND h.kind = $8::text AND h.version = $9::bigint), convert_from($10::bytea, 'UTF8')::jsonb ) d ORDER BY d.field ` type InsertResourceAuditParams struct { At time.Time RecordKey string Version int64 Actor string Source string RequestID string OrgID string Kind string PreviousVersion int64 Value []byte } func (q *Queries) InsertResourceAudit(ctx context.Context, arg InsertResourceAuditParams) error { _, err := q.db.Exec(ctx, insertResourceAudit, arg.At, arg.RecordKey, arg.Version, arg.Actor, arg.Source, arg.RequestID, arg.OrgID, arg.Kind, arg.PreviousVersion, arg.Value, ) return err }