GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

44 lines
1.7 KiB

-- name: SelectLog :one
SELECT id, short_id, character_ids, date, channel_name, event_name, title, description, open FROM log WHERE id=$1 OR short_id=$1 LIMIT 1;
-- name: SelectLogs :many
SELECT id, short_id, character_ids, date, channel_name, event_name, title, description, open FROM log
WHERE (@filter_short_id::BOOL = false OR short_id = ANY(@short_ids::TEXT[]))
AND (@filter_character_id::BOOL = false OR character_ids @> (@character_ids::TEXT[]))
AND (@filter_channel_name::BOOL = false OR channel_name = ANY(@channel_names::TEXT[]))
AND (@filter_event_name::BOOL = false OR event_name = ANY(@event_names::TEXT[]))
AND (@filter_open::BOOL = false OR open = @open::BOOL)
AND (@filter_earlist_date::BOOL = false OR date >= @earliest_date::TIMESTAMP)
AND (@filter_lastest_date::BOOL = false OR date <= @latest_date::TIMESTAMP)
AND (@filter_search::BOOL = false OR "ts_vector" @@ to_tsquery(@search::TEXT))
ORDER BY date DESC
LIMIT NULLIF(@limit_size::INT, 0);
-- name: InsertLog :exec
INSERT INTO log (id, short_id, character_ids, date, channel_name, event_name, title, description, open)
VALUES (
@id, @short_id, @character_ids, @date, @channel_name, @event_name, @title, @description, @open
);
-- name: UpdateLog :exec
UPDATE log
SET title = @title,
event_name = @event_name,
description = @description,
open = @open,
character_ids = @character_ids
WHERE id = @id;
-- name: GenerateLogTSVector :exec
UPDATE log
SET "ts_vector" = (
SELECT TO_TSVECTOR(
immutable_array_to_string(array_agg(text), '\n\n')
)
FROM log_post
WHERE log_short_id = @short_id
)
WHERE short_id = @short_id;
-- name: DeleteLog :exec
DELETE FROM log WHERE id=$1;