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;
|
|
|
|
|
|
2022-04-01 15:45:23 -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
|
2024-02-22 08:14:48 -06:00
|
|
|
id = ANY(
|
2022-04-01 15:45:23 -05:00
|
|
|
SELECT
|
|
|
|
|
organization_id
|
|
|
|
|
FROM
|
|
|
|
|
organization_members
|
|
|
|
|
WHERE
|
|
|
|
|
user_id = $1
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
-- name: InsertOrganization :one
|
|
|
|
|
INSERT INTO
|
2024-02-15 11:01:16 -06:00
|
|
|
organizations (id, "name", description, created_at, updated_at, is_default)
|
2022-04-01 15:45:23 -05:00
|
|
|
VALUES
|
2024-02-15 11:01:16 -06:00
|
|
|
-- If no organizations exist, and this is the first, make it the default.
|
|
|
|
|
($1, $2, $3, $4, $5, (SELECT TRUE FROM organizations LIMIT 1) IS NULL) RETURNING *;
|