| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- package repository
- const querySelectSongById = `
- select
- id
- ,track_number
- ,title
- ,artist
- ,album
- ,duration
- ,modified_date
- ,base_path
- ,relative_path
- from songs
- where id = ANY($1)
- `
- const querySelectArtistsOrdered = `
- select distinct artist
- from songs
- order by artist
- limit $1
- offset $2
- `
- const queryCountArtists = `
- select count(*) as count from (
- select distinct artist from songs
- ) distinct_artists
- `
- const querySelectAlbumsByArtist = `
- select distinct album
- from songs
- where artist = $1
- order by album
- `
- const querySelectSongsByArtist = `
- select
- id
- ,track_number
- ,title
- ,artist
- ,album
- ,duration
- from songs
- where artist = $1
- order by album, track_number, title, id
- `
- const queryInsertSongs = `
- insert into songs (
- track_number
- ,title
- ,artist
- ,album
- ,duration
- ,modified_date
- ,base_path
- ,relative_path
- )
- select * from unnest(
- $1::integer[]
- ,$2::varchar[]
- ,$3::varchar[]
- ,$4::varchar[]
- ,$5::integer[]
- ,$6::bigint[]
- ,$7::varchar[]
- ,$8::varchar[]
- )
- on conflict (base_path, relative_path) do update
- set
- track_number = excluded.track_number
- ,title = excluded.title
- ,artist = excluded.artist
- ,album = excluded.album
- ,duration = excluded.duration
- ,modified_date = excluded.modified_date
- `
- const querySelectNextSong = `
- select
- s1.id
- ,s1.track_number
- ,s1.title
- ,s1.artist
- ,s1.album
- ,s1.duration
- from (
- select * from songs where id = $1
- ) s0
- left join songs s1 on (
- s1.artist > s0.artist
- or (s1.artist = s0.artist
- and s1.album > s0.album
- )
- or (s1.artist = s0.artist
- and s1.album = s0.album
- and s1.track_number > s0.track_number
- )
- or (s1.artist = s0.artist
- and s1.album = s0.album
- and s1.track_number = s0.track_number
- and s1.title > s0.title
- )
- or (s1.artist = s0.artist
- and s1.album = s0.album
- and s1.track_number = s0.track_number
- and s1.title = s0.title
- and s1.id > s0.id
- )
- )
- order by
- s1.artist
- ,s1.album
- ,s1.track_number
- ,s1.title
- ,s1.id
- limit 1
- `
- const querySelectPrevSong = `
- select
- s1.id
- ,s1.track_number
- ,s1.title
- ,s1.artist
- ,s1.album
- ,s1.duration
- from (
- select * from songs where id = $1
- ) s0
- left join songs s1 on (
- s1.artist < s0.artist
- or (s1.artist = s0.artist
- and s1.album < s0.album
- )
- or (s1.artist = s0.artist
- and s1.album = s0.album
- and s1.track_number < s0.track_number
- )
- or (s1.artist = s0.artist
- and s1.album = s0.album
- and s1.track_number = s0.track_number
- and s1.title < s0.title
- )
- or (s1.artist = s0.artist
- and s1.album = s0.album
- and s1.track_number = s0.track_number
- and s1.title = s0.title
- and s1.id < s0.id
- )
- )
- order by
- s1.artist desc
- ,s1.album desc
- ,s1.track_number desc
- ,s1.title desc
- ,s1.id desc
- limit 1
- `
|