diff options
author | dakkar <dakkar@thenautilus.net> | 2018-03-03 14:07:18 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2018-03-03 14:07:18 +0000 |
commit | 09650d2214422d3e56adbf1885dca3aa07ce1f7e (patch) | |
tree | dd3333be95cb0d457e37873795fb233733272652 /lib/Ultramarine/Model/DB/SQLite.pm6 | |
parent | allow both POST and GET (diff) | |
download | Ultramarine-09650d2214422d3e56adbf1885dca3aa07ce1f7e.tar.gz Ultramarine-09650d2214422d3e56adbf1885dca3aa07ce1f7e.tar.bz2 Ultramarine-09650d2214422d3e56adbf1885dca3aa07ce1f7e.zip |
more retrieval methods in DB
Diffstat (limited to 'lib/Ultramarine/Model/DB/SQLite.pm6')
-rw-r--r-- | lib/Ultramarine/Model/DB/SQLite.pm6 | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/lib/Ultramarine/Model/DB/SQLite.pm6 b/lib/Ultramarine/Model/DB/SQLite.pm6 index 8a0e017..030a32f 100644 --- a/lib/Ultramarine/Model/DB/SQLite.pm6 +++ b/lib/Ultramarine/Model/DB/SQLite.pm6 @@ -130,7 +130,7 @@ class Ultramarine::Model::DB::SQLite does Ultramarine::Model::DB { $rel-path .= parent; } }; - my $parent-id=Nil; + my $parent-id=$ROOT-DIR-ID; while my $name = @components.pop { $parent-id = self.ensure-one-directory(:$name,:$parent-id); } @@ -214,7 +214,9 @@ class Ultramarine::Model::DB::SQLite does Ultramarine::Model::DB { sub unpack-row(%song is copy) { %song<metadata> = from-json(%song<metadata>); - return %song; + return Ultramarine::Model::DB::File.new( + |(%song<id path mtime metadata album_id>:p.Capture), + ); } method get-song(Str() :$path!) { @@ -228,6 +230,52 @@ class Ultramarine::Model::DB::SQLite does Ultramarine::Model::DB { return unpack-row($sth.row(:hash)); } + method top-folders() { + return (Ultramarine::Model::DB::Directory.new( + id => $ROOT-DIR-ID, + name => 'Music', + ),); + } + + method dir-children-of(Int() :$id = $ROOT-DIR-ID) { + my $sth = $!dbh.prepare(q:to/END/); + SELECT * + FROM directories + WHERE parent_id = ? + AND id != ? + ORDER BY name ASC + END + # the C< AND id != ? > is because the root dir is its own + # parent, and we never want to return it + $sth.execute($id,$id); + + return gather { + while $sth.row(:hash) -> %dir { + take Ultramarine::Model::DB::Directory.new( + |(%dir<id name>:p.Capture), + ); + } + .finish with $sth; + }; + } + + method songs-children-of(Int() :$id = $ROOT-DIR-ID) { + my $sth = $!dbh.prepare(q:to/END/); + SELECT * + FROM songs + WHERE directory_id = ? + ORDER BY path ASC + END + $sth.execute($id); + + return gather { + while $sth.row(:hash) -> %song { + take unpack-row(%song); + } + .finish with $sth; + }; + } + method all-songs() { my $sth = $!dbh.prepare(q:to/END/); SELECT * |