Files
coder/coderd/database/queries/organizations.sql
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
1.4 KiB
SQL
Raw Normal View History

2024-02-16 08:28:36 -06:00
-- name: GetDefaultOrganization :one
SELECT
*
FROM
organizations
WHERE
is_default = true
LIMIT
1;
2022-04-23 17:58:57 -05:00
-- name: GetOrganizations :many
SELECT
*
FROM
organizations
WHERE
true
-- Filter by ids
AND CASE
WHEN array_length(@ids :: uuid[], 1) > 0 THEN
id = ANY(@ids)
ELSE true
END
AND CASE
WHEN @name::text != '' THEN
LOWER("name") = LOWER(@name)
ELSE true
END
;
2022-04-23 17:58:57 -05:00
-- name: GetOrganizationByID :one
SELECT
*
FROM
organizations
WHERE
id = $1;
-- name: GetOrganizationByName :one
SELECT
*
FROM
organizations
WHERE
LOWER("name") = LOWER(@name)
LIMIT
1;
-- name: GetOrganizationsByUserID :many
SELECT
*
FROM
organizations
WHERE
id = ANY(
SELECT
organization_id
FROM
organization_members
WHERE
user_id = $1
);
-- name: InsertOrganization :one
INSERT INTO
2024-06-12 12:28:13 -06:00
organizations (id, "name", display_name, description, icon, created_at, updated_at, is_default)
VALUES
-- If no organizations exist, and this is the first, make it the default.
2024-06-12 12:28:13 -06:00
(@id, @name, @display_name, @description, @icon, @created_at, @updated_at, (SELECT TRUE FROM organizations LIMIT 1) IS NULL) RETURNING *;
-- name: UpdateOrganization :one
UPDATE
organizations
SET
updated_at = @updated_at,
name = @name,
display_name = @display_name,
2024-06-12 12:28:13 -06:00
description = @description,
icon = @icon
WHERE
id = @id
RETURNING *;
-- name: DeleteOrganization :exec
DELETE FROM
organizations
WHERE
id = $1 AND
is_default = false;