36 lines
974 B
SQL
36 lines
974 B
SQL
-- name: InsertEventHistory :one
|
|
INSERT INTO event_history (event_id, status)
|
|
VALUES ($1, $2)
|
|
RETURNING *;
|
|
-- name: GetAllEventHistory :many
|
|
SELECT *
|
|
FROM event_history
|
|
WHERE (
|
|
event_id = sqlc.narg('event_id')
|
|
OR sqlc.narg('event_id') IS NULL
|
|
)
|
|
AND (
|
|
created_at > sqlc.narg('created_before')
|
|
OR sqlc.narg('created_before') IS NULL
|
|
)
|
|
AND (
|
|
created_at < sqlc.narg('created_after')
|
|
OR sqlc.narg('created_after') IS NULL
|
|
);
|
|
-- name: GetInitialEventPerDay :many
|
|
SELECT DISTINCT ON (DATE_TRUNC('day', created_at)) *
|
|
FROM event_history
|
|
WHERE (
|
|
event_id = sqlc.narg('event_id')
|
|
OR sqlc.narg('event_id') IS NULL
|
|
)
|
|
AND (
|
|
created_at > sqlc.narg('created_before')
|
|
OR sqlc.narg('created_before') IS NULL
|
|
)
|
|
AND (
|
|
created_at < sqlc.narg('created_after')
|
|
OR sqlc.narg('created_after') IS NULL
|
|
)
|
|
ORDER BY DATE_TRUNC('day', created_at),
|
|
created_at ASC; |