41 lines
923 B
SQL
41 lines
923 B
SQL
-- name: InsertChatProject :one
|
|||
|
|
INSERT INTO chat_projects (id, organization_id, owner_id, name, description, icon)
|
||
|
|
VALUES (
|
||
|
|
COALESCE(sqlc.narg('id')::uuid, gen_random_uuid()),
|
||
|
|
@organization_id::uuid,
|
||
|
|
@owner_id::uuid,
|
||
|
|
@name::text,
|
||
|
|
@description::text,
|
||
|
|
@icon::text
|
||
|
|
)
|
||
|
|
RETURNING *;
|
||
|
|
|
||
|
|
-- name: GetChatProjectByID :one
|
||
|
|
SELECT *
|
||
|
|
FROM chat_projects
|
||
|
|
WHERE id = @id::uuid;
|
||
|
|
|
||
|
|
-- name: GetChatProjectsByOwnerID :many
|
||
|
|
SELECT *
|
||
|
|
FROM chat_projects
|
||
|
|
WHERE owner_id = @owner_id::uuid
|
||
|
|
ORDER BY lower(name), id;
|
||
|
|
|
||
|
|
-- name: UpdateChatProjectByID :one
|
||
|
|
UPDATE chat_projects
|
||
|
|
SET
|
||
|
|
name = @name::text,
|
||
|
|
description = @description::text,
|
||
|
|
icon = @icon::text,
|
||
|
|
updated_at = now()
|
||
|
|
WHERE id = @id::uuid
|
||
|
|
RETURNING *;
|
||
|
|
|
||
|
|
-- name: DeleteChatProjectByID :exec
|
||
|
|
DELETE FROM chat_projects
|
||
|
|
WHERE id = @id::uuid;
|
||
|
|
|
||
|
|
-- name: CountChatProjectsByOwnerID :one
|
||
|
|
SELECT COUNT(*)::bigint
|
||
|
|
FROM chat_projects
|
||
|
|
WHERE owner_id = @owner_id::uuid;
|