本文整理汇总了Golang中github.com/luci/gae/service/datastore.FinalizedQuery.Original方法的典型用法代码示例。如果您正苦于以下问题:Golang FinalizedQuery.Original方法的具体用法?Golang FinalizedQuery.Original怎么用?Golang FinalizedQuery.Original使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/luci/gae/service/datastore.FinalizedQuery
的用法示例。
在下文中一共展示了FinalizedQuery.Original方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: countQuery
func countQuery(fq *ds.FinalizedQuery, aid, ns string, isTxn bool, idx, head *memStore) (ret int64, err error) {
if len(fq.Project()) == 0 && !fq.KeysOnly() {
fq, err = fq.Original().KeysOnly(true).Finalize()
if err != nil {
return
}
}
err = executeQuery(fq, aid, ns, isTxn, idx, head, func(_ *ds.Key, _ ds.PropertyMap, _ ds.CursorCB) error {
ret++
return nil
})
return
}
示例2: Count
func (d *dsTxnBuf) Count(fq *ds.FinalizedQuery) (count int64, err error) {
// Unfortunately there's no fast-path here. We literally have to run the
// query and count. Fortunately we can optimize to count keys if it's not
// a projection query. This will save on bandwidth a bit.
if len(fq.Project()) == 0 && !fq.KeysOnly() {
fq, err = fq.Original().KeysOnly(true).Finalize()
if err != nil {
return
}
}
err = d.Run(fq, func(_ *ds.Key, _ ds.PropertyMap, _ ds.CursorCB) error {
count++
return nil
})
return
}
示例3: adjustQuery
// adjustQuery applies various mutations to the query to make it suitable for
// merging. In general, this removes limits and offsets the 'distinct' modifier,
// and it ensures that if there are sort orders which won't appear in the
// result data that the query is transformed into a projection query which
// contains all of the data. A non-projection query will never be transformed
// in this way.
func adjustQuery(fq *ds.FinalizedQuery) (*ds.FinalizedQuery, error) {
q := fq.Original()
// The limit and offset must be done in-memory because otherwise we may
// request too few entities from the underlying store if many matching
// entities have been deleted in the buffered transaction.
q = q.Limit(-1)
q = q.Offset(-1)
// distinction must be done in-memory, because otherwise there's no way
// to merge in the effect of the in-flight changes (because there's no way
// to push back to the datastore "yeah, I know you told me that the (1, 2)
// result came from `/Bob,1`, but would you mind pretending that it didn't
// and tell me next the one instead?
q = q.Distinct(false)
// since we need to merge results, we must have all order-related fields
// in each result. The only time we wouldn't have all the data available would
// be for a keys-only or projection query. To fix this, we convert all
// Projection and KeysOnly queries to project on /all/ Orders.
//
// FinalizedQuery already guarantees that all projected fields show up in
// the Orders, but the projected fields could be a subset of the orders.
//
// Additionally on a keys-only query, any orders other than __key__ require
// conversion of this query to a projection query including those orders in
// order to merge the results correctly.
//
// In both cases, the resulting objects returned to the higher layers of the
// stack will only include the information requested by the user; keys-only
// queries will discard all PropertyMap data, and projection queries will
// discard any field data that the user didn't ask for.
orders := fq.Orders()
if len(fq.Project()) > 0 || (fq.KeysOnly() && len(orders) > 1) {
q = q.KeysOnly(false)
for _, o := range orders {
if o.Property == "__key__" {
continue
}
q = q.Project(o.Property)
}
}
return q.Finalize()
}