[gnome-music/wip/merge: 121/343] query: format queries nicely
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/merge: 121/343] query: format queries nicely
- Date: Thu, 25 Jul 2013 11:23:35 +0000 (UTC)
commit 94023bf6249e70834c1abb6161793c58a5def0f0
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date: Mon Jul 15 17:47:27 2013 +0200
query: format queries nicely
gnomemusic/query.py | 346 +++++++++++++++++++++++++-------------------------
1 files changed, 173 insertions(+), 173 deletions(-)
---
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index 9814347..6883ae4 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -1,218 +1,218 @@
class Query():
ALBUMS = """
-SELECT DISTINCT
- rdf:type(?album)
- tracker:id(?album) AS id
- (
- SELECT
- nmm:artistName(?artist)
- WHERE {
- ?album nmm:albumArtist ?artist
- }
- LIMIT 1
- ) AS artist
- nie:title(?album) AS title
- nie:title(?album) AS album
- tracker:coalesce(
+ SELECT DISTINCT
+ rdf:type(?album)
+ tracker:id(?album) AS id
(
SELECT
- GROUP_CONCAT(
- nmm:artistName(?artist),
- ","
- )
+ nmm:artistName(?artist)
WHERE {
?album nmm:albumArtist ?artist
}
- ),
- (
- SELECT
- GROUP_CONCAT(
- (
- SELECT
- nmm:artistName(nmm:performer(?_12)) AS perf
- WHERE {
- ?_12 nmm:musicAlbum ?album
- }
- GROUP BY ?perf
- ),
- ","
- ) AS album_performer
- WHERE {
- }
- )
- ) AS author
- xsd:integer(
+ LIMIT 1
+ ) AS artist
+ nie:title(?album) AS title
+ nie:title(?album) AS album
tracker:coalesce(
- nmm:albumTrackCount(?album),
(
SELECT
- COUNT(?_1)
+ GROUP_CONCAT(
+ nmm:artistName(?artist),
+ ","
+ )
+ WHERE {
+ ?album nmm:albumArtist ?artist
+ }
+ ),
+ (
+ SELECT
+ GROUP_CONCAT(
+ (
+ SELECT
+ nmm:artistName(nmm:performer(?_12)) AS perf
+ WHERE {
+ ?_12 nmm:musicAlbum ?album
+ }
+ GROUP BY ?perf
+ ),
+ ","
+ ) AS album_performer
WHERE {
- ?_1 nmm:musicAlbum ?album ;
- tracker:available "true"
}
)
- )
- ) AS childcount
- (
- SELECT
- fn:year-from-dateTime(?c)
- WHERE {
- ?_2 nmm:musicAlbum ?album ;
- nie:contentCreated ?c ;
- tracker:available "true"
- }
- LIMIT 1
- ) AS creation-date
- {
- ?album a nmm:MusicAlbum .
- FILTER (
- EXISTS {
- ?_3 nmm:musicAlbum ?album ;
+ ) AS author
+ xsd:integer(
+ tracker:coalesce(
+ nmm:albumTrackCount(?album),
+ (
+ SELECT
+ COUNT(?_1)
+ WHERE {
+ ?_1 nmm:musicAlbum ?album ;
+ tracker:available "true"
+ }
+ )
+ )
+ ) AS childcount
+ (
+ SELECT
+ fn:year-from-dateTime(?c)
+ WHERE {
+ ?_2 nmm:musicAlbum ?album ;
+ nie:contentCreated ?c ;
tracker:available "true"
}
- )
- }
-ORDER BY nie:title(?album) ?author ?albumyear
-"""
+ LIMIT 1
+ ) AS creation-date
+ {
+ ?album a nmm:MusicAlbum .
+ FILTER (
+ EXISTS {
+ ?_3 nmm:musicAlbum ?album ;
+ tracker:available "true"
+ }
+ )
+ }
+ ORDER BY nie:title(?album) ?author ?albumyear
+ """.replace("\n", " ").strip()
ALBUMS_COUNT = """
-SELECT
- COUNT(?album) AS childcount
-WHERE {
- ?album a nmm:MusicAlbum
-}
-"""
+ SELECT
+ COUNT(?album) AS childcount
+ WHERE {
+ ?album a nmm:MusicAlbum
+ }
+ """.replace("\n", " ").strip()
ARTISTS = """
-SELECT DISTINCT
- rdf:type(?album)
- tracker:id(?album) AS id
- (
- SELECT
- nmm:artistName(?artist)
- WHERE {
- ?album nmm:albumArtist ?artist
- }
- LIMIT 1
- ) AS artist
- nie:title(?album) AS title
- nie:title(?album) AS album
- tracker:coalesce(
+ SELECT DISTINCT
+ rdf:type(?album)
+ tracker:id(?album) AS id
(
SELECT
- GROUP_CONCAT(
- nmm:artistName(?artist),
- ","
- )
+ nmm:artistName(?artist)
WHERE {
?album nmm:albumArtist ?artist
}
- ),
- (
- SELECT
- GROUP_CONCAT(
- (
- SELECT
- nmm:artistName(nmm:performer(?_12)) AS perf
- WHERE {
- ?_12 nmm:musicAlbum ?album
- }
- GROUP BY ?perf
- ),
- ","
- ) AS album_performer
- WHERE {
- }
- )
- ) AS author
- xsd:integer(
+ LIMIT 1
+ ) AS artist
+ nie:title(?album) AS title
+ nie:title(?album) AS album
tracker:coalesce(
- nmm:albumTrackCount(?album),
(
SELECT
- COUNT(?_1)
+ GROUP_CONCAT(
+ nmm:artistName(?artist),
+ ","
+ )
+ WHERE {
+ ?album nmm:albumArtist ?artist
+ }
+ ),
+ (
+ SELECT
+ GROUP_CONCAT(
+ (
+ SELECT
+ nmm:artistName(nmm:performer(?_12)) AS perf
+ WHERE {
+ ?_12 nmm:musicAlbum ?album
+ }
+ GROUP BY ?perf
+ ),
+ ","
+ ) AS album_performer
WHERE {
- ?_1 nmm:musicAlbum ?album ;
- tracker:available "true"
}
)
- )
- ) AS childcount
- (
- SELECT
- fn:year-from-dateTime(?c)
- WHERE {
- ?_2 nmm:musicAlbum ?album ;
- nie:contentCreated ?c ;
- tracker:available "true"
- }
- LIMIT 1
- ) AS creation-date
- {
- ?album a nmm:MusicAlbum .
- FILTER (
- EXISTS {
- ?_3 nmm:musicAlbum ?album ;
+ ) AS author
+ xsd:integer(
+ tracker:coalesce(
+ nmm:albumTrackCount(?album),
+ (
+ SELECT
+ COUNT(?_1)
+ WHERE {
+ ?_1 nmm:musicAlbum ?album ;
+ tracker:available "true"
+ }
+ )
+ )
+ ) AS childcount
+ (
+ SELECT
+ fn:year-from-dateTime(?c)
+ WHERE {
+ ?_2 nmm:musicAlbum ?album ;
+ nie:contentCreated ?c ;
tracker:available "true"
}
- )
- }
-ORDER BY ?author ?albumyear nie:title(?album)
-"""
+ LIMIT 1
+ ) AS creation-date
+ {
+ ?album a nmm:MusicAlbum .
+ FILTER (
+ EXISTS {
+ ?_3 nmm:musicAlbum ?album ;
+ tracker:available "true"
+ }
+ )
+ }
+ ORDER BY ?author ?albumyear nie:title(?album)
+ """.replace("\n", " ").strip()
ARTISTS_COUNT = """
-SELECT
- COUNT(DISTINCT ?artist)
-WHERE {
- ?artist a nmm:Artist .
- ?album nmm:performer ?artist
-}
-"""
+ SELECT
+ COUNT(DISTINCT ?artist)
+ WHERE {
+ ?artist a nmm:Artist .
+ ?album nmm:performer ?artist
+ }
+ """.replace("\n", " ").strip()
SONGS = """
-SELECT DISTINCT
- rdf:type(?song)
- tracker:id(?song) AS id
- nie:url(?song) AS url
- nie:title(?song) AS title
- nmm:artistName(nmm:performer(?song)) AS artist
- nie:title(nmm:musicAlbum(?song)) AS album
- nfo:duration(?song) AS duration
- {
- ?song a nmm:MusicPiece
- }
-ORDER BY tracker:added(?song)
-"""
+ SELECT DISTINCT
+ rdf:type(?song)
+ tracker:id(?song) AS id
+ nie:url(?song) AS url
+ nie:title(?song) AS title
+ nmm:artistName(nmm:performer(?song)) AS artist
+ nie:title(nmm:musicAlbum(?song)) AS album
+ nfo:duration(?song) AS duration
+ {
+ ?song a nmm:MusicPiece
+ }
+ ORDER BY tracker:added(?song)
+ """.replace("\n", " ").strip()
SONGS_COUNT = """
-SELECT
- COUNT(?song) AS childcount
-WHERE {
- ?song a nmm:MusicPiece
-}
-"""
+ SELECT
+ COUNT(?song) AS childcount
+ WHERE {
+ ?song a nmm:MusicPiece
+ }
+ """.replace("\n", " ").strip()
@staticmethod
def album_songs(album_id):
query = """
-SELECT DISTINCT
- rdf:type(?song)
- tracker:id(?song) AS id
- nie:url(?song) AS url
- nie:title(?song) AS title
- nmm:artistName(nmm:performer(?song)) AS artist
- nie:title(nmm:musicAlbum(?song)) AS album
- nfo:duration(?song) AS duration
-WHERE {
- ?song a nmm:MusicPiece ;
- nmm:musicAlbum ?album .
- FILTER (
- tracker:id(?album) = %(album_id)s
- )
-}
-ORDER BY nmm:trackNumber(?song) tracker:added(?song)
-""" % {'album_id': album_id}
+ SELECT DISTINCT
+ rdf:type(?song)
+ tracker:id(?song) AS id
+ nie:url(?song) AS url
+ nie:title(?song) AS title
+ nmm:artistName(nmm:performer(?song)) AS artist
+ nie:title(nmm:musicAlbum(?song)) AS album
+ nfo:duration(?song) AS duration
+ WHERE {
+ ?song a nmm:MusicPiece ;
+ nmm:musicAlbum ?album .
+ FILTER (
+ tracker:id(?album) = %(album_id)s
+ )
+ }
+ ORDER BY nmm:trackNumber(?song) tracker:added(?song)
+ """.replace("\n", " ").strip() % {'album_id': album_id}
return query
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]