mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
mongo.sort
This commit is contained in:
@@ -396,16 +396,21 @@ function mongo_collection:find(query, selector)
|
||||
} , cursor_meta)
|
||||
end
|
||||
|
||||
local function unfold(list, key, ...)
|
||||
if key == nil then
|
||||
return list
|
||||
end
|
||||
local next_func, t = pairs(key)
|
||||
local k, v = next_func(t) -- The first key pair
|
||||
table.insert(list, k)
|
||||
table.insert(list, v)
|
||||
return unfold(list, ...)
|
||||
end
|
||||
|
||||
-- cursor:sort { key = 1 } or cursor:sort( {key1 = 1}, {key2 = -1})
|
||||
function mongo_cursor:sort(key, key_v, ...)
|
||||
if key_v then
|
||||
local key_list = {}
|
||||
for _, kp in ipairs {key, key_v, ...} do
|
||||
local next_func, t = pairs(kp)
|
||||
local k, v = next_func(t, v) -- The first key pair
|
||||
table.insert(key_list, k)
|
||||
table.insert(key_list, v)
|
||||
end
|
||||
local key_list = unfold({}, key, key_v , ...)
|
||||
key = bson_encode_order(table.unpack(key_list))
|
||||
end
|
||||
self.__sortquery = bson_encode {['$query'] = self.__query, ['$orderby'] = key}
|
||||
|
||||
@@ -158,7 +158,7 @@ local function dispatch_by_order(self)
|
||||
local func, co = pop_response(self)
|
||||
if not co then
|
||||
-- close signal
|
||||
wakeup_all(self, errmsg)
|
||||
wakeup_all(self, "channel_closed")
|
||||
break
|
||||
end
|
||||
local ok, result_ok, result_data, padding = pcall(func, self.__sock)
|
||||
|
||||
Reference in New Issue
Block a user