From 49f691114317a3ef73d3bf4ef2bd264799ef3197 Mon Sep 17 00:00:00 2001 From: Bing Sun Date: Sun, 26 Apr 2020 17:16:43 +0800 Subject: [PATCH] make_model: support order --- src/util/make_model.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/util/make_model.js b/src/util/make_model.js index e167db2..145bf14 100644 --- a/src/util/make_model.js +++ b/src/util/make_model.js @@ -30,7 +30,8 @@ export default (options={}) => { endpoint: options.endpoint, endpoint_type: options.endpoint.startsWith('/rpc') ? 'function' : 'relation', // query part - selects: options.selects + selects: options.selects, + order: options.order } // private model cache & meta-info @@ -80,11 +81,24 @@ export default (options={}) => { queries: [ // transform model state to postgest queries //...ambient_queries, + // selects ...(_configs.selects ? [{ label: 'select', value: _configs.selects.map(select => select.alias ? select.alias + ':' + select.label : select.label).join(',') }] : []), + // order + ...(_configs.order ? [{ + label: 'order', + value: _configs.order + .map(o => [ + o.label, + o.direction, + o.nulls ? 'nulls'+o.nulls : '' + ].filter(a => a).join('.')) + .join(',') + }] : []), + // limit/offset offset == 0 ? undefined : {label: 'offset', value: offset}, limit == Infinity ? undefined : {label: 'limit', value: limit} @@ -133,7 +147,6 @@ export const default1 = (args) => { // private model configs let _configs = { queries: args.queries || [], - order: args.order || [] } return { // model & model state