← Back to team overview

ubuntu-phone team mailing list archive

Re: U1dB Documentation and Advice

 

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
> 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?

ciao,
    Christian

Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups

References