Files
projectx/internal/db/query/sys_user_login_log.sql
2025-04-14 15:28:51 +08:00

41 lines
1.3 KiB
SQL

-- name: CreateSysUserLoginLog :exec
INSERT INTO sys_user_login_log (created_at,
email,
username,
user_uuid,
is_success,
message,
referer_url,
url,
os,
ip,
browser)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);
-- name: CountSysUserLoginLogCondition :one
SELECT COUNT(*) FROM sys_user_login_log
WHERE created_at BETWEEN @start_at AND @end_at
AND (@email::text = '' OR email ILIKE '%' || @email || '%')
AND (@username::text = '' OR username ILIKE '%' || @username || '%');
-- name: ListSysUserLoginLogCondition :many
SELECT
id,
created_at,
email,
COALESCE((SELECT username FROM sys_user WHERE email = sys_user_login_log.email LIMIT 1), '') AS username,
user_uuid,
is_success,
message,
referer_url,
url,
os,
ip,
browser
FROM sys_user_login_log
WHERE sys_user_login_log.created_at BETWEEN @start_at AND @end_at
AND (@email::text = '' OR email ILIKE '%' || @email || '%')
AND (@username::text = '' OR username ILIKE '%' || @username || '%')
ORDER BY created_at DESC
OFFSET @skip
LIMIT @size;