nv-pg-jrow-ir-cond-back
install
- npm install nv-pg-jrow-ir-cond-back
usage
const {creat_cond_sql} = require("nv-pg-jrow-ir-cond-back")
var [cond,reason] = creat_cond_sql(cd,hint,scheme,_parser)
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
a:[ //non_leaf a : [c1,c2,c3,c4,c5,c6]
'float8', //leaf c1 a.0
'text', //leaf c2 a.1
{ //non_leaf a.2: [c3,c4]
dina_k0:'text', //leaf c3 a.2.dina_k0
dina_k1:'text', //leaf c4 a.2.dina_k1
},
'int4', //leaf c5 a.3
'json' //leaf c6 a.4
],
dd: { //non_leaf d : [c7,c8,c9,c10,c11]
k0:'int8', //leaf c7 d.k0
k1:'buf', //leaf c8 d.k1
aind: [ //non_leaf d.aind : [c9,c10,c11]
'text', //leaf c9 a.aind.0
'text', //leaf c10 a.aind.1
'json' //leaf c11 a.aind.2
]
}
}
var scheme = _scheme.creat(jcfg).scheme;
var front = {
cd: ' to_i32(JPL0) === 555 && c3 === "ttxxtt" && JPL1 === JLIT0 || c6 !== JLIT1 || c5 > 8 || str_includes(c9, "ssss") || !to_bl(to_i32(c1))',
hint: {
jpl: { JPL0: [ 'extra', 'x' ], JPL1: [ 'c11', 'x', 1, '2', 'x' ] },
jlit: {
JLIT0: '{"m":1,"n":2}',
JLIT1: '[1,{"m":888},2,[{"n":[5,6,7]}]]'
}
}
}
var cd = front.cd;
var hint = front.hint
const {creat_cond_sql} = require("nv-pg-jrow-ir-cond-back")
var [cond,reason] = creat_cond_sql(cd,hint,scheme,_parser)
console.log(cond,reason)
/*
true
((((((((((extra->'x')::jsonb)::INT4) = 555) AND (c3 = 'ttxxtt')) AND (((c11->'x'->1->2->'x')::jsonb) = ('{"m":1,"n":2}'::JSONB))) OR (c6 != ('[1,{"m":888},2,[{"n":[5,6,7]}]]'::JSONB))) OR (c5 > 8)) OR (strpos(c9,'ssss')>0)) OR NOT(((c1::INT4)::BOOL)))
postgres=# SELECT * FROM jrow_test0 WHERE ((((((((((extra->'x')::jsonb)::INT4) = 555) AND (c3 = 'ttxxtt')) AND (((c11->'x'->1->2->'x')::jsonb) = ('{"m":1,"n":2}'::JSONB))) OR (c6 != ('[1,{"m":888},2,[{"n":[5,6,7]}]]'::JSONB))) OR (c5 > 8)) OR (strpos(c9,'ssss')>0)) OR NOT(((c1::INT4)::BOOL)));
extra | c3 | c11 | c6 | c5 | c9 | c1
------------+--------+------------------------------------------------+----------------------------------------+----+------+-------
{"x": 555} | ttxxtt | {"x": [0, [0, 1, {"x": {"m": 1, "n": 2}}], 2]} | | | |
{"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]} | [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
(4 rows)
*/
METHODS
APIS
{
_ir: {
expr: {
'!': [Function: !],
'&&': [Function: &&],
'||': [Function: ||],
'===': [Function: ===],
'!==': [Function: !==],
'>': [Function: >],
'>=': [Function: >=],
'<': [Function: <],
'<=': [Function: <=]
},
builtin: { str_includes: [Function: str_includes] },
cast: {
to_json: [Function: to_json],
to_str: [Function: to_str],
to_bl: [Function: to_bl],
to_i16: [Function: to_i16],
to_i32: [Function: to_i32],
to_i64: [Function: to_i64],
to_f32: [Function: to_f32],
to_f64: [Function: to_f64]
},
jsonb: { to_pg_jk: [Function: to_pg_jk], fmt_jpl: [Function: fmt_jpl] }
},
_vali: {
hint: { fmt: [Function: fmt] },
nd: {
SUPPORTED_ND_TYPS: [Array],
ERRD: [Object],
_bin: [Function: _bin],
_params: [Function: _params],
check_and_handle: [Function: check_and_handle]
}
},
creat_cond_sql: [Function: creat_cond_sql]
}
LICENSE