128 lines
3.4 KiB
Go
128 lines
3.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: access_logs.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
"net/netip"
|
|
"time"
|
|
)
|
|
|
|
const countAccessLogs = `-- name: CountAccessLogs :one
|
|
SELECT COUNT(*)
|
|
FROM access_logs
|
|
`
|
|
|
|
func (q *Queries) CountAccessLogs(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countAccessLogs)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createAccessLog = `-- name: CreateAccessLog :exec
|
|
INSERT INTO access_logs(request_id, user_id, ip, user_agent, request_method, request_path, referer, status_code,
|
|
response_time_ms, started_at, message)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
|
`
|
|
|
|
type CreateAccessLogParams struct {
|
|
RequestID *string `json:"request_id"`
|
|
UserID *int32 `json:"user_id"`
|
|
Ip *netip.Addr `json:"ip"`
|
|
UserAgent *string `json:"user_agent"`
|
|
RequestMethod string `json:"request_method"`
|
|
RequestPath string `json:"request_path"`
|
|
Referer *string `json:"referer"`
|
|
StatusCode *int32 `json:"status_code"`
|
|
ResponseTimeMs *int32 `json:"response_time_ms"`
|
|
StartedAt time.Time `json:"started_at"`
|
|
Message *string `json:"message"`
|
|
}
|
|
|
|
func (q *Queries) CreateAccessLog(ctx context.Context, arg CreateAccessLogParams) error {
|
|
_, err := q.db.Exec(ctx, createAccessLog,
|
|
arg.RequestID,
|
|
arg.UserID,
|
|
arg.Ip,
|
|
arg.UserAgent,
|
|
arg.RequestMethod,
|
|
arg.RequestPath,
|
|
arg.Referer,
|
|
arg.StatusCode,
|
|
arg.ResponseTimeMs,
|
|
arg.StartedAt,
|
|
arg.Message,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const listAccessLogs = `-- name: ListAccessLogs :many
|
|
SELECT a.id, a.request_id, a.user_id, a.ip, a.user_agent, a.request_method, a.request_path, a.referer, a.message, a.status_code, a.response_time_ms, a.started_at, a.created_at, u.username
|
|
FROM access_logs a
|
|
LEFT JOIN sys_users u
|
|
ON u.id = a.user_id
|
|
ORDER BY a.started_at DESC, a.id
|
|
LIMIT $1 OFFSET $2
|
|
`
|
|
|
|
type ListAccessLogsParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type ListAccessLogsRow struct {
|
|
ID int64 `json:"id"`
|
|
RequestID *string `json:"request_id"`
|
|
UserID *int32 `json:"user_id"`
|
|
Ip *netip.Addr `json:"ip"`
|
|
UserAgent *string `json:"user_agent"`
|
|
RequestMethod string `json:"request_method"`
|
|
RequestPath string `json:"request_path"`
|
|
Referer *string `json:"referer"`
|
|
Message *string `json:"message"`
|
|
StatusCode *int32 `json:"status_code"`
|
|
ResponseTimeMs *int32 `json:"response_time_ms"`
|
|
StartedAt time.Time `json:"started_at"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
Username *string `json:"username"`
|
|
}
|
|
|
|
func (q *Queries) ListAccessLogs(ctx context.Context, arg ListAccessLogsParams) ([]ListAccessLogsRow, error) {
|
|
rows, err := q.db.Query(ctx, listAccessLogs, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListAccessLogsRow{}
|
|
for rows.Next() {
|
|
var i ListAccessLogsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.RequestID,
|
|
&i.UserID,
|
|
&i.Ip,
|
|
&i.UserAgent,
|
|
&i.RequestMethod,
|
|
&i.RequestPath,
|
|
&i.Referer,
|
|
&i.Message,
|
|
&i.StatusCode,
|
|
&i.ResponseTimeMs,
|
|
&i.StartedAt,
|
|
&i.CreatedAt,
|
|
&i.Username,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|