| 1 | // Code generated by sqlc. DO NOT EDIT. |
| 2 | // versions: |
| 3 | // sqlc v1.31.1 |
| 4 | // source: auth_audit_log.sql |
| 5 | |
| 6 | package usersdb |
| 7 | |
| 8 | import ( |
| 9 | "context" |
| 10 | |
| 11 | "github.com/jackc/pgx/v5/pgtype" |
| 12 | ) |
| 13 | |
| 14 | const insertAuditLog = `-- name: InsertAuditLog :exec |
| 15 | |
| 16 | INSERT INTO auth_audit_log (actor_id, action, target_type, target_id, meta) |
| 17 | VALUES ($1, $2, $3, $4, $5) |
| 18 | ` |
| 19 | |
| 20 | type InsertAuditLogParams struct { |
| 21 | ActorID pgtype.Int8 |
| 22 | Action string |
| 23 | TargetType string |
| 24 | TargetID pgtype.Int8 |
| 25 | Meta []byte |
| 26 | } |
| 27 | |
| 28 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 29 | func (q *Queries) InsertAuditLog(ctx context.Context, db DBTX, arg InsertAuditLogParams) error { |
| 30 | _, err := db.Exec(ctx, insertAuditLog, |
| 31 | arg.ActorID, |
| 32 | arg.Action, |
| 33 | arg.TargetType, |
| 34 | arg.TargetID, |
| 35 | arg.Meta, |
| 36 | ) |
| 37 | return err |
| 38 | } |
| 39 | |
| 40 | const listAuditLogForTarget = `-- name: ListAuditLogForTarget :many |
| 41 | SELECT id, actor_id, action, target_type, target_id, meta, created_at |
| 42 | FROM auth_audit_log |
| 43 | WHERE target_type = $1 AND target_id = $2 |
| 44 | ORDER BY created_at DESC |
| 45 | LIMIT $3 |
| 46 | ` |
| 47 | |
| 48 | type ListAuditLogForTargetParams struct { |
| 49 | TargetType string |
| 50 | TargetID pgtype.Int8 |
| 51 | Limit int32 |
| 52 | } |
| 53 | |
| 54 | func (q *Queries) ListAuditLogForTarget(ctx context.Context, db DBTX, arg ListAuditLogForTargetParams) ([]AuthAuditLog, error) { |
| 55 | rows, err := db.Query(ctx, listAuditLogForTarget, arg.TargetType, arg.TargetID, arg.Limit) |
| 56 | if err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | defer rows.Close() |
| 60 | items := []AuthAuditLog{} |
| 61 | for rows.Next() { |
| 62 | var i AuthAuditLog |
| 63 | if err := rows.Scan( |
| 64 | &i.ID, |
| 65 | &i.ActorID, |
| 66 | &i.Action, |
| 67 | &i.TargetType, |
| 68 | &i.TargetID, |
| 69 | &i.Meta, |
| 70 | &i.CreatedAt, |
| 71 | ); err != nil { |
| 72 | return nil, err |
| 73 | } |
| 74 | items = append(items, i) |
| 75 | } |
| 76 | if err := rows.Err(); err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | return items, nil |
| 80 | } |
| 81 |