← Back to team overview

ubuntu-touch-coreapps team mailing list archive

Re: [Ubuntu-phone] U1dB Documentation and Advice

 

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks for your quick reply, please see my comments embedded below.

On 06/01/14 12:17, Christian Dywan wrote:
> On 2014-01-05 23:29, Nekhelesh Ramananthan wrote:
>> So I have been spending my entire weekend trying to figure out
>> U1dB-Qt and trying to create a sample test program, I did some of
>> this work with Andrew Hayzen from the music app team. While we
>> did succeed in implementing some basic functionalities like
>> static and dynamic document creation, there were some areas which
>> were unclear to us. My plan was to get familiar with using u1db
>> and then blog about its usage. However since we hit some
>> roadblocks while trying to implement the sample test program, I
>> thought it would be best to bring it up on the mailing list and
>> get some questions answered. So here goes some of my
>> observations,
> Cool! I'll see how I can help paving the road!
>> 
>> 1. It is a common scenario where a developer has to resort to
>> dynamic document creation. While we managed to create the
>> documents using the putDoc() function, we had some issues with
>> using U1db.Index and U1db.Query. As I understand Index and Query
>> provide the capability to filter specific documents in a database
>> which can then be sent to a listview for display purposes.
>> However Andrew and I have been troubled with setting up an Index.
>> The document structure was as follows,
>> 
>> { "playlist" : { "name": "Rock", "tracks": [ { "file":
>> "filepath", "title": "ABC" }, { "file": "filepath2", "title":
>> "DEF" } ] } }
>> 
>> We set up a Index and Query as shown below,
>> 
>> U1db.Index { id: "by_playlist" database: db expression:
>> ["playlist.name <http://playlist.name>", "playlist.tracks.file",
>> "playlist.tracks.title"] }
>> 
>> U1db.Query { id: aQuery index: "by_playlist" query: [{"name":"*",
>> "file":"*", "title":"*"}] }
>> 
>> However while using the aQuery object as a model in our listview,
>> it didnt work out as expected. I observed that the index
>> expressions has to have the same length. Because the moment I
>> changed the index expression to ["playlist.name
>> <http://playlist.name>", "playlist.tracks"], things started
>> working out better. So my question is, if it is possible for
>> Christian or Lucio to perhaps provide a short tutorial on how one
>> goes about using Index and Queries. That part is not really
>> understandable from the documentation available.
> Have you seen http://developer.ubuntu.com/api/qml/sdk-1.0/U1DB/ ? 
> As the doc website continues to be a moving target there's no URL
> to save but this is the latest, and I think it's uptodate with
> trunk.
> 
> I agree more about index/ query would be good.
> 
> 
> Maybe as an idea we could try to come up with a way to issue a
> warning on the console if the query doesn't match the index? If
> there's a way to avoid spamming the logs - with QML we cannot throw
> errors in such a situation as it's all lazily evaluated. It would
> need some thinking on how to do it best.
>> 2. Also I would like to know if feature parity between the u1db
>> python and u1db qt implementation has been achieved. Because
>> while specifying the u1db.Queries, we were unable to specific
>> logical expression to perform appropriate filtering like doing
>> numeric expression like number1>somevalue. At the moment I am
>> only able to specify name:"Rock" to show specific documents or
>> name:"*" to show everything.
>> 
> Short answer: not yet.
> 
> QML works quite differently to python including how queries are
> lazily evaluated and not function calls. There's been some
> brainstorming over more expressions and whether to inherit from
> python or go for slightly different ones that feel more "natural". 
> There's a bug report
> https://bugs.launchpad.net/u1db-qt/+bug/1217963 unfortunatley time/
> progress fell short.
> 
> If you're interested this would be awesome to get some helping 
> brains/hands on. <https://bugs.launchpad.net/u1db-qt/+bug/1217963>
>> 3. In the document structure mentioned above, we have 3 layers of
>> data -> playlist.tracks.file. How does one go about displaying
>> this properly in a listview. We were able to only display the
>> playlist name by specifying contents.name <http://contents.name>
>> in the delegate. But when we did contents.tracks.title, it just
>> showed it as undefined.
>> 
> file is a list so I would expect playlist.tracks[0].file

In most of our attempts it came back as undefined or we had strange
results :/

Basically we need a query that is a list of tracks for a specific
playlist name that can then be used in a listview with a separate row
for each track.

Is there anyway to replicate the python example below which is similar
to what we require, that Stuart provided, so that a track will be on
each row of the listmodel in QML?

import u1db; db=u1db.open(':memory:',create=True);
db.create_index('by-file', 'playlist.name','playlist.tracks.file');
doc=db.create_doc(
  {'playlist':{'name':'playlist1',
'tracks':[{'file':'pl1-one'},{'file':'pl1-two'}]}}); doc=db.create_doc(
  {'playlist':{'name':'playlist2',
'tracks':[{'file':'pl2-one'},{'file':'pl2-two'}]}});

print db.get_index_keys('by-file')
which prints
[(u'playlist1', u'pl1-one'), (u'playlist1', u'pl1-two'),
(u'playlist2', u'pl2-one'), (u'playlist2', u'pl2-two')]

>> 4. While displaying the data in a listview, we were unable to
>> sort it unlike in the python u1db implementation.
> Can you be more specific there?
> 

I'm storing the recently played items in U1DB as separate documents.
I need the results of the query to be *sorted* by recent.time in a
descending order to give the most recent items first.

> ciao, Christian
> 
> 
> 

Thanks,

Andrew Hayzen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSyw3vAAoJEODyjTCPZv776C4IAIddEvuzCpYeqKIaYqKFHvq+
yisClS+1gGesD0krgCsICSUaK9LQmy2NSMKG9MUV1QdJ5LaTdZUmcgDYDI3QY8j4
f3h8+SMSpLnklJCyWwWZc2jTDuA4hFOxgmYMGw/0Y5yjde5d1HOHArGAFkVad7wp
8L5BqpBic4Fk9m03P6EJsjrEdOzDlpxpE3ixJHzFv12VR9Tdy3/yZKjxDfeE98QF
vlz+V3kxIgAPN/+RqEmDmNJfTmOhnC5QEYR2vIhwyG0MSCIfL0kKbZ3JKZv6NPxP
bnTkWXs+CmJx1ddup2A6WZJlRh2QEbOxM8LNgvP1MUSF1RXxo2W/eaObdQOkqP0=
=mo1y
-----END PGP SIGNATURE-----


Follow ups

References