← Back to team overview

ubuntu-phone team mailing list archive

Re: Fwd: u1db with sub-field

 

Hey Yasmany,

I think you may have confused an aspect of how documents work. Your
example uses account.name but that is only the name of a document and
there's no such field.

I modified the example a bit, see the attached QML file. Have a look and
see if this helps.

ciao,
    Christian

On 30.07.2014 16:19, Yasmany Cubela Medina wrote:
> Hello everyone
>
> Im writing a ubuntu touch app with u1db as db,  but im getting
> troubles with query and index. Im saving a doc with sub-fields, but at
> retrieve point with index and query i wont get the expected resutls. I
> need the list to show two rows one for the account "Ahorro" another
> one for the account "Corriente" but only one row show, the first one.
>
> can anyone help me?
>
> Here i post my code:
>
> UbuntuListView {
>         id: accountListView
>         anchors.margins: units.gu <http://units.gu>(2)
>         anchors.top: accountLabel.bottom
>         anchors.left: parent.left
>         anchors.right: parent.right
>         anchors.bottom: parent.bottom
>         model: accountQuery
>         delegate: ListItem.SingleValue {
>             text: contents["name"]
>             progression: true
>             onClicked: {
>                 print("clicked")
>             }
>         }
>     }
>     U1db.Database {
>         id: myMoneyDB
>         path: "MyMoney.u1db"
>     }
>     U1db.Document {
>         id: accountDocument
>         database: myMoneyDB
>         docId: 'account'
>         create: true
>         defaults: {
>             [
>                 {
>                     "name": "Ahorro"
>                 },
>                 {
>                     "name": "Corriente"
>                 }
>             ]
>         }
>     }
>     U1db.Index{
>         database: myMoneyDB
>         id: accountIndex
>         expression: ["account.name <http://account.name>"]
>     }
>     U1db.Query{
>         id: accountQuery
>         index: accountIndex
>         query: "*"
>     }
> Thanks in advance.
> S.U.C.C.E.S.S
> Success is a journey, not a destination.
> Ing. Yasmany Cubela Medina:
> Linux user 446757
> Ubuntu user 13464
>
>
>

import QtQuick 2.0
import Ubuntu.Components 1.1
import Ubuntu.Components.ListItems 1.0 as ListItem
import U1db 1.0 as U1db

MainView {
    width: units.gu(40)
    height: units.gu(60)

    Label {
        id: accountLabel
    }

    UbuntuListView {
        id: accountListView
        anchors.margins: units.gu(2)
        anchors.top: accountLabel.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        model: accountQuery

        delegate: ListItem.SingleValue {
            text: contents["name"]
            progression: true
            onClicked: print("clicked")
        }
    }

    U1db.Database {
        id: myMoneyDB
    }

    U1db.Document {
        database: myMoneyDB
        docId: 'now'
        create: true
        defaults: {
            "name": "Ahorro"
        }
    }

    U1db.Document {
        database: myMoneyDB
        docId: 'current'
        create: true
        defaults: {
            "name": "Corriente"
        }
    }

    U1db.Index {
        database: myMoneyDB
        id: accountIndex
        expression: ["name"]
    }

    U1db.Query {
        id: accountQuery
        index: accountIndex
        query: "*"
    }
}

Attachment: signature.asc
Description: OpenPGP digital signature


References