Skip to content

High performance self-hosted photo and video management solution.

2.3 KB
Raw Blame
-- NOTE: This file is auto generated by ./sql-generator

-- PersonUserRepository.searchPeopleUsers
select
  "person_user"."personGroupId" as "personId",
  "person_user"."sharedById",
  "person_user"."sharedWithId",
  "person_user"."role",
  (
    select
      to_json(obj)
    from
      (
        select
          "user"."id",
          "user"."name",
          "user"."email",
          "user"."avatarColor",
          "user"."profileImagePath",
          "user"."profileChangedAt"
        from
          "user"
        where
          "user"."id" = "person_user"."sharedById"
      ) as obj
  ) as "sharedBy",
  (
    select
      to_json(obj)
    from
      (
        select
          "user"."id",
          "user"."name",
          "user"."email",
          "user"."avatarColor",
          "user"."profileImagePath",
          "user"."profileChangedAt"
        from
          "user"
        where
          "user"."id" = "person_user"."sharedWithId"
      ) as obj
  ) as "sharedWith"
from
  "person_user"
where
  (
    "person_user"."sharedById" = $1
    or "person_user"."sharedWithId" = $2
  )

-- PersonUserRepository.createAll
insert into
  "person_user" (
    "personGroupId",
    "sharedById",
    "sharedWithId",
    "role"
  )
values
  ($1, $2, $3, $4)
on conflict ("personGroupId", "sharedById", "sharedWithId") do update
set
  "role" = "excluded"."role"
returning
  *

-- PersonUserRepository.createAllForOwner
insert into
  "person_user" (
    "personGroupId",
    "sharedById",
    "sharedWithId",
    "role"
  )
select
  "person"."personGroupId" as "personGroupId",
  "person"."ownerId" as "sharedById",
  "shared"."sharedWithId" as "sharedWithId",
  $1::person_user_role_enum as "role"
from
  "person"
  cross join (
    select
      unnest($2::uuid[]) as "sharedWithId"
  ) as "shared"
where
  "person"."ownerId" = $3
on conflict ("personGroupId", "sharedById", "sharedWithId") do update
set
  "role" = "excluded"."role"
returning
  *

-- PersonUserRepository.deleteAll
delete from "person_user"
where
  exists (
    select
      *
    from
      (
        select
          unnest($1::uuid[]) as "personGroupId",
          unnest($2::uuid[]) as "sharedWithId"
      ) as "people"
    where
      "people"."personGroupId" = "person_user"."personGroupId"
      and "people"."sharedWithId" = "person_user"."sharedWithId"
  )
  and "person_user"."sharedById" = $3