1.0.4 • Published 1 year ago
nv-pg-jrow-ir-order-by-back v1.0.4
nv-pg-jrow-ir-order-by-back
install
- npm install nv-pg-jrow-ir-order-by-back
usage
const {creat_order_by_sql} = require("nv-pg-jrow-ir-order-by-back");
example
const _parser = require("/mnt/sdb/JS/BUSINESS-LIB_/PG/nv-pg-jrow/pkgs/nv-pg-jrow-back")._parser;
const unparse_func = _parser.unparse;
const _scheme = require("/mnt/sdb/JS/BUSINESS-LIB_/PG/nv-pg-jrow/pkgs/nv-pg-jrow-scheme");
var jcfg = { //non_leaf '': [c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11]
ss:'text', //leaf c0 s
aa:[ //non_leaf aa : [c1,c2,c3,c4,c5,c6]
'float8', //leaf c1 aa.0
'text', //leaf c2 aa.1
{ //non_leaf aa.2: [c3,c4]
dina_k0:'text', //leaf c3 aa.2.dina_k0
dina_k1:'text', //leaf c4 aa.2.dina_k1
},
'int4', //leaf c5 aa.3
'json' //leaf c6 aa.4
],
dd: { //non_leaf dd : [c7,c8,c9,c10,c11]
k0:'int8', //leaf c7 dd.k0
k1:'buf', //leaf c8 dd.k1
aind: [ //non_leaf dd.aind : [c9,c10,c11]
'text', //leaf c9 dd.aind.0
'text', //leaf c10 dd.aind.1
'json' //leaf c11 dd.aind.2
]
}
}
var scheme = _scheme.creat(jcfg).scheme;
var front = {
cd: [
'JPL0', 'DESC', 'JPL1',
'ASC', 'c3', 'ASC',
'JPL2', 'DESC', 'JPL3',
'ASC', 'c6', 'ASC',
'c5', 'ASC', 'c9',
'DESC', 'c1', 'ASC'
],
hint: Hint {
jpl: {
JPL0: [ 'extra', 'x' ],
JPL1: [ 'extra', 'y' ],
JPL2: [ 'c11', 'x', 1, '2', 'x' ],
JPL3: [ 'c11', 'int' ]
},
jlit: {}
}
}
var cd = front.cd;
var hint = front.hint
var [cond,reason] = creat_order_by_sql(cd,hint,scheme)
console.log(cond,reason)
/*
true ((extra->'x')::jsonb) DESC , ((extra->'y')::jsonb) ASC , c3 ASC , ((c11->'x'->1->2->'x')::jsonb) DESC , ((c11->'int')::jsonb) ASC , c6 ASC , c5 ASC , c9 DESC , c1 ASC
postgres=# select * from jrow_test0 ORDER BY ((extra->'x')::jsonb) DESC , ((extra->'y')::jsonb) ASC , c3 ASC , ((c11->'x'->1->2->'x')::jsonb) DESC , ((c11->'int')::jsonb) ASC , c6 ASC , c5 ASC , c9 DESC , c1 ASC;
extra | c3 | c11 | c6 | c5 | c9 | c1
------------+--------+------------------------------------------------+----------------------------------------+----+------+-------
{"x": 555} | ttxxtt | | | | |
{"x": 555} | ttxxtt | {"x": [0, [0, 1, {"x": {"m": 1, "n": 2}}], 2]} | [1, {"m": 888}, 2, [{"n": [5, 6, 7]}]] | 7 | |
{"x": 555} | ttxxtt | {"x": [0, [0, 1, {"x": {"m": 1, "n": 2}}], 2]} | [1, {"m": 888}, 2, [{"n": [5, 6, 7]}]] | 7 | aass | 3.888
{"x": 555} | ttxxtt | {"x": [0, [0, 1, {"x": {"m": 1, "n": 2}}], 2]} | [1, {"m": 888}, 2, [{"n": [5, 6, 7]}]] | 7 | aass | 3.888
{"x": 555} | ttxxtt | {"x": [0, [0, 1, {"x": {"m": 1, "n": 2}}], 2]} | [1, {"m": 888}, 2, [{"n": [5, 6, 7]}]] | 7 | aass | 3.888
{"x": 555} | ttxxtt | {"x": [0, [0, 1, {"x": {"m": 1, "n": 2}}], 2]} | [1, {"m": 888}, 2, [{"n": [5, 6, 7]}]] | 7 | aass | 3.888
{"x": 555} | ttxxtt | {"x": [0, [0, 1, {"x": {"m": 1, "n": 2}}], 2]} | [1, {"m": 888}, 2, [{"n": [5, 6, 7]}]] | | |
{"x": 555} | ttxxtt | {"x": [0, [0, 1, {"x": {"m": 1, "n": 2}}], 2]} | | | |
{"x": 555} | | | | | |
(9 rows)
postgres=#
*/
METHODS
APIS
{
ERRD: { cd_must_be_ary: 'cd_must_be_ary' },
_ir: { nv_as: [Function: nv_as] },
_vali: {
ERRD: { ele_of_cd_must_be_str: 'ele_of_cd_must_be_str' },
check_and_handle: [Function: check_and_handle]
},
creat_order_by_sql: [Function: creat_order-by_sql]
}
LICENSE
- ISC