gpt4 book ai didi

go - 如何在Scylla和Go中查询带偏移量的限制

转载 作者:行者123 更新时间:2023-12-01 20:03:23 25 4
gpt4 key购买 nike

使用gocqlgocqlx,没有获取第n页的示例:

CREATE TABLE IF NOT EXISTS users (
id BIGINT, -- unique using distributed synchronous counter (redis-like), since Scylla doesn't support RETURNING on counter
email TEXT, -- to enforce uniqueness
PRIMARY KEY(email)
);
CREATE INDEX IF NOT EXISTS ON users(id);

查询功能:
func QueryRows(cql string) (res []M.SX) { // M.SX is map[string]interface{}
q := Database.Query(cql) // database is the connection to scylla
defer q.Release()
res = []M.SX{}
iter := q.Iter()
for {
row := M.SX{}
if !iter.MapScan(row) {
break
}
res = append(res, row)
}
return
}

要获取第n页(按 ALLOW FILTERINGemail排序),是否容易但性能良好(没有 id)?
SELECT * FROM users WHERE id > 44 LIMIT 10 ALLOW FILTERING; 
-- eg. 44 is last id of current page

最佳答案

嗨,您尝试过基于 token 的分页吗?

来自scylladb/gocqlx的示例

https://github.com/scylladb/gocqlx/blob/master/example_test.go#L168

关于go - 如何在Scylla和Go中查询带偏移量的限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59555835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com