|
44 | 44 | AND (@eventid::text = '' OR event_id = @eventid::text) |
45 | 45 | AND (@publishedafter::timestamptz IS NULL OR published_at >= @publishedafter::timestamptz) |
46 | 46 | AND (@publishedbefore::timestamptz IS NULL OR published_at <= @publishedbefore::timestamptz); |
| 47 | + |
| 48 | +-- name: CreateChallenge :one |
| 49 | +INSERT INTO challenges ( |
| 50 | + id, |
| 51 | + project_id, |
| 52 | + event_id, |
| 53 | + name, |
| 54 | + description, |
| 55 | + image_url, |
| 56 | + url, |
| 57 | + button_text, |
| 58 | + published_at, |
| 59 | + end_time |
| 60 | +) |
| 61 | +VALUES ( |
| 62 | + @id::text, |
| 63 | + @projectid::text, |
| 64 | + @eventid::text, |
| 65 | + @name::text, |
| 66 | + @description::text, |
| 67 | + sqlc.narg('imageurl')::text, |
| 68 | + sqlc.narg('url')::text, |
| 69 | + @buttontext::text, |
| 70 | + @publishedat::timestamptz, |
| 71 | + @endtime::timestamptz |
| 72 | +) |
| 73 | +RETURNING id, project_id, event_id, name, description, image_url, url, button_text, published_at, end_time, created_at, updated_at; |
| 74 | + |
| 75 | +-- name: UpdateChallenge :one |
| 76 | +UPDATE challenges |
| 77 | +SET |
| 78 | + name = COALESCE(sqlc.narg('name')::text, name), |
| 79 | + description = COALESCE(sqlc.narg('description')::text, description), |
| 80 | + image_url = COALESCE(sqlc.narg('imageurl')::text, image_url), |
| 81 | + url = COALESCE(sqlc.narg('url')::text, url), |
| 82 | + button_text = COALESCE(sqlc.narg('buttontext')::text, button_text), |
| 83 | + event_id = COALESCE(sqlc.narg('eventid')::text, event_id), |
| 84 | + end_time = COALESCE(sqlc.narg('endtime')::timestamptz, end_time), |
| 85 | + updated_at = now() |
| 86 | +WHERE id = @id::text |
| 87 | +RETURNING id, project_id, event_id, name, description, image_url, url, button_text, published_at, end_time, created_at, updated_at; |
| 88 | + |
| 89 | +-- name: DeleteChallenge :exec |
| 90 | +DELETE FROM challenges |
| 91 | +WHERE id = @id::text; |
| 92 | + |
| 93 | +-- name: PublishChallenge :one |
| 94 | +UPDATE challenges |
| 95 | +SET |
| 96 | + published_at = @publishedat::timestamptz, |
| 97 | + updated_at = now() |
| 98 | +WHERE id = @id::text |
| 99 | +RETURNING id, project_id, event_id, name, description, image_url, url, button_text, published_at, end_time, created_at, updated_at; |
| 100 | + |
| 101 | +-- name: AssignChallengeToEvent :one |
| 102 | +UPDATE challenges |
| 103 | +SET |
| 104 | + event_id = @eventid::text, |
| 105 | + updated_at = now() |
| 106 | +WHERE id = @id::text |
| 107 | +RETURNING id, project_id, event_id, name, description, image_url, url, button_text, published_at, end_time, created_at, updated_at; |
| 108 | + |
| 109 | +-- name: BulkPublishChallenges :many |
| 110 | +UPDATE challenges |
| 111 | +SET |
| 112 | + published_at = @publishedat::timestamptz, |
| 113 | + updated_at = now() |
| 114 | +WHERE id = ANY(@ids::text[]) |
| 115 | +RETURNING id, project_id, event_id, name, description, image_url, url, button_text, published_at, end_time, created_at, updated_at; |
| 116 | + |
| 117 | +-- name: BulkCreateChallenges :many |
| 118 | +INSERT INTO challenges ( |
| 119 | + id, |
| 120 | + project_id, |
| 121 | + event_id, |
| 122 | + name, |
| 123 | + description, |
| 124 | + image_url, |
| 125 | + url, |
| 126 | + button_text, |
| 127 | + published_at, |
| 128 | + end_time |
| 129 | +) |
| 130 | +SELECT |
| 131 | + unnest(@ids::text[]), |
| 132 | + unnest(@projectids::text[]), |
| 133 | + unnest(@eventids::text[]), |
| 134 | + unnest(@names::text[]), |
| 135 | + unnest(@descriptions::text[]), |
| 136 | + unnest(@imageurls::text[]), |
| 137 | + unnest(@urls::text[]), |
| 138 | + unnest(@buttontexts::text[]), |
| 139 | + unnest(@publishedats::timestamptz[]), |
| 140 | + unnest(@endtimes::timestamptz[]) |
| 141 | +RETURNING id, project_id, event_id, name, description, image_url, url, button_text, published_at, end_time, created_at, updated_at; |
0 commit comments