couchdb-golang
couchdb-golang copied to clipboard
total rows with views
Hello, Thank you for this great library.
If the query is done directly on couchDB
http://localhost:5984/mydb/_design/myview/_view/all?limit=1
I get the total rows = 6 which is number of rows for that view regardless of the limit.
If the query is done via the library
option := map[string]interface{}{"limit": 1}
results, err := myDB.View("myview/all", nil, option)
results.TotalRows() // returns 1
I get the total rows = 1 which is number of rows returned constrained by the limit.
Is it possible to get number of rows regardless of the limit? As without this I wonder how paging could be done. Cheers
I see where it differs in design.go
vr.totalRows = len(rowsRaw)
it should be
json.Unmarshal(*jsonMap["total_rows"], &vr.totalRows)
@jcantonio Thank you for finding this bug, would you help me to fix it? : )
@leesper Sure, I will create a pull request. Thanks
@jcantonio Thank you very much, I really appreciate it!
Found an issue if you try to do a use View(...) on a document with a reduce function. The returned raw JSON payload i get from couchdb:
{"rows":[
{"key":null,"value":12937}
]}
which causes an panic in design.go:154 when it tries to deref *jsonMap["total_rows"]
var totalRows float64
json.Unmarshal(*jsonMap["total_rows"], &totalRows)
vr.totalRows = int(totalRows)
I'm not sure what a good fix would be except that having some null checks would avoid having the library panic. If I have the time, I will try to get back and figure out how to fix this issue is.
there's no tag which fixes this issue, but on last commit in master this issued fixed.
Workaround go get github.com/leesper/couchdb-golang@master