immich/server/src/queries/activity.repository.sql

88 lines
1.7 KiB
MySQL
Raw Normal View History

-- NOTE: This file is auto generated by ./sql-generator
-- ActivityRepository.search
select
"activity".*,
to_json("user") as "user"
from
"activity"
2025-07-14 10:13:06 -04:00
inner join "user" as "user2" on "user2"."id" = "activity"."userId"
and "user2"."deletedAt" is null
inner join lateral (
select
2025-07-14 10:13:06 -04:00
"user2"."id",
"user2"."name",
"user2"."email",
"user2"."avatarColor",
"user2"."profileImagePath",
"user2"."profileChangedAt"
from
(
select
1
) as "dummy"
) as "user" on true
2025-07-14 10:13:06 -04:00
left join "asset" on "asset"."id" = "activity"."assetId"
where
"activity"."albumId" = $1
2025-07-14 10:13:06 -04:00
and "asset"."deletedAt" is null
order by
"activity"."createdAt" asc
-- ActivityRepository.create
insert into
"activity" ("albumId", "userId")
values
($1, $2)
returning
*,
(
select
to_json(obj)
from
(
select
2025-01-15 23:31:26 -05:00
"id",
"name",
"email",
2025-04-28 09:54:51 -04:00
"avatarColor",
2025-01-15 23:31:26 -05:00
"profileImagePath",
"profileChangedAt"
from
2025-07-14 10:13:06 -04:00
"user"
where
2025-07-14 10:13:06 -04:00
"user"."id" = "activity"."userId"
) as obj
) as "user"
-- ActivityRepository.delete
delete from "activity"
where
"id" = $1::uuid
-- ActivityRepository.getStatistics
select
count(*) filter (
where
"activity"."isLiked" = $1
) as "comments",
count(*) filter (
where
"activity"."isLiked" = $2
) as "likes"
from
"activity"
2025-07-14 10:13:06 -04:00
inner join "user" on "user"."id" = "activity"."userId"
and "user"."deletedAt" is null
left join "asset" on "asset"."id" = "activity"."assetId"
where
"activity"."assetId" = $3
and "activity"."albumId" = $4
and (
(
2025-07-14 10:13:06 -04:00
"asset"."deletedAt" is null
and "asset"."visibility" != 'locked'
)
2025-07-14 10:13:06 -04:00
or "asset"."id" is null
)