-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db) added queries and implemented database_sql.rs functions.
- Loading branch information
1 parent
5f4c5d3
commit dc24c43
Showing
7 changed files
with
157 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- Binds: user_id, resource_url, start, end, document_id | ||
|
||
with upserted_audio_resource as ( | ||
insert into media_resource (url, recorded_at, recorded_by) | ||
select $2::text, now(), $1 | ||
-- we do this no-op update to ensure an id is returned | ||
on conflict (url) do update set url=excluded.url | ||
returning id | ||
), | ||
|
||
inserted_audio_slice as ( | ||
insert into media_slice (resource_id, time_range) | ||
select upserted_audio_resource.id, int8range($3, $4) | ||
from upserted_audio_resource | ||
returning id | ||
) | ||
|
||
insert into document_user_media (document_id, media_slice_id) | ||
select $5, inserted_audio_slice.id | ||
from inserted_audio_slice | ||
join document on document.id = $5 | ||
on conflict (media_slice_id, document_id) do nothing -- document already associated | ||
returning media_slice_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
select | ||
media_slice.id as "id", | ||
media_slice.time_range as "range?", | ||
media_resource.url as "resource_url", | ||
document_user_media.include_in_edited_collection as "include_in_edited_collection", | ||
media_resource.recorded_at as "recorded_at?", | ||
contributor.id as "recorded_by?", | ||
contributor.display_name as "recorded_by_name?", | ||
editor.id as "edited_by?", | ||
editor.display_name as "edited_by_name?" | ||
from document_user_media | ||
left join media_slice on media_slice.id = document_user_media.media_slice_id | ||
left join media_resource on media_resource.id = media_slice.resource_id | ||
left join dailp_user contributor on contributor.id = media_resource.recorded_by | ||
left join dailp_user editor on editor.id = document_user_media.edited_by | ||
where | ||
document_id = $1 | ||
order by media_resource.recorded_at desc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- Binds: document_id, slice_id, include_in_edited_collection, editor_id | ||
|
||
with document_update as ( | ||
-- update ingested audio, if the slice_id was ingested audio | ||
update document | ||
set include_audio_in_edited_collection=$3, | ||
audio_edited_by=$4 | ||
where document.id = $1 | ||
-- if the slice_id given doesn't match, we won't update | ||
and document.audio_slice_id = $2 | ||
returning document.id as document_id | ||
), | ||
document_user_media_update as ( | ||
-- update user contributed audio, if the slice id is user contributed audio tied to the document | ||
update document_user_media | ||
set include_in_edited_collection=$3, | ||
edited_by=$4 | ||
where document_id = $1 | ||
and media_slice_id = $2 | ||
returning document_id | ||
) | ||
|
||
select distinct t.document_id | ||
from ( | ||
select document_id from document_update | ||
union | ||
select document_id from document_user_media_update | ||
) as t |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters