2023-11-30 10:10:30 -05:00
|
|
|
-- NOTE: This file is auto generated by ./sql-generator
|
|
|
|
|
|
|
|
|
|
-- AlbumRepository.getById
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
"albums".*,
|
2023-11-30 10:10:30 -05:00
|
|
|
(
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
to_json(obj)
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
"id",
|
2025-04-14 20:34:06 +02:00
|
|
|
"name",
|
2025-01-21 11:24:48 -06:00
|
|
|
"email",
|
|
|
|
|
"profileImagePath",
|
|
|
|
|
"profileChangedAt"
|
|
|
|
|
from
|
|
|
|
|
"users"
|
|
|
|
|
where
|
|
|
|
|
"users"."id" = "albums"."ownerId"
|
|
|
|
|
) as obj
|
|
|
|
|
) as "owner",
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
coalesce(json_agg(agg), '[]')
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
2025-04-14 20:34:06 +02:00
|
|
|
"album_users"."role",
|
2025-01-21 11:24:48 -06:00
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
to_json(obj)
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
"id",
|
2025-04-14 20:34:06 +02:00
|
|
|
"name",
|
2025-01-21 11:24:48 -06:00
|
|
|
"email",
|
|
|
|
|
"profileImagePath",
|
|
|
|
|
"profileChangedAt"
|
|
|
|
|
from
|
|
|
|
|
"users"
|
|
|
|
|
where
|
|
|
|
|
"users"."id" = "album_users"."usersId"
|
|
|
|
|
) as obj
|
|
|
|
|
) as "user"
|
|
|
|
|
from
|
|
|
|
|
"albums_shared_users_users" as "album_users"
|
|
|
|
|
where
|
|
|
|
|
"album_users"."albumsId" = "albums"."id"
|
|
|
|
|
) as agg
|
|
|
|
|
) as "albumUsers",
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
coalesce(json_agg(agg), '[]')
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
*
|
|
|
|
|
from
|
|
|
|
|
"shared_links"
|
|
|
|
|
where
|
|
|
|
|
"shared_links"."albumId" = "albums"."id"
|
|
|
|
|
) as agg
|
2025-01-22 15:17:42 -05:00
|
|
|
) as "sharedLinks",
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
json_agg("asset") as "assets"
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
"assets".*,
|
2025-01-25 23:37:19 -05:00
|
|
|
"exif" as "exifInfo"
|
2025-01-22 15:17:42 -05:00
|
|
|
from
|
|
|
|
|
"assets"
|
2025-03-26 21:24:22 -05:00
|
|
|
left join "exif" on "assets"."id" = "exif"."assetId"
|
2025-01-22 15:17:42 -05:00
|
|
|
inner join "albums_assets_assets" on "albums_assets_assets"."assetsId" = "assets"."id"
|
|
|
|
|
where
|
|
|
|
|
"albums_assets_assets"."albumsId" = "albums"."id"
|
|
|
|
|
and "assets"."deletedAt" is null
|
|
|
|
|
order by
|
|
|
|
|
"assets"."fileCreatedAt" desc
|
|
|
|
|
) as "asset"
|
|
|
|
|
) as "assets"
|
2025-01-21 11:24:48 -06:00
|
|
|
from
|
|
|
|
|
"albums"
|
|
|
|
|
where
|
2025-01-24 11:54:53 -06:00
|
|
|
"albums"."id" = $1
|
2025-01-21 11:24:48 -06:00
|
|
|
and "albums"."deletedAt" is null
|
2023-11-30 10:10:30 -05:00
|
|
|
|
|
|
|
|
-- AlbumRepository.getByAssetId
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
"albums".*,
|
2023-11-30 10:10:30 -05:00
|
|
|
(
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
to_json(obj)
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
"id",
|
2025-04-14 20:34:06 +02:00
|
|
|
"name",
|
2025-01-21 11:24:48 -06:00
|
|
|
"email",
|
|
|
|
|
"profileImagePath",
|
|
|
|
|
"profileChangedAt"
|
|
|
|
|
from
|
|
|
|
|
"users"
|
|
|
|
|
where
|
|
|
|
|
"users"."id" = "albums"."ownerId"
|
|
|
|
|
) as obj
|
|
|
|
|
) as "owner",
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
coalesce(json_agg(agg), '[]')
|
|
|
|
|
from
|
2023-11-30 10:10:30 -05:00
|
|
|
(
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
2025-04-14 20:34:06 +02:00
|
|
|
"album_users"."role",
|
2024-02-06 22:06:02 +00:00
|
|
|
(
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
to_json(obj)
|
|
|
|
|
from
|
2024-04-25 06:19:49 +02:00
|
|
|
(
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
"id",
|
2025-04-14 20:34:06 +02:00
|
|
|
"name",
|
2025-01-21 11:24:48 -06:00
|
|
|
"email",
|
|
|
|
|
"profileImagePath",
|
|
|
|
|
"profileChangedAt"
|
|
|
|
|
from
|
|
|
|
|
"users"
|
|
|
|
|
where
|
|
|
|
|
"users"."id" = "album_users"."usersId"
|
|
|
|
|
) as obj
|
|
|
|
|
) as "user"
|
|
|
|
|
from
|
|
|
|
|
"albums_shared_users_users" as "album_users"
|
|
|
|
|
where
|
|
|
|
|
"album_users"."albumsId" = "albums"."id"
|
|
|
|
|
) as agg
|
|
|
|
|
) as "albumUsers"
|
|
|
|
|
from
|
|
|
|
|
"albums"
|
2025-01-25 23:37:19 -05:00
|
|
|
inner join "albums_assets_assets" as "album_assets" on "album_assets"."albumsId" = "albums"."id"
|
2025-01-21 11:24:48 -06:00
|
|
|
where
|
|
|
|
|
(
|
2025-01-25 23:37:19 -05:00
|
|
|
"albums"."ownerId" = $1
|
|
|
|
|
or exists (
|
|
|
|
|
select
|
|
|
|
|
from
|
|
|
|
|
"albums_shared_users_users" as "album_users"
|
|
|
|
|
where
|
|
|
|
|
"album_users"."albumsId" = "albums"."id"
|
|
|
|
|
and "album_users"."usersId" = $2
|
2023-11-30 10:10:30 -05:00
|
|
|
)
|
|
|
|
|
)
|
2025-01-25 23:37:19 -05:00
|
|
|
and "album_assets"."assetsId" = $3
|
2025-01-21 11:24:48 -06:00
|
|
|
and "albums"."deletedAt" is null
|
|
|
|
|
order by
|
|
|
|
|
"albums"."createdAt" desc,
|
|
|
|
|
"albums"."createdAt" desc
|
2023-11-30 10:10:30 -05:00
|
|
|
|
|
|
|
|
-- AlbumRepository.getMetadataForIds
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
2025-04-01 00:28:41 +13:00
|
|
|
"album_assets"."albumsId" as "albumId",
|
|
|
|
|
min(
|
|
|
|
|
("assets"."localDateTime" AT TIME ZONE 'UTC'::text)::date
|
|
|
|
|
) as "startDate",
|
|
|
|
|
max(
|
|
|
|
|
("assets"."localDateTime" AT TIME ZONE 'UTC'::text)::date
|
|
|
|
|
) as "endDate",
|
|
|
|
|
max("assets"."updatedAt") as "lastModifiedAssetTimestamp",
|
2025-01-25 23:37:19 -05:00
|
|
|
count("assets"."id")::int as "assetCount"
|
2025-01-21 11:24:48 -06:00
|
|
|
from
|
2025-04-01 00:28:41 +13:00
|
|
|
"assets"
|
|
|
|
|
inner join "albums_assets_assets" as "album_assets" on "album_assets"."assetsId" = "assets"."id"
|
2025-01-21 11:24:48 -06:00
|
|
|
where
|
2025-04-01 00:28:41 +13:00
|
|
|
"album_assets"."albumsId" in ($1)
|
2025-01-25 23:45:13 +01:00
|
|
|
and "assets"."deletedAt" is null
|
2025-01-21 11:24:48 -06:00
|
|
|
group by
|
2025-04-01 00:28:41 +13:00
|
|
|
"album_assets"."albumsId"
|
2023-11-30 10:10:30 -05:00
|
|
|
|
|
|
|
|
-- AlbumRepository.getOwned
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
"albums".*,
|
2023-11-30 10:10:30 -05:00
|
|
|
(
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
to_json(obj)
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
"id",
|
2025-04-14 20:34:06 +02:00
|
|
|
"name",
|
2025-01-21 11:24:48 -06:00
|
|
|
"email",
|
|
|
|
|
"profileImagePath",
|
|
|
|
|
"profileChangedAt"
|
|
|
|
|
from
|
|
|
|
|
"users"
|
|
|
|
|
where
|
|
|
|
|
"users"."id" = "albums"."ownerId"
|
|
|
|
|
) as obj
|
|
|
|
|
) as "owner",
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
coalesce(json_agg(agg), '[]')
|
|
|
|
|
from
|
2024-02-06 22:06:02 +00:00
|
|
|
(
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
2025-04-14 20:34:06 +02:00
|
|
|
"album_users"."role",
|
2024-02-06 22:06:02 +00:00
|
|
|
(
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
to_json(obj)
|
|
|
|
|
from
|
2024-04-25 06:19:49 +02:00
|
|
|
(
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
"id",
|
2025-04-14 20:34:06 +02:00
|
|
|
"name",
|
2025-01-21 11:24:48 -06:00
|
|
|
"email",
|
|
|
|
|
"profileImagePath",
|
|
|
|
|
"profileChangedAt"
|
|
|
|
|
from
|
|
|
|
|
"users"
|
|
|
|
|
where
|
|
|
|
|
"users"."id" = "album_users"."usersId"
|
|
|
|
|
) as obj
|
|
|
|
|
) as "user"
|
|
|
|
|
from
|
|
|
|
|
"albums_shared_users_users" as "album_users"
|
|
|
|
|
where
|
|
|
|
|
"album_users"."albumsId" = "albums"."id"
|
|
|
|
|
) as agg
|
|
|
|
|
) as "albumUsers",
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
coalesce(json_agg(agg), '[]')
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
*
|
|
|
|
|
from
|
|
|
|
|
"shared_links"
|
|
|
|
|
where
|
|
|
|
|
"shared_links"."albumId" = "albums"."id"
|
|
|
|
|
) as agg
|
|
|
|
|
) as "sharedLinks"
|
|
|
|
|
from
|
|
|
|
|
"albums"
|
|
|
|
|
where
|
|
|
|
|
"albums"."ownerId" = $1
|
|
|
|
|
and "albums"."deletedAt" is null
|
|
|
|
|
order by
|
|
|
|
|
"albums"."createdAt" desc
|
|
|
|
|
|
|
|
|
|
-- AlbumRepository.getShared
|
2025-01-25 23:37:19 -05:00
|
|
|
select
|
|
|
|
|
"albums".*,
|
2025-01-21 11:24:48 -06:00
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
coalesce(json_agg(agg), '[]')
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
2025-04-14 20:34:06 +02:00
|
|
|
"album_users"."role",
|
2024-02-06 22:06:02 +00:00
|
|
|
(
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
to_json(obj)
|
|
|
|
|
from
|
2024-02-06 22:06:02 +00:00
|
|
|
(
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
"id",
|
2025-04-14 20:34:06 +02:00
|
|
|
"name",
|
2025-01-21 11:24:48 -06:00
|
|
|
"email",
|
|
|
|
|
"profileImagePath",
|
|
|
|
|
"profileChangedAt"
|
|
|
|
|
from
|
|
|
|
|
"users"
|
|
|
|
|
where
|
|
|
|
|
"users"."id" = "album_users"."usersId"
|
|
|
|
|
) as obj
|
|
|
|
|
) as "user"
|
|
|
|
|
from
|
|
|
|
|
"albums_shared_users_users" as "album_users"
|
|
|
|
|
where
|
|
|
|
|
"album_users"."albumsId" = "albums"."id"
|
|
|
|
|
) as agg
|
|
|
|
|
) as "albumUsers",
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
to_json(obj)
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
"id",
|
2025-04-14 20:34:06 +02:00
|
|
|
"name",
|
2025-01-21 11:24:48 -06:00
|
|
|
"email",
|
|
|
|
|
"profileImagePath",
|
|
|
|
|
"profileChangedAt"
|
|
|
|
|
from
|
|
|
|
|
"users"
|
|
|
|
|
where
|
|
|
|
|
"users"."id" = "albums"."ownerId"
|
|
|
|
|
) as obj
|
|
|
|
|
) as "owner",
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
coalesce(json_agg(agg), '[]')
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
*
|
|
|
|
|
from
|
|
|
|
|
"shared_links"
|
|
|
|
|
where
|
|
|
|
|
"shared_links"."albumId" = "albums"."id"
|
|
|
|
|
) as agg
|
|
|
|
|
) as "sharedLinks"
|
|
|
|
|
from
|
|
|
|
|
"albums"
|
|
|
|
|
where
|
|
|
|
|
(
|
2025-01-25 23:37:19 -05:00
|
|
|
exists (
|
|
|
|
|
select
|
|
|
|
|
from
|
|
|
|
|
"albums_shared_users_users" as "album_users"
|
|
|
|
|
where
|
|
|
|
|
"album_users"."albumsId" = "albums"."id"
|
|
|
|
|
and (
|
|
|
|
|
"albums"."ownerId" = $1
|
|
|
|
|
or "album_users"."usersId" = $2
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
or exists (
|
|
|
|
|
select
|
|
|
|
|
from
|
|
|
|
|
"shared_links"
|
|
|
|
|
where
|
|
|
|
|
"shared_links"."albumId" = "albums"."id"
|
|
|
|
|
and "shared_links"."userId" = $3
|
2023-11-30 10:10:30 -05:00
|
|
|
)
|
|
|
|
|
)
|
2025-01-21 11:24:48 -06:00
|
|
|
and "albums"."deletedAt" is null
|
|
|
|
|
order by
|
|
|
|
|
"albums"."createdAt" desc
|
2023-11-30 10:10:30 -05:00
|
|
|
|
|
|
|
|
-- AlbumRepository.getNotShared
|
2025-01-25 23:37:19 -05:00
|
|
|
select
|
|
|
|
|
"albums".*,
|
2025-01-21 11:24:48 -06:00
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
to_json(obj)
|
|
|
|
|
from
|
|
|
|
|
(
|
|
|
|
|
select
|
|
|
|
|
"id",
|
2025-04-14 20:34:06 +02:00
|
|
|
"name",
|
2025-01-21 11:24:48 -06:00
|
|
|
"email",
|
|
|
|
|
"profileImagePath",
|
|
|
|
|
"profileChangedAt"
|
|
|
|
|
from
|
|
|
|
|
"users"
|
|
|
|
|
where
|
|
|
|
|
"users"."id" = "albums"."ownerId"
|
|
|
|
|
) as obj
|
2025-01-25 23:37:19 -05:00
|
|
|
) as "owner"
|
2025-01-21 11:24:48 -06:00
|
|
|
from
|
|
|
|
|
"albums"
|
|
|
|
|
where
|
|
|
|
|
"albums"."ownerId" = $1
|
|
|
|
|
and "albums"."deletedAt" is null
|
2025-01-25 23:37:19 -05:00
|
|
|
and not exists (
|
|
|
|
|
select
|
|
|
|
|
from
|
|
|
|
|
"albums_shared_users_users" as "album_users"
|
|
|
|
|
where
|
|
|
|
|
"album_users"."albumsId" = "albums"."id"
|
|
|
|
|
)
|
|
|
|
|
and not exists (
|
|
|
|
|
select
|
|
|
|
|
from
|
|
|
|
|
"shared_links"
|
|
|
|
|
where
|
|
|
|
|
"shared_links"."albumId" = "albums"."id"
|
|
|
|
|
)
|
2025-01-21 11:24:48 -06:00
|
|
|
order by
|
|
|
|
|
"albums"."createdAt" desc
|
2023-11-30 10:10:30 -05:00
|
|
|
|
|
|
|
|
-- AlbumRepository.getAssetIds
|
2025-01-21 11:24:48 -06:00
|
|
|
select
|
|
|
|
|
*
|
|
|
|
|
from
|
|
|
|
|
"albums_assets_assets"
|
|
|
|
|
where
|
|
|
|
|
"albums_assets_assets"."albumsId" = $1
|
|
|
|
|
and "albums_assets_assets"."assetsId" in ($2)
|