Results from U1db.Query contain only indexed fields, not the whole document
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
U1DB Qt/ QML |
Confirmed
|
High
|
Unassigned | ||
u1db-qt (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
Whe using U1db.Index and U1db.Query to query information from a U1db, the results returned from a Query should be the entire document, and instead they are a subset of the document containing only the indexed fields.
Example code below. Observe that the left-hand ListView is showing results, but those results are not the whole content of each document; instead, they contain only the fields in the index. Index queries should return the whole document. Otherwise queries are almost useless; they are designed so that you can get a list of the documents which match the query fields, not just the query fields which match the query fields. Returning the value of the fields which match the query is pointless: you must already know those values in order to construct the query in the first place.
import QtQuick 2.0
import U1db 1.0 as U1db
Rectangle {
width: 600
height: 300
U1db.Database { id: db; path: "u1db-broken-
U1db.Document {
database: db; docId: "doc1"; create: true
defaults: { "topfield": { "subfield": "subvalue1" }, "toplevelfield": "topvalue1" }
}
U1db.Document {
database: db; docId: "doc2"; create: true
defaults: { "topfield": { "subfield": "subvalue2" }, "toplevelfield": "topvalue2" }
}
U1db.Index {
database: db
id: by_topfield_
expression: ["topfield.
}
U1db.Index {
database: db
id: by_toplevelfield
expression: ["toplevelfield
}
U1db.Query { id: qtopsub; index: by_topfield_
U1db.Query { id: qtoplevel; index: by_toplevelfield; query: [{toplevelfield: "*"}] }
Text {
id: h1
width: parent.width / 2
height: 50
text: "ListModel on topfield.subfield"
}
ListView {
width: h1.width
model: qtopsub
delegate: Text {
text: JSON.stringify(
}
}
Text {
id: h2
width: parent.width / 2
height: 50
text: "ListModel on toplevelfield"
}
ListView {
width: h2.width
model: qtoplevel
delegate: Text {
text: JSON.stringify(
}
}
}
Related branches
- PS Jenkins bot: Approve (continuous-integration)
- Benjamin Zeller: Approve
-
Diff: 25 lines (+3/-1)2 files modifiedsrc/query.cpp (+1/-1)
tests/tst_query.qml (+2/-0)
Changed in u1db-qt: | |
importance: | Undecided → Medium |
status: | New → Confirmed |
Changed in u1db-qt: | |
status: | Fix Committed → Confirmed |
milestone: | none → 1.0 |
tags: | added: devexp |
Changed in u1db-qt (Ubuntu): | |
status: | Confirmed → Fix Committed |
Changed in u1db-qt: | |
status: | Confirmed → Fix Committed |
status: | Fix Committed → Confirmed |
Changed in u1db-qt (Ubuntu): | |
status: | Fix Committed → Confirmed |
Changed in u1db-qt: | |
importance: | Medium → High |
Fix committed into lp:u1db-qt at revision 113, scheduled for release in u1db-qt, milestone 1.0