361 lines
7.8 KiB
SQL
361 lines
7.8 KiB
SQL
-- NOTE: This file is auto generated by ./sql-generator
|
|
|
|
-- MemoryRepository.statistics
|
|
select
|
|
count(*) as "total"
|
|
from
|
|
"memory"
|
|
where
|
|
"deletedAt" is null
|
|
and "ownerId" = $1
|
|
|
|
-- MemoryRepository.statistics (date filter)
|
|
select
|
|
count(*) as "total"
|
|
from
|
|
"memory"
|
|
where
|
|
(
|
|
"showAt" is null
|
|
or "showAt" <= $1
|
|
)
|
|
and (
|
|
"hideAt" is null
|
|
or "hideAt" >= $2
|
|
)
|
|
and "deletedAt" is null
|
|
and "ownerId" = $3
|
|
|
|
-- MemoryRepository.search
|
|
select
|
|
(
|
|
select
|
|
coalesce(json_agg(agg), '[]')
|
|
from
|
|
(
|
|
select
|
|
"asset".*
|
|
from
|
|
"asset"
|
|
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
|
|
where
|
|
"memory_asset"."memoriesId" = "memory"."id"
|
|
and "asset"."visibility" = 'timeline'
|
|
and "asset"."deletedAt" is null
|
|
and not exists (
|
|
select
|
|
$1 as "one"
|
|
from
|
|
"asset_face"
|
|
inner join "person" on "person"."personGroupId" = "asset_face"."personGroupId"
|
|
and "person"."ownerId" = "asset"."ownerId"
|
|
where
|
|
"asset_face"."assetId" = "asset"."id"
|
|
and "person"."isHidden" = $2
|
|
)
|
|
order by
|
|
"asset"."fileCreatedAt" asc
|
|
) as agg
|
|
) as "assets",
|
|
"memory".*
|
|
from
|
|
"memory"
|
|
where
|
|
"deletedAt" is null
|
|
and "ownerId" = $3
|
|
order by
|
|
"showAt" desc nulls last,
|
|
"memoryAt" desc
|
|
|
|
-- MemoryRepository.search (date filter)
|
|
select
|
|
(
|
|
select
|
|
coalesce(json_agg(agg), '[]')
|
|
from
|
|
(
|
|
select
|
|
"asset".*
|
|
from
|
|
"asset"
|
|
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
|
|
where
|
|
"memory_asset"."memoriesId" = "memory"."id"
|
|
and "asset"."visibility" = 'timeline'
|
|
and "asset"."deletedAt" is null
|
|
and not exists (
|
|
select
|
|
$1 as "one"
|
|
from
|
|
"asset_face"
|
|
inner join "person" on "person"."personGroupId" = "asset_face"."personGroupId"
|
|
and "person"."ownerId" = "asset"."ownerId"
|
|
where
|
|
"asset_face"."assetId" = "asset"."id"
|
|
and "person"."isHidden" = $2
|
|
)
|
|
order by
|
|
"asset"."fileCreatedAt" asc
|
|
) as agg
|
|
) as "assets",
|
|
"memory".*
|
|
from
|
|
"memory"
|
|
where
|
|
(
|
|
"showAt" is null
|
|
or "showAt" <= $3
|
|
)
|
|
and (
|
|
"hideAt" is null
|
|
or "hideAt" >= $4
|
|
)
|
|
and "deletedAt" is null
|
|
and "ownerId" = $5
|
|
order by
|
|
"showAt" desc nulls last,
|
|
"memoryAt" desc
|
|
|
|
-- MemoryRepository.search (upcoming filter)
|
|
select
|
|
(
|
|
select
|
|
coalesce(json_agg(agg), '[]')
|
|
from
|
|
(
|
|
select
|
|
"asset".*
|
|
from
|
|
"asset"
|
|
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
|
|
where
|
|
"memory_asset"."memoriesId" = "memory"."id"
|
|
and "asset"."visibility" = 'timeline'
|
|
and "asset"."deletedAt" is null
|
|
and not exists (
|
|
select
|
|
$1 as "one"
|
|
from
|
|
"asset_face"
|
|
inner join "person" on "person"."personGroupId" = "asset_face"."personGroupId"
|
|
and "person"."ownerId" = "asset"."ownerId"
|
|
where
|
|
"asset_face"."assetId" = "asset"."id"
|
|
and "person"."isHidden" = $2
|
|
)
|
|
order by
|
|
"asset"."fileCreatedAt" asc
|
|
) as agg
|
|
) as "assets",
|
|
"memory".*
|
|
from
|
|
"memory"
|
|
where
|
|
"showAt" > $3
|
|
and "deletedAt" is null
|
|
and "ownerId" = $4
|
|
order by
|
|
"showAt" desc nulls last,
|
|
"memoryAt" desc
|
|
|
|
-- MemoryRepository.search (not upcoming filter)
|
|
select
|
|
(
|
|
select
|
|
coalesce(json_agg(agg), '[]')
|
|
from
|
|
(
|
|
select
|
|
"asset".*
|
|
from
|
|
"asset"
|
|
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
|
|
where
|
|
"memory_asset"."memoriesId" = "memory"."id"
|
|
and "asset"."visibility" = 'timeline'
|
|
and "asset"."deletedAt" is null
|
|
and not exists (
|
|
select
|
|
$1 as "one"
|
|
from
|
|
"asset_face"
|
|
inner join "person" on "person"."personGroupId" = "asset_face"."personGroupId"
|
|
and "person"."ownerId" = "asset"."ownerId"
|
|
where
|
|
"asset_face"."assetId" = "asset"."id"
|
|
and "person"."isHidden" = $2
|
|
)
|
|
order by
|
|
"asset"."fileCreatedAt" asc
|
|
) as agg
|
|
) as "assets",
|
|
"memory".*
|
|
from
|
|
"memory"
|
|
where
|
|
(
|
|
"showAt" is null
|
|
or "showAt" <= $3
|
|
)
|
|
and "deletedAt" is null
|
|
and "ownerId" = $4
|
|
order by
|
|
"showAt" desc nulls last,
|
|
"memoryAt" desc
|
|
|
|
-- MemoryRepository.getPersonBirthdayYears
|
|
select distinct
|
|
date_part(
|
|
'year',
|
|
(asset."localDateTime" at time zone 'UTC')::date
|
|
)::int as "year"
|
|
from
|
|
"asset"
|
|
where
|
|
"asset"."ownerId" = $1
|
|
and "asset"."visibility" = $2
|
|
and "asset"."deletedAt" is null
|
|
and exists (
|
|
select
|
|
from
|
|
"asset_face"
|
|
where
|
|
"asset_face"."assetId" = "asset"."id"
|
|
and "asset_face"."personGroupId" = $3
|
|
and "asset_face"."deletedAt" is null
|
|
and "asset_face"."isVisible" is true
|
|
)
|
|
and exists (
|
|
select
|
|
from
|
|
"asset_file"
|
|
where
|
|
"asset_file"."assetId" = "asset"."id"
|
|
and "asset_file"."type" = $4
|
|
)
|
|
and date_part(
|
|
'month',
|
|
(asset."localDateTime" at time zone 'UTC')::date
|
|
)::int = $5
|
|
and date_part(
|
|
'day',
|
|
(asset."localDateTime" at time zone 'UTC')::date
|
|
)::int = $6
|
|
and (asset."localDateTime" at time zone 'UTC')::date >= make_date($7::int, $8::int, $9::int)
|
|
and (asset."localDateTime" at time zone 'UTC')::date < make_date($10::int, $11::int, $12::int)
|
|
order by
|
|
year desc
|
|
|
|
-- MemoryRepository.getPersonAssetsByDate
|
|
select
|
|
"asset"."id"
|
|
from
|
|
"asset"
|
|
where
|
|
"asset"."ownerId" = $1
|
|
and "asset"."visibility" = $2
|
|
and "asset"."deletedAt" is null
|
|
and exists (
|
|
select
|
|
from
|
|
"asset_face"
|
|
where
|
|
"asset_face"."assetId" = "asset"."id"
|
|
and "asset_face"."personGroupId" = $3
|
|
and "asset_face"."deletedAt" is null
|
|
and "asset_face"."isVisible" is true
|
|
)
|
|
and exists (
|
|
select
|
|
from
|
|
"asset_file"
|
|
where
|
|
"asset_file"."assetId" = "asset"."id"
|
|
and "asset_file"."type" = $4
|
|
)
|
|
and (asset."localDateTime" at time zone 'UTC')::date = make_date($5::int, $6::int, $7::int)
|
|
order by
|
|
"asset"."localDateTime" desc
|
|
limit
|
|
$8
|
|
|
|
-- MemoryRepository.get
|
|
select
|
|
"memory".*,
|
|
(
|
|
select
|
|
coalesce(json_agg(agg), '[]')
|
|
from
|
|
(
|
|
select
|
|
"asset".*
|
|
from
|
|
"asset"
|
|
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
|
|
where
|
|
"memory_asset"."memoriesId" = "memory"."id"
|
|
and "asset"."visibility" = 'timeline'
|
|
and "asset"."deletedAt" is null
|
|
order by
|
|
"asset"."fileCreatedAt" asc
|
|
) as agg
|
|
) as "assets"
|
|
from
|
|
"memory"
|
|
where
|
|
"id" = $1
|
|
and "deletedAt" is null
|
|
|
|
-- MemoryRepository.update
|
|
update "memory"
|
|
set
|
|
"ownerId" = $1,
|
|
"isSaved" = $2
|
|
where
|
|
"id" = $3
|
|
select
|
|
"memory".*,
|
|
(
|
|
select
|
|
coalesce(json_agg(agg), '[]')
|
|
from
|
|
(
|
|
select
|
|
"asset".*
|
|
from
|
|
"asset"
|
|
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
|
|
where
|
|
"memory_asset"."memoriesId" = "memory"."id"
|
|
and "asset"."visibility" = 'timeline'
|
|
and "asset"."deletedAt" is null
|
|
order by
|
|
"asset"."fileCreatedAt" asc
|
|
) as agg
|
|
) as "assets"
|
|
from
|
|
"memory"
|
|
where
|
|
"id" = $1
|
|
and "deletedAt" is null
|
|
|
|
-- MemoryRepository.delete
|
|
delete from "memory"
|
|
where
|
|
"id" = $1
|
|
|
|
-- MemoryRepository.getAssetIds
|
|
select
|
|
"assetId"
|
|
from
|
|
"memory_asset"
|
|
where
|
|
"memoriesId" = $1
|
|
and "assetId" in ($2)
|
|
|
|
-- MemoryRepository.addAssetIds
|
|
insert into
|
|
"memory_asset" ("memoriesId", "assetId")
|
|
values
|
|
($1, $2)
|