← Back to team overview

ubuntu-touch-coreapps team mailing list archive

Re: [Ubuntu-phone] U1dB Documentation and Advice

 

Hi everyone,

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,

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", "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", "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.

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.

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 in the delegate. But when we did contents.tracks.title, it
just showed it as undefined.

4. While displaying the data in a listview, we were unable to sort it
unlike in the python u1db implementation.

Any help would be appreciated. Thanks.

Cheers,
Nekhelesh

Follow ups

References