UNPKG

lite-ui-sql-parser

Version:
1 lines 585 kB
!function(){var r=function(r){var t;return function(n){return t||r(t={exports:{},parent:n},t.exports),t.exports}},t=r(function(r,t){!function(r,e){if("function"==typeof define&&define.amd)define(["exports","./union"],e);else if(void 0!==t)e(t,n({}));else{var u={exports:{}};e(u.exports,r.union),r.sql=u.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=function(r){return Array.isArray(r)?(r.forEach(e),(0,t.multipleToSQL)(r)):(e(r),(0,t.unionToSQL)(r))};const n=["select","delete","update","insert","drop","rename","truncate","call","use","alter","set","create","lock","unlock"];function e(r){const t=r&&r.ast?r.ast:r;if(!n.includes(t.type))throw new Error(`${t.type} statements not supported at the moment`)}})}),n=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./create","./alter","./select","./delete","./update","./insert","./command"],n);else if(void 0!==t)n(t,i({}),E({}),l({}),s({}),o({}),u({}),e({}));else{var a={exports:{}};n(a.exports,r.create,r.alter,r.select,r._delete,r.update,r.insert,r.command),r.union=a.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e,u,o,s,i){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.unionToSQL=c,r.multipleToSQL=function(r){const t=[];for(let n=0,e=r.length;n<e;++n){let e=r[n]&&r[n].ast;e||(e=r[n]),t.push(c(e))}return t.join(" ; ")};const a={alter:n.alterToSQL,create:t.createToSQL,select:e.selectToSQL,delete:u.deleteToSQL,update:o.updateToSQL,insert:s.insertToSQL,drop:i.dropToSQL,truncate:i.truncateToSQL,use:i.useToSQL,rename:i.renameToSQL,call:i.callToSQL,set:i.setVarToSQL,lock:i.lockUnlockToSQL,unlock:i.lockUnlockToSQL};function c(r){const t=a[r.type],n=[t(r)];for(;r._next;){const e=(r.union||"union").toUpperCase();n.push(e,t(r._next)),r=r._next}return n.join(" ")}})}),e=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./util","./expr","./tables"],n);else if(void 0!==t)n(t,T({}),f({}),y({}));else{var e={exports:{}};n(e.exports,r.util,r.expr,r.tables),r.command=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.dropToSQL=function(r){return["DROP TABLE",(0,e.tablesToSQL)(r.table)].join(" ")},r.truncateToSQL=function(r){return["TRUNCATE",r.keyword,(0,e.tablesToSQL)(r.table)].filter(t.hasVal).join(" ")},r.renameToSQL=function(r){const{type:t,table:n}=r,u=[],o=`${t&&t.toUpperCase()} TABLE`;if(n)for(const s of n){const r=s.map(e.tableToSQL);u.push(r.join(" TO "))}return`${o} ${u.join(", ")}`},r.useToSQL=function(r){const{type:n,db:e}=r;return`${n&&n.toUpperCase()} ${(0,t.identifierToSql)(e)}`},r.callToSQL=function(r){return`CALL ${(0,n.exprToSQL)(r.expr)}`},r.setVarToSQL=function(r){const{expr:t}=r;return`SET ${(0,n.exprToSQL)(t)}`},r.lockUnlockToSQL=function(r){const{type:n,keyword:u,tables:o}=r,s=[n.toUpperCase(),(0,t.toUpper)(u)];if("UNLOCK"===n.toUpperCase())return s.join(" ");const i=[];for(const a of o){const{table:r,lock_type:n}=a,u=[(0,e.tableToSQL)(r)];if(n){const r=["prefix","type","suffix"];u.push(r.map(r=>(0,t.toUpper)(n[r])).filter(t.hasVal).join(" "))}i.push(u.join(" "))}return s.push(i.join(", "),...function(r){const{lock_mode:t,nowait:n}=r,e=[];if(t){const{mode:r}=t;e.push(r.toUpperCase())}return n&&e.push(n.toUpperCase()),e}(r)),s.filter(t.hasVal).join(" ")}})}),u=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./tables","./expr","./util","./select"],n);else if(void 0!==t)n(t,y({}),f({}),T({}),l({}));else{var e={exports:{}};n(e.exports,r.tables,r.expr,r.util,r.select),r.insert=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e,u){"use strict";function o(r){return"select"===r.type?(0,u.selectToSQL)(r):`(${r.map(n.exprToSQL).join("),(")})`}function s(r){if(!r)return"";const t=["PARTITION","("];if(Array.isArray(r))t.push(r.map(e.identifierToSql).join(", "));else{const{value:e}=r;t.push(e.map(n.exprToSQL).join(", "))}return t.push(")"),t.filter(e.hasVal).join("")}Object.defineProperty(r,"__esModule",{value:!0}),r.insertToSQL=function(r){const{table:u,prefix:i="into",columns:a,values:c,where:f,partition:l,returning:v}=r,b=["INSERT",(0,e.toUpper)(i),(0,t.tablesToSQL)(u),s(l)];return Array.isArray(a)&&b.push(`(${a.map(e.identifierToSql).join(", ")})`),b.push((0,e.commonOptionConnector)(Array.isArray(c)?"VALUES":"",o,c)),b.push((0,e.commonOptionConnector)("WHERE",n.exprToSQL,f)),b.push((0,e.returningToSQL)(v)),b.filter(e.hasVal).join(" ")}})}),o=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./tables","./expr","./util"],n);else if(void 0!==t)n(t,y({}),f({}),T({}));else{var e={exports:{}};n(e.exports,r.tables,r.expr,r.util),r.update=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e){"use strict";function u(r){if(!r||0===r.length)return"";const t=[];for(const u of r){let r="";const{table:o,column:s,value:i}=u;r=[o,s].filter(e.hasVal).map(r=>(0,e.identifierToSql)(r)).join("."),i&&(r=`${r} = ${(0,n.exprToSQL)(i)}`),t.push(r)}return t.join(", ")}Object.defineProperty(r,"__esModule",{value:!0}),r.updateToSQL=function(r){const{table:o,set:s,where:i,returning:a}=r;return["UPDATE",(0,t.tablesToSQL)(o),(0,e.commonOptionConnector)("SET",u,s),(0,e.commonOptionConnector)("WHERE",n.exprToSQL,i),(0,e.returningToSQL)(a)].filter(e.hasVal).join(" ")}})}),s=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./column","./tables","./expr","./util"],n);else if(void 0!==t)n(t,c({}),y({}),f({}),T({}));else{var e={exports:{}};n(e.exports,r.column,r.tables,r.expr,r.util),r._delete=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e,u){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.deleteToSQL=function(r){const o=["DELETE"],{columns:s,from:i,table:a,where:c}=r,f=(0,t.columnsToSQL)(s,i);return o.push(f),Array.isArray(a)&&(1===a.length&&!0===a[0].addition||o.push((0,n.tablesToSQL)(a))),o.push((0,u.commonOptionConnector)("FROM",n.tablesToSQL,i)),o.push((0,u.commonOptionConnector)("WHERE",e.exprToSQL,c)),o.filter(u.hasVal).join(" ")}})}),i=r(function(r,t){!function(r,e){if("function"==typeof define&&define.amd)define(["exports","./index-definition","./column","./constrain","./tables","./union","./util"],e);else if(void 0!==t)e(t,A({}),c({}),a({}),y({}),n({}),T({}));else{var u={exports:{}};e(u.exports,r.indexDefinition,r.column,r.constrain,r.tables,r.union,r.util),r.create=u.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e,u,o,s){"use strict";function i(r){if(!r)return[];const{resource:u}=r;switch(u){case"column":return(0,n.columnDefinitionToSQL)(r);case"index":return(0,t.indexDefinitionToSQL)(r);case"constraint":return(0,e.constraintDefinitionToSQL)(r);default:throw new Error(`unknow resource = ${u} type`)}}Object.defineProperty(r,"__esModule",{value:!0}),r.createToSQL=function(r){const{type:t,keyword:n,table:e,like:a,as:c,temporary:f,if_not_exists:l,create_definitions:v,table_options:b,ignore_replace:p,query_expr:d}=r,L=[(0,s.toUpper)(t),(0,s.toUpper)(f),(0,s.toUpper)(n),(0,s.toUpper)(l),(0,u.tablesToSQL)(e)];if(a){const{type:r,table:t}=a,n=(0,u.tablesToSQL)(t);return L.push((0,s.toUpper)(r),n),L.filter(s.hasVal).join(" ")}return v&&L.push(`(${v.map(i).join(", ")})`),b&&L.push(b.map(u.tableOptionToSQL).join(" ")),L.push((0,s.toUpper)(p),(0,s.toUpper)(c)),d&&L.push((0,o.unionToSQL)(d)),L.filter(s.hasVal).join(" ")}})}),a=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./util","./index-definition","./column"],n);else if(void 0!==t)n(t,T({}),A({}),c({}));else{var e={exports:{}};n(e.exports,r.util,r.indexDefinition,r.column),r.constrain=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.constraintDefinitionToSQL=function(r){const{constraint:u,constraint_type:o,index:s,keyword:i,reference_definition:a}=r,c=[];return c.push((0,t.toUpper)(i)),c.push(u),c.push((0,t.toUpper)(o)),c.push((0,t.identifierToSql)(s)),c.push(...(0,n.indexTypeAndOptionToSQL)(r)),c.push(...(0,e.columnReferenceDefinitionToSQL)(a)),c.filter(t.hasVal).join(" ")}})}),c=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./expr","./tables","./util"],n);else if(void 0!==t)n(t,f({}),y({}),T({}));else{var e={exports:{}};n(e.exports,r.expr,r.tables,r.util),r.column=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e){"use strict";function u(r){const{dataType:t,length:n,suffix:u,scale:o}=r||{};let s=t;return n&&(s+=`(${[n,o].filter(e.hasVal).join(", ")})`),u&&u.length&&(s+=` ${u.join(" ")}`),s}function o(r){const t=[];if(!r)return t;const{definition:u,keyword:o,match:s,table:i,on_delete:a,on_update:c}=r;return t.push(o.toUpperCase()),t.push((0,n.tablesToSQL)(i)),t.push(`(${u.map(e.identifierToSql).join(", ")})`),t.push((0,e.toUpper)(s)),t.push(...(0,e.commonTypeValue)(a)),t.push(...(0,e.commonTypeValue)(c)),t.filter(e.hasVal)}Object.defineProperty(r,"__esModule",{value:!0}),r.columnDefinitionToSQL=function(r){const n=[],s=(0,e.columnRefToSQL)(r.column),i=u(r.definition);n.push(s),n.push(i);const a=function(r){const n=[],{nullable:u,comment:s,collate:i,storage:a,default_val:c,auto_increment:f,unique_or_primary:l,column_format:v,reference_definition:b}=r;if(n.push((0,e.toUpper)(u&&u.value)),c){const{type:r,value:e}=c;n.push(r.toUpperCase(),(0,t.exprToSQL)(e))}return n.push((0,e.toUpper)(f),(0,e.toUpper)(l),(0,e.commentToSQL)(s)),n.push(...(0,e.commonTypeValue)(i)),n.push(...(0,e.commonTypeValue)(v)),n.push(...(0,e.commonTypeValue)(a)),n.push(...o(b)),n.filter(e.hasVal).join(" ")}(r);return n.push(a),n.filter(e.hasVal).join(" ")},r.columnsToSQL=function(r,n){if(!r)return;if("*"===r)return r;const u=Array.isArray(n)&&n[0];let o=!1;return u&&"dual"===u.type&&(o=!0),r.map(r=>{const{expr:n}=r;o&&(n.isDual=o);let u=(0,t.exprToSQL)(n);return null!==r.as&&(u=`${u} AS `,u=r.as.match(/^[a-z_][0-9a-z_]*$/i)?`${u}${(0,e.identifierToSql)(r.as)}`:`${u}\`${r.as}\``),u}).join(", ")},r.columnDataType=u,r.columnReferenceDefinitionToSQL=o})}),f=r(function(r,t){!function(r,e){if("function"==typeof define&&define.amd)define(["exports","./util","./alter","./aggregation","./assign","./binary","./case","./func","./interval","./select","./union"],e);else if(void 0!==t)e(t,T({}),E({}),h({}),C({}),L({}),d({}),p({}),b({}),l({}),n({}));else{var u={exports:{}};e(u.exports,r.util,r.alter,r.aggregation,r.assign,r.binary,r._case,r.func,r.interval,r.select,r.union),r.expr=u.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e,u,o,s,i,a,c,f){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.exprToSQL=b,r.getExprListSQL=p,r.varToSQL=v,r.orderOrPartitionByToSQL=function(r,n){if(!Array.isArray(r))return"";let e=[];const u=(0,t.toUpper)(n);switch(u){case"ORDER BY":e=r.map(r=>`${b(r.expr)} ${r.type}`);break;case"PARTITION BY":default:e=r.map(r=>`${(0,t.columnRefToSQL)(r.expr)}`)}return(0,t.connector)(u,e.join(", "))},r.exprToSQLConvertFn=void 0;const l={alter:n.alterExprToSQL,aggr_func:e.aggrToSQL,assign:u.assignToSQL,binary_expr:o.binaryToSQL,case:s.caseToSQL,cast:i.castToSQL,column_ref:t.columnRefToSQL,function:i.funcToSQL,interval:a.intervalToSQL};function v(r){const{prefix:t="@",name:n,members:e,keyword:u}=r,o=[];u&&o.push(u);const s=e&&e.length>0?`${n}.${e.join(".")}`:n;return o.push(`${t||""}${s}`),o.join(" ")}function b(r){const n=r;if(r.ast){const{ast:r}=n;Reflect.deleteProperty(n,r);for(const t of Object.keys(r))n[t]=r[t]}return l[n.type]?l[n.type](n):(0,t.literalToSQL)(n)}function p(r){return r?r.map(b):[]}r.exprToSQLConvertFn=l,l.var=v,l.expr_list=(r=>{const t=p(r.value);return r.parentheses?`(${t})`:t}),l.select=(r=>{const t="object"==typeof r._next?(0,f.unionToSQL)(r):(0,c.selectToSQL)(r);return r.parentheses?`(${t})`:t}),l.unary_expr=function(r){const t=`${r.operator} ${b(r.expr)}`;return r.parentheses?`(${t})`:t}})}),l=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./expr","./column","./with","./tables","./util"],n);else if(void 0!==t)n(t,f({}),c({}),v({}),y({}),T({}));else{var e={exports:{}};n(e.exports,r.expr,r.column,r._with,r.tables,r.util),r.select=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e,u,o){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.selectToSQL=function(r){const{with:s,options:i,distinct:a,columns:c,from:f,where:l,groupby:v,having:b,orderby:p,limit:d,top:L}=r,C=[(0,e.withToSql)(s),"SELECT"];if(C.push((0,o.topToSQL)(L)),Array.isArray(i)&&C.push(i.join(" ")),C.push(a,(0,n.columnsToSQL)(c,f)),C.push((0,o.commonOptionConnector)("FROM",u.tablesToSQL,f)),C.push((0,o.commonOptionConnector)("WHERE",t.exprToSQL,l)),C.push((0,o.connector)("GROUP BY",(0,t.getExprListSQL)(v).join(", "))),C.push((0,o.commonOptionConnector)("HAVING",t.exprToSQL,b)),C.push((0,t.orderOrPartitionByToSQL)(p,"order by")),d){const{seperator:r,value:n}=d;C.push((0,o.connector)("LIMIT",n.map(t.exprToSQL).join(`${"offset"===r?" ":""}${r.toUpperCase()} `)))}return C.filter(o.hasVal).join(" ")}})}),v=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./expr"],n);else if(void 0!==t)n(t,f({}));else{var e={exports:{}};n(e.exports,r.expr),r._with=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.withToSql=function(r){if(!r||0===r.length)return;return`WITH ${r[0].recursive?"RECURSIVE ":""}${r.map(r=>{return`${`"${r.name}"`}${Array.isArray(r.columns)?`(${r.columns.join(", ")})`:""} AS (${(0,t.exprToSQL)(r.stmt)})`}).join(", ")}`}})}),b=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./util","./expr"],n);else if(void 0!==t)n(t,T({}),f({}));else{var e={exports:{}};n(e.exports,r.util,r.expr),r.interval=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.intervalToSQL=function(r){const{expr:e,unit:u}=r;return`INTERVAL ${(0,n.exprToSQL)(e)} ${(0,t.toUpper)(u)}`}})}),p=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./expr","./util","./over"],n);else if(void 0!==t)n(t,f({}),T({}),w({}));else{var e={exports:{}};n(e.exports,r.expr,r.util,r.over),r.func=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.castToSQL=function(r){const{target:n,expr:e,symbol:u}=r,{length:o,dataType:s,parentheses:i,scale:a}=n;let c="";o&&(c=a?`${o}, ${a}`:o),i&&(c=`(${c})`);let f=(0,t.exprToSQL)(e),l="::",v="";return"as"===u&&(f=`CAST(${f}`,v=")",l=` ${u.toUpperCase()} `),`${f}${l}${s}${c}${v}`},r.funcToSQL=function(r){const{args:u,name:o}=r;if(!u)return o;const{parentheses:s,over:i}=r,a=`${o}(${(0,t.exprToSQL)(u).join(", ")})`;return[s?`(${a})`:a,(0,e.overToSQL)(i)].filter(n.hasVal).join(" ")}})}),d=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./expr"],n);else if(void 0!==t)n(t,f({}));else{var e={exports:{}};n(e.exports,r.expr),r._case=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.caseToSQL=function(r){const n=["CASE"],e=r.args;r.expr&&n.push((0,t.exprToSQL)(r.expr));for(let u=0,o=e.length;u<o;++u)n.push(e[u].type.toUpperCase()),e[u].cond&&(n.push((0,t.exprToSQL)(e[u].cond)),n.push("THEN")),n.push((0,t.exprToSQL)(e[u].result));return n.push("END"),n.join(" ")}})}),L=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./expr"],n);else if(void 0!==t)n(t,f({}));else{var e={exports:{}};n(e.exports,r.expr),r.binary=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.binaryToSQL=function(r){let{operator:n}=r,e=(0,t.exprToSQL)(r.right),u=!1;if(Array.isArray(e)){switch(n){case"=":n="IN";break;case"!=":n="NOT IN";break;case"BETWEEN":case"NOT BETWEEN":u=!0,e=`${e[0]} AND ${e[1]}`}u||(e=`(${e.join(", ")})`)}const o=`${(0,t.exprToSQL)(r.left)} ${n} ${e}`;return r.parentheses?`(${o})`:o}})}),C=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./expr"],n);else if(void 0!==t)n(t,f({}));else{var e={exports:{}};n(e.exports,r.expr),r.assign=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.assignToSQL=function(r){const{left:n,right:e,symbol:u,keyword:o}=r;return n.keyword=o,`${(0,t.exprToSQL)(n)} ${u} ${(0,t.exprToSQL)(e)}`}})}),h=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./expr","./util","./over"],n);else if(void 0!==t)n(t,f({}),T({}),w({}));else{var e={exports:{}};n(e.exports,r.expr,r.util,r.over),r.aggregation=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.aggrToSQL=function(r){const{args:u,over:o}=r;let s=(0,t.exprToSQL)(u.expr);const i=r.name,a=(0,e.overToSQL)(o);return"COUNT"===i&&u.distinct&&(s=`DISTINCT ${s}`),[`${i}(${s})`,a].filter(n.hasVal).join(" ")}})}),w=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./util","./expr"],n);else if(void 0!==t)n(t,T({}),f({}));else{var e={exports:{}};n(e.exports,r.util,r.expr),r.over=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.overToSQL=function(r){if(!r)return;const{partitionby:e,orderby:u}=r;return`OVER (${[(0,n.orderOrPartitionByToSQL)(e,"partition by"),(0,n.orderOrPartitionByToSQL)(u,"order by")].filter(t.hasVal).join(" ")})`}})}),E=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./column","./index-definition","./tables","./expr","./util"],n);else if(void 0!==t)n(t,c({}),A({}),y({}),f({}),T({}));else{var e={exports:{}};n(e.exports,r.column,r.indexDefinition,r.tables,r.expr,r.util),r.alter=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n,e,u,o){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.alterToSQL=function(r){const{type:t,table:n,expr:s=[]}=r;return[(0,o.toUpper)(t),"TABLE",(0,e.tablesToSQL)(n),s.map(u.exprToSQL).join(", ")].filter(o.hasVal).join(" ")},r.alterExprToSQL=function(r){const{action:e,if_not_exists:u,keyword:s,resource:i}=r,a=(0,o.toUpper)(e),c=(0,o.toUpper)(s),f=(0,o.toUpper)(u);let l="",v="";switch(i){case"column":v=(0,t.columnDefinitionToSQL)(r);break;case"index":v=(v=(0,n.indexTypeAndOptionToSQL)(r)).filter(o.hasVal).join(" "),l=r[i];break;case"table":l=(0,o.identifierToSql)(r[i]);break;case"algorithm":case"lock":l=`= ${r[i]}`}const b=[a];return b.push(c),b.push(f),b.push(l),b.push(v),b.filter(o.hasVal).join(" ")}})}),y=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./util","./expr"],n);else if(void 0!==t)n(t,T({}),f({}));else{var e={exports:{}};n(e.exports,r.util,r.expr),r.tables=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t,n){"use strict";function e(r){const{table:e,db:u,as:o,expr:s}=r,i=(0,t.identifierToSql)(u),a=e?(0,t.identifierToSql)(e):(0,n.exprToSQL)(s),c=i?`${i}.${a}`:a;return o?`${c} AS ${(0,t.identifierToSql)(o)}`:c}Object.defineProperty(r,"__esModule",{value:!0}),r.tablesToSQL=function(r){const u=r[0],o=[];if("dual"===u.type)return"DUAL";o.push(e(u));for(let s=1;s<r.length;++s){const u=r[s],{on:i,using:a,join:c}=u,f=[];f.push(c?` ${c}`:","),f.push(e(u)),f.push((0,t.commonOptionConnector)("ON",n.exprToSQL,i)),a&&f.push(`USING (${a.map(t.identifierToSql).join(", ")})`),o.push(f.filter(t.hasVal).join(" "))}return o.filter(t.hasVal).join("")},r.tableOptionToSQL=function(r){const{keyword:t,symbol:n,value:e}=r,u=[t.toUpperCase()];return n&&u.push(n),u.push(e),u.join(" ")},r.tableToSQL=e})}),A=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports","./util"],n);else if(void 0!==t)n(t,T({}));else{var e={exports:{}};n(e.exports,r.util),r.indexDefinition=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r,t){"use strict";function n(r){if(!r)return;const{keyword:t,type:n}=r;return`${t.toUpperCase()} ${n.toUpperCase()}`}function e(r){if(!r)return;const{type:e,expr:u,symbol:o}=r,s=e.toUpperCase(),i=[];switch(i.push(s),s){case"KEY_BLOCK_SIZE":o&&i.push(o),i.push((0,t.literalToSQL)(u));break;case"BTREE":case"HASH":i.length=0,i.push(n(r));break;case"WITH PARSER":i.push(u);break;case"VISIBLE":case"INVISIBLE":break;case"COMMENT":i.shift(),i.push((0,t.commentToSQL)(r))}return i.join(" ")}function u(r){const{index_type:u,index_options:o=[],definition:s}=r,i=[];return i.push(n(u)),s&&s.length&&i.push(`(${s.map(r=>(0,t.identifierToSql)(r)).join(", ")})`),i.push(o&&o.map(e).join(" ")),i}Object.defineProperty(r,"__esModule",{value:!0}),r.indexDefinitionToSQL=function(r){const n=[],{keyword:e,index:o}=r;return n.push((0,t.toUpper)(e)),n.push(o),n.push(...u(r)),n.filter(t.hasVal).join(" ")},r.indexTypeToSQL=n,r.indexOptionToSQL=e,r.indexTypeAndOptionToSQL=u})}),T=r(function(r,t){!function(r,n){if("function"==typeof define&&define.amd)define(["exports"],n);else if(void 0!==t)n(t);else{var e={exports:{}};n(e.exports),r.util=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.commonOptionConnector=function(r,t,n){if(n)return r?`${r.toUpperCase()} ${t(n)}`:t(n)},r.connector=function(r,t){if(t)return`${r.toUpperCase()} ${t}`},r.commonTypeValue=a,r.columnRefToSQL=c,r.commentToSQL=function(r){if(!r)return;const t=[],{keyword:n,symbol:e,value:u}=r;return t.push(n.toUpperCase()),e&&t.push(e),t.push(i(u)),t.join(" ")},r.createBinaryExpr=function(r,t,n){const e={operator:r,type:"binary_expr"};return e.left=t.type?t:u(t),"BETWEEN"===r||"NOT BETWEEN"===r?(e.right={type:"expr_list",value:[u(n[0]),u(n[1])]},e):(e.right=n.type?n:u(n),e)},r.createValueExpr=u,r.escape=o,r.literalToSQL=i,r.identifierToSql=s,r.replaceParams=function(r,t){return function r(t,n){return Object.keys(t).filter(r=>{const n=t[r];return Array.isArray(n)||"object"==typeof n&&null!==n}).forEach(e=>{const o=t[e];if("object"!=typeof o||"param"!==o.type)return r(o,n);if(void 0===n[o.value])throw new Error(`no value for parameter :${o.value} found`);return t[e]=u(n[o.value]),null}),t}(JSON.parse(JSON.stringify(r)),t)},r.returningToSQL=function(r){if(!r)return"";const{columns:t}=r;return["RETURNING",t.map(c).filter(f).join(", ")].join(" ")},r.hasVal=f,r.setParserOpt=function(r){e=r},r.toUpper=function(r){if(r)return r.toUpperCase()},r.topToSQL=function(r){if(!r)return;const{value:t,percent:n}=r,e=`TOP ${t}`;return n?`${e} ${n.toUpperCase()}`:e},r.DEFAULT_OPT=void 0;const t={"\0":"\\0","'":"\\'",'"':'\\"',"\b":"\\b","\n":"\\n","\r":"\\r","\t":"\\t","\x1a":"\\Z"},n={database:"mysql",type:"table"};r.DEFAULT_OPT=n;let e=n;function u(r){const t=typeof r;if(Array.isArray(r))return{type:"expr_list",value:r.map(u)};if(null===r)return{type:"null",value:null};switch(t){case"boolean":return{type:"bool",value:r};case"string":return{type:"string",value:r};case"number":return{type:"number",value:r};default:throw new Error(`Cannot convert value "${t}" to SQL`)}}function o(r){const n=[];for(let e=0,u=r.length;e<u;++e){let u=r[e];const o=t[u];o&&(u=o),n.push(u)}return n.join("")}function s(r,t){const{database:n}=e;if(!0===t)return`'${r}'`;if(r)switch(n&&n.toLowerCase()){case"mysql":case"mariadb":return`\`${r}\``;case"postgresql":return`"${r}"`;case"transactsql":return`[${r}]`;default:return`\`${r}\``}}function i(r){const{type:t,parentheses:n,value:e}=r;let u=e;switch(t){case"string":u=`'${o(e)}'`;break;case"boolean":case"bool":u=e?"TRUE":"FALSE";break;case"null":u="NULL";break;case"star":u="*";break;case"param":u=`:${e}`;break;case"origin":u=e.toUpperCase();break;case"time":case"date":case"timestamp":u=`${t.toUpperCase()} '${e}'`}return n?`(${u})`:u}function a(r){const t=[];if(!r)return t;const{type:n,value:e}=r;return t.push(n.toUpperCase()),t.push(e.toUpperCase()),t}function c(r){const{arrow:t,collate:n,column:e,isDual:u,table:o,parentheses:i,property:c}=r;let f="*"===e?"*":s(e,u);return o&&(f=`${s(o)}.${f}`),t&&(f+=` ${t} '${c}'`),n&&(f+=` ${a(n).join(" ")}`),i?`(${f})`:f}function f(r){return r}})}),m=r(function(r,t){var n;n=function(r){"use strict";function t(r,n,e,u){this.message=r,this.expected=n,this.found=e,this.location=u,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}return function(r,t){function n(){this.constructor=r}n.prototype=t.prototype,r.prototype=new n}(t,Error),t.buildMessage=function(r,t){var n={literal:function(r){return'"'+u(r.text)+'"'},class:function(r){var t,n="";for(t=0;t<r.parts.length;t++)n+=r.parts[t]instanceof Array?o(r.parts[t][0])+"-"+o(r.parts[t][1]):o(r.parts[t]);return"["+(r.inverted?"^":"")+n+"]"},any:function(r){return"any character"},end:function(r){return"end of input"},other:function(r){return r.description}};function e(r){return r.charCodeAt(0).toString(16).toUpperCase()}function u(r){return r.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(r){return"\\x0"+e(r)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(r){return"\\x"+e(r)})}function o(r){return r.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(r){return"\\x0"+e(r)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(r){return"\\x"+e(r)})}return"Expected "+function(r){var t,e,u,o=new Array(r.length);for(t=0;t<r.length;t++)o[t]=(u=r[t],n[u.type](u));if(o.sort(),o.length>0){for(t=1,e=1;t<o.length;t++)o[t-1]!==o[t]&&(o[e]=o[t],e++);o.length=e}switch(o.length){case 1:return o[0];case 2:return o[0]+" or "+o[1];default:return o.slice(0,-1).join(", ")+", or "+o[o.length-1]}}(r)+" but "+function(r){return r?'"'+u(r)+'"':"end of input"}(t)+" found."},{SyntaxError:t,parse:function(n,e){e=void 0!==e?e:{};var u,o={},s={start:db},i=db,a=function(r,t){const n=[r&&r.ast||r];for(let e=0;e<t.length;e++)t[e][3]&&0!==t[e][3].length&&n.push(t[e][3]&&t[e][3].ast||t[e][3]);return{tableList:Array.from(yL),columnList:wL(AL),ast:n}},c=function(r,t){let n=r;for(let e=0;e<t.length;e++)n._next=t[e][5],n.union=t[e][3]?"union all":"union",n=n._next;return{tableList:Array.from(yL),columnList:wL(AL),ast:r}},f=function(r,t,n,e,u,o,s,i,a){return e&&e.forEach(r=>yL.add(`create::${r.db}::${r.table}`)),{tableList:Array.from(yL),columnList:wL(AL),ast:{type:r[0].toLowerCase(),keyword:"table",temporary:t&&t[0].toLowerCase(),if_not_exists:n&&n[0].toLowerCase(),table:e,ignore_replace:s&&s[0].toLowerCase(),as:i&&i[0].toLowerCase(),query_expr:a&&a.ast,create_definitions:u,table_options:o}}},l=function(r,t,n,e,u){return e&&e.forEach(r=>yL.add(`create::${r.db}::${r.table}`)),{tableList:Array.from(yL),columnList:wL(AL),ast:{type:r[0].toLowerCase(),keyword:"table",temporary:t&&t[0].toLowerCase(),if_not_exists:n&&n[0].toLowerCase(),table:e,like:u}}},v=function(r){return{type:"like",table:r}},b=function(r){return r.parentheses=!0,r},p=function(r,t){return CL(r,t)},d="auto_increment",L=fb("AUTO_INCREMENT",!0),C="unique",h=fb("UNIQUE",!0),w="primary",E=fb("PRIMARY",!0),y="key",A=fb("KEY",!0),T=function(r,t,n,e,u,o,s,i,a,c,f){return AL.add(`create::${r.table}::${r.column}`),n&&!n.value&&(n.value="null"),{column:r,definition:t,nullable:n,default_val:e,auto_increment:u&&u.toLowerCase(),unique_or_primary:o&&`${o[0].toLowerCase()} ${o[2].toLowerCase()}`,comment:s,collate:i,column_format:a,storage:c,reference_definition:f,resource:"column"}},m=function(r){return{type:"collate",value:r}},S="column_format",g=fb("COLUMN_FORMAT",!0),N="fixed",I=fb("FIXED",!0),R="dynamic",_=fb("DYNAMIC",!0),x="default",O=fb("DEFAULT",!0),U=function(r,t){return{type:"column_format",value:t.toLowerCase()}},M="storage",$=fb("STORAGE",!0),D="disk",k=fb("DISK",!0),P="memory",F=fb("MEMORY",!0),j=function(r,t){return{type:"storage",value:t.toLowerCase()}},H=function(r){return{type:"default",value:r}},B=function(r,t){return t&&t.forEach(t=>yL.add(`${r}::${t.db}::${t.table}`)),{tableList:Array.from(yL),columnList:wL(AL),ast:{type:r.toLowerCase(),table:t}}},Q=function(r,t,n){return n&&n.forEach(t=>yL.add(`${r}::${t.db}::${t.table}`)),{tableList:Array.from(yL),columnList:wL(AL),ast:{type:r.toLowerCase(),keyword:t,table:n}}},G=function(r){return yL.add(`use::${r}::null`),{tableList:Array.from(yL),columnList:wL(AL),ast:{type:"use",db:r}}},Y=function(r,t){return r&&r.length>0&&r.forEach(r=>yL.add(`alter::${r.db}::${r.table}`)),{tableList:Array.from(yL),columnList:wL(AL),ast:{type:"alter",table:r,expr:t}}},V=function(r,t){return{action:"add",...t,keyword:r,resource:"column",type:"alter"}},q=function(r,t){return{action:"drop",column:t,keyword:r,resource:"column",type:"alter"}},X=function(r){return{action:"add",type:"alter",...r}},W=function(r,t){return{action:"rename",type:"alter",resource:"table",keyword:r&&r[0].toLowerCase(),table:t}},Z="algorithm",K=fb("ALGORITHM",!0),J="instant",z=fb("INSTANT",!0),rr="inplace",tr=fb("INPLACE",!0),nr="copy",er=fb("COPY",!0),ur=function(r){return{type:"alter",keyword:"algorithm",resource:"algorithm",algorithm:r}},or="lock",sr=fb("LOCK",!0),ir="none",ar=fb("NONE",!0),cr="shared",fr=fb("SHARED",!0),lr="exclusive",vr=fb("EXCLUSIVE",!0),br=function(r){return{type:"alter",keyword:"lock",resource:"lock",lock:r}},pr=function(r,t,n,e,u){return{index:t,definition:e,keyword:r.toLowerCase(),index_type:n,resource:"index",index_options:u}},dr=function(r,t,n,e,u){return{index:n,definition:e,keyword:t&&`${r.toLowerCase()} ${t.toLowerCase()}`||r.toLowerCase(),index_options:u,resource:"index"}},Lr=function(r,t){return{keyword:r.toLowerCase(),constraint:t}},Cr="primary key",hr=fb("PRIMARY KEY",!0),wr=function(r,t,n,e,u){return{constraint:r&&r.constraint,definition:e,constraint_type:t.toLowerCase(),keyword:r&&r.keyword,index_type:n,resource:"constraint",index_options:u}},Er=function(r,t,n,e,u,o,s){return{constraint:r&&r.constraint,definition:o,constraint_type:n&&`${t.toLowerCase()} ${n.toLowerCase()}`||t.toLowerCase(),keyword:r&&r.keyword,index_type:u,index:e,resource:"constraint",index_options:s}},yr="foreign key",Ar=fb("FOREIGN KEY",!0),Tr=function(r,t,n,e,u){return{constraint:r&&r.constraint,definition:e,constraint_type:t,keyword:r&&r.keyword,index:n,resource:"constraint",reference_definition:u}},mr="match full",Sr=fb("MATCH FULL",!0),gr="match partial",Nr=fb("MATCH PARTIAL",!0),Ir="match simple",Rr=fb("MATCH SIMPLE",!0),_r=function(r,t,n,e,u,o){return{definition:n,table:t,keyword:r.toLowerCase(),match:e&&e.toLowerCase(),on_delete:u,on_update:o}},xr="on delete",Or=fb("ON DELETE",!0),Ur="on update",Mr=fb("ON UPDATE",!0),$r=function(r,t){return{type:r.toLowerCase(),value:t}},Dr="restrict",kr=fb("RESTRICT",!0),Pr="cascade",Fr=fb("CASCADE",!0),jr="set null",Hr=fb("SET NULL",!0),Br="no action",Qr=fb("NO ACTION",!0),Gr="set default",Yr=fb("SET DEFAULT",!0),Vr=function(r){return r.toLowerCase()},qr=function(r,t){return CL(r,t)},Xr="avg_row_length",Wr=fb("AVG_ROW_LENGTH",!0),Zr="key_block_size",Kr=fb("KEY_BLOCK_SIZE",!0),Jr="max_rows",zr=fb("MAX_ROWS",!0),rt="min_rows",tt=fb("MIN_ROWS",!0),nt="stats_sample_pages",et=fb("STATS_SAMPLE_PAGES",!0),ut=function(r,t,n){return{keyword:r.toLowerCase(),symbol:t,value:n.value}},ot="character set",st=fb("CHARACTER SET",!0),it="charset",at=fb("CHARSET",!0),ct="collate",ft=fb("COLLATE",!0),lt=function(r,t,n,e){return{keyword:r&&`${r[0].toLowerCase()} ${t.toLowerCase()}`||t.toLowerCase(),symbol:n,value:e}},vt="connection",bt=fb("CONNECTION",!0),pt=function(r,t,n){return{keyword:r.toLowerCase(),symbol:t,value:`'${n.value}'`}},dt="compression",Lt=fb("COMPRESSION",!0),Ct="'",ht=fb("'",!1),wt="zlib",Et=fb("ZLIB",!0),yt="lz4",At=fb("LZ4",!0),Tt=function(r,t,n){return{keyword:r.toLowerCase(),symbol:t,value:n.join("").toUpperCase()}},mt="engine",St=fb("ENGINE",!0),gt=function(r,t,n){return{keyword:r.toLowerCase(),symbol:t,value:n.toUpperCase()}},Nt=function(r){return{action:"add",type:"alter",...r}},It=function(r){return r.forEach(r=>r.forEach(r=>r.table&&yL.add(`rename::${r.db}::${r.table}`))),{tableList:Array.from(yL),columnList:wL(AL),ast:{type:"rename",table:r}}},Rt=function(r,t){return t.keyword=r,{tableList:Array.from(yL),columnList:wL(AL),ast:{type:"set",expr:t}}},_t=function(){return{tableList:Array.from(yL),columnList:wL(AL),ast:{type:"unlock",keyword:"tables"}}},xt="read",Ot=fb("READ",!0),Ut="local",Mt=fb("LOCAL",!0),$t=function(r){return{type:"read",suffix:r&&"local"}},Dt="low_priority",kt=fb("LOW_PRIORITY",!0),Pt="write",Ft=fb("WRITE",!0),jt=function(r){return{type:"write",prefix:r&&"low_priority"}},Ht=function(r,t){return yL.add(`lock::${r.db}::${r.table}`),{table:r,lock_type:t}},Bt=function(r,t){return CL(r,t)},Qt=function(r){return{tableList:Array.from(yL),columnList:wL(AL),ast:{type:"lock",keyword:"tables",tables:r}}},Gt=function(r){return{tableList:Array.from(yL),columnList:wL(AL),ast:{type:"call",expr:r}}},Yt="(",Vt=fb("(",!1),qt=")",Xt=fb(")",!1),Wt=function(r){return r[2]},Zt=function(r){return r.recursive=!0,[r]},Kt=function(r,t,n){return{name:r,stmt:n,columns:t}},Jt=function(r,t,n,e,u,o,s,i,a,c,f){return o&&o.forEach(r=>r.table&&yL.add(`select::${r.db}::${r.table}`)),{with:r,type:"select",options:t,distinct:e,columns:u,from:o,where:s,groupby:i,having:a,top:n,orderby:c,limit:f}},zt="percent",rn=fb("PERCENT",!0),tn=function(r,t){return{value:r,percent:t&&t.toLowerCase()}},nn=function(r,t){const n=[r];for(let e=0,u=t.length;e<u;++e)n.push(t[e][1]);return n},en=function(r){return r},un=function(r,t){return AL.add("select::null::(.*)"),t&&t.length>0?(r[0]={expr:{type:"column_ref",table:null,column:"*"},as:null},CL(r[0],t)):r[0]},on=function(r){return AL.add(`select::${r}::(.*)`),{expr:{type:"column_ref",table:r,column:"*"},as:null}},sn=function(r,t){return{expr:r,as:t}},an=function(r){return r},cn=function(r){return r},fn=function(r,t){return[r,t]},ln="btree",vn=fb("BTREE",!0),bn="hash",pn=fb("HASH",!0),dn=function(r){return{keyword:"using",type:r.toLowerCase()}},Ln=function(r,t){const n=[r];for(let e=0;e<t.length;e++)n.push(t[e][1]);return n},Cn=function(r,t,n){return{type:r.toLowerCase(),symbol:t,expr:n}},hn="with",wn=fb("WITH",!0),En="parser",yn=fb("PARSER",!0),An=function(r){return{type:"with parser",expr:r}},Tn="visible",mn=fb("VISIBLE",!0),Sn="invisible",gn=fb("INVISIBLE",!0),Nn=function(r){return{type:r.toLowerCase(),expr:r.toLowerCase()}},In=function(r,t){return t.unshift(r),t.forEach(r=>{const{table:t,as:n}=r;TL[t]=t,n&&(TL[n]=t)}),t},Rn=function(r){return r},_n=function(r,t,n,e){return t.join=r,t.using=CL(n,e),t},xn=function(r,t,n){return t.join=r,t.on=n,t},On=function(r,t,n,e){return t.parentheses=!0,{expr:t,as:n,join:r,on:e}},Un=function(){return{type:"dual"}},Mn=function(r,t){return"var"===r.type?(r.as=t,r):{db:r.db,table:r.table,as:t}},$n=function(r,t){return r.parentheses=!0,{expr:r,as:t}},Dn=function(){return"LEFT JOIN"},kn=function(){return"RIGHT JOIN"},Pn=function(){return"FULL JOIN"},Fn=function(){return"INNER JOIN"},jn=function(r,t,n){const e={db:null,table:r};return null!==n&&(e.db=`${r}.${t[3]}`,e.table=n[3]),e},Hn=function(r,t){const n={db:null,table:r};return null!==t&&(n.db=r,n.table=t[3]),n},Bn=function(r){return r.db=null,r.table=r.name,r},Qn=function(r){return r},Gn=function(r){return r.value},Yn=function(r,t){const n={expr:r,type:"ASC"};return"DESC"===t&&(n.type="DESC"),n},Vn=function(r,t){const n=[r];return t&&n.push(t[2]),{seperator:t&&t[0]&&t[0].toLowerCase()||"",value:n}},qn=function(r,t,n){return r&&r.forEach(r=>{const{db:t,as:n,table:e}=r;yL.add(`update::${t}::${e}`)}),t&&t.forEach(r=>AL.add(`update::${r.table}::${r.column}`)),{tableList:Array.from(yL),columnList:wL(AL),ast:{type:"update",table:r,set:t,where:n}}},Xn=function(r,t,n){if(t&&t.forEach(r=>{r.table&&yL.add(`delete::${r.db}::${r.table}`),AL.add(`delete::${r.table}::(.*)`)}),null===r&&1===t.length){const n=t[0];r=[{db:n.db,table:n.table,as:n.as,addition:!0}]}return{tableList:Array.from(yL),columnList:wL(AL),ast:{type:"delete",table:r,from:t,where:n}}},Wn="=",Zn=fb("=",!1),Kn=function(r,t,n){return{column:t,value:n,table:r&&r[0]}},Jn=function(r,t){return CL(r,t)},zn=function(r){return r},re=function(r,t,n,e,u){if(t&&(yL.add(`insert::${t.db}::${t.table}`),t.as=null),e){let r=t&&t.table||null;e.forEach(t=>AL.add(`insert::${r}::${t}`))}return{tableList:Array.from(yL),columnList:wL(AL),ast:{type:r,table:[t],columns:e,values:u,partition:n}}},te=function(r,t,n,e){return t&&(yL.add(`insert::${t.db}::${t.table}`),AL.add(`insert::${t.table}::(.*)`),t.as=null),{tableList:Array.from(yL),columnList:wL(AL),ast:{type:r,table:[t],columns:null,values:e,partition:n}}},ne=function(){return"insert"},ee=function(){return"replace"},ue=function(r){return r},oe=function(r,t){const n={type:"expr_list"};return n.value=CL(r,t),n},se=function(r,t){return{type:"interval",expr:r,unit:t.toLowerCase()}},ie=function(r,t,n){return n&&t.push(n),{type:"case",expr:r||null,args:t}},ae=function(r,t){return{type:"when",cond:r,result:t}},ce=function(r){return{type:"else",result:r}},fe=function(r,t){return hL(r,t)},le=function(r,t){return pL(r,t[0][1])},ve=function(r,t){return hL(r,t)},be="!",pe=fb("!",!1),de=function(r){return pL("NOT",r)},Le=function(r,t){return null===t?r:"arithmetic"===t.type?hL(r,t.tail):dL(t.op,r,t.right)},Ce=function(r,t){return t.parentheses=!0,pL(r,t)},he=function(r){return r[0]+" "+r[2]},we=function(r){return{type:"arithmetic",tail:r}},Ee=">=",ye=fb(">=",!1),Ae=">",Te=fb(">",!1),me="<=",Se=fb("<=",!1),ge="<>",Ne=fb("<>",!1),Ie="<",Re=fb("<",!1),_e="!=",xe=fb("!=",!1),Oe=function(r){return{op:"IS",right:r}},Ue=function(r){return{op:"IS NOT",right:r}},Me=function(r,t,n){return{op:r,right:{type:"expr_list",value:[t,n]}}},$e=function(r,t){return{op:r,right:t}},De=function(r,t){return{op:r,right:t}},ke=function(r,t){return{op:r,right:t}},Pe="+",Fe=fb("+",!1),je="-",He=fb("-",!1),Be=function(r,t){return hL(r,t)},Qe="*",Ge=fb("*",!1),Ye="/",Ve=fb("/",!1),qe="%",Xe=fb("%",!1),We=function(r){return r.parentheses=!0,r},Ze=function(r){return r.parentheses=!0,r},Ke=function(r,t){return AL.add(`select::${r}::${t}`),{type:"column_ref",table:r,column:t}},Je=function(r){return AL.add(`select::null::${r}`),{type:"column_ref",table:null,column:r}},ze=function(r){return!0===bL[r.toUpperCase()]},ru=function(r){return r},tu=function(r){if(!0===bL[r.toUpperCase()])throw new Error("Error: "+JSON.stringify(r)+" is a reserved word, can not as alias clause");return!1},nu='"',eu=fb('"',!1),uu=/^[^"]/,ou=lb(['"'],!0,!1),su=function(r){return r.join("")},iu=/^[^']/,au=lb(["'"],!0,!1),cu="`",fu=fb("`",!1),lu=/^[^`]/,vu=lb(["`"],!0,!1),bu=function(r){return r},pu=function(r,t){return r+t.join("")},du=/^[A-Za-z_]/,Lu=lb([["A","Z"],["a","z"],"_"],!1,!1),Cu=/^[A-Za-z0-9_]/,hu=lb([["A","Z"],["a","z"],["0","9"],"_"],!1,!1),wu=/^[A-Za-z0-9_:]/,Eu=lb([["A","Z"],["a","z"],["0","9"],"_",":"],!1,!1),yu=":",Au=fb(":",!1),Tu=function(r){return{type:"param",value:r[1]}},mu=function(r,t){return{type:"aggr_func",name:r,args:{expr:t}}},Su=function(r,t){return{partitionby:r,orderby:t}},gu=function(r,t,n){return{type:"aggr_func",name:r,args:t,over:n}},Nu=function(r,t){return{type:"aggr_func",name:r,args:t}},Iu=function(r){return{expr:r}},Ru=function(r,t){return{distinct:r,expr:t}},_u=function(){return{type:"star",value:"*"}},xu=function(r,t,n){return{type:"function",name:r,args:t||{type:"expr_list",value:[]},over:n}},Ou=function(r,t){return{type:"function",name:r,args:t||{type:"expr_list",value:[]}}},Uu=function(r){return{type:"function",name:r,args:{type:"expr_list",value:[]}}},Mu=function(r,t){return{type:"cast",expr:r,symbol:"as",target:t}},$u=function(r,t){return{type:"cast",expr:r,symbol:"as",target:{dataType:"DECIMAL("+t+")"}}},Du=function(r,t,n){return{type:"cast",expr:r,symbol:"as",target:{dataType:"DECIMAL("+t+", "+n+")"}}},ku=function(r,t,n){return{type:"cast",expr:r,symbol:"as",target:{dataType:t+(n?" "+n:"")}}},Pu=function(){return{type:"null",value:null}},Fu=function(){return{type:"not null",value:"not null"}},ju=function(){return{type:"bool",value:!0}},Hu=function(){return{type:"bool",value:!1}},Bu=function(r){return{type:"string",value:r[1].join("")}},Qu=function(r,t){return{type:r.toLowerCase(),value:t[1].join("")}},Gu=function(r,t,n){if(t&&n)return!0},Yu="on update current_timestamp",Vu=fb("ON UPDATE CURRENT_TIMESTAMP",!0),qu=function(r,t,n,e){return{type:"origin",value:(e?`${r} ${e}`:r).toLowerCase()}},Xu=/^[^"\\\0-\x1F\x7F]/,Wu=lb(['"',"\\",["\0","\x1f"],"\x7f"],!0,!1),Zu=/^[^'\\]/,Ku=lb(["'","\\"],!0,!1),Ju="\\'",zu=fb("\\'",!1),ro=function(){return"'"},to='\\"',no=fb('\\"',!1),eo=function(){return'"'},uo="\\\\",oo=fb("\\\\",!1),so=function(){return"\\"},io="\\/",ao=fb("\\/",!1),co=function(){return"/"},fo="\\b",lo=fb("\\b",!1),vo=function(){return"\b"},bo="\\f",po=fb("\\f",!1),Lo=function(){return"\f"},Co="\\n",ho=fb("\\n",!1),wo=function(){return"\n"},Eo="\\r",yo=fb("\\r",!1),Ao=function(){return"\r"},To="\\t",mo=fb("\\t",!1),So=function(){return"\t"},go="\\u",No=fb("\\u",!1),Io=function(r,t,n,e){return String.fromCharCode(parseInt("0x"+r+t+n+e))},Ro="\\",_o=fb("\\",!1),xo=/^[\n\r]/,Oo=lb(["\n","\r"],!1,!1),Uo=function(r){return r&&"bigint"===r.type?r:{type:"number",value:r}},Mo=function(r,t,n){return{type:"bigint",value:r+t+n}},$o=function(r,t){const n=r+t;return LL(r)?{type:"bigint",value:n}:parseFloat(n)},Do=function(r,t){return{type:"bigint",value:r+t}},ko=function(r){return LL(r)?{type:"bigint",value:r}:parseFloat(r)},Po=function(r,t){return"-"+t},Fo=function(r,t){return"-"+t},jo=".",Ho=fb(".",!1),Bo=function(r){return"."+r},Qo=function(r,t){return r+t},Go=function(r){return r.join("")},Yo=/^[0-9]/,Vo=lb([["0","9"]],!1,!1),qo=/^[0-9a-fA-F]/,Xo=lb([["0","9"],["a","f"],["A","F"]],!1,!1),Wo=/^[eE]/,Zo=lb(["e","E"],!1,!1),Ko=/^[+\-]/,Jo=lb(["+","-"],!1,!1),zo=function(r,t){return r+(null!==t?t:"")},rs="null",ts=fb("NULL",!0),ns="not null",es=fb("NOT NULL",!0),us="true",os=fb("TRUE",!0),ss="to",is=fb("TO",!0),as="top",cs=fb("TOP",!0),fs="false",ls=fb("FALSE",!0),vs=(fb("SHOW",!0),"drop"),bs=fb("DROP",!0),ps=function(){return"DROP"},ds="use",Ls=fb("USE",!0),Cs="alter",hs=fb("ALTER",!0),ws="select",Es=fb("SELECT",!0),ys="update",As=fb("UPDATE",!0),Ts="create",ms=fb("CREATE",!0),Ss="temporary",gs=fb("TEMPORARY",!0),Ns="if not exists",Is=fb("IF NOT EXISTS",!0),Rs="delete",_s=fb("DELETE",!0),xs="insert",Os=fb("INSERT",!0),Us="RECURSIVE",Ms=fb("RECURSIVE",!1),$s="replace",Ds=fb("REPLACE",!0),ks="rename",Ps=fb("RENAME",!0),Fs="ignore",js=fb("IGNORE",!0),Hs=(fb("EXPLAIN",!0),"partition"),Bs=fb("PARTITION",!0),Qs=function(){return"PARTITION"},Gs="into",Ys=fb("INTO",!0),Vs="from",qs=fb("FROM",!0),Xs="set",Ws=fb("SET",!0),Zs="unlock",Ks=fb("UNLOCK",!0),Js="as",zs=fb("AS",!0),ri="table",ti=fb("TABLE",!0),ni=function(){return"TABLE"},ei="tables",ui=fb("TABLES",!0),oi=function(){return"TABLES"},si=function(){return"COLLATE"},ii="on",ai=fb("ON",!0),ci="left",fi=fb("LEFT",!0),li="right",vi=fb("RIGHT",!0),bi="full",pi=fb("FULL",!0),di="inner",Li=fb("INNER",!0),Ci="join",hi=fb("JOIN",!0),wi="outer",Ei=fb("OUTER",!0),yi="over",Ai=fb("OVER",!0),Ti="union",mi=fb("UNION",!0),Si="values",gi=fb("VALUES",!0),Ni="using",Ii=fb("USING",!0),Ri="where",_i=fb("WHERE",!0),xi="group",Oi=fb("GROUP",!0),Ui="by",Mi=fb("BY",!0),$i="order",Di=fb("ORDER",!0),ki="having",Pi=fb("HAVING",!0),Fi="limit",ji=fb("LIMIT",!0),Hi="offset",Bi=fb("OFFSET",!0),Qi=function(){return"OFFSET"},Gi="asc",Yi=fb("ASC",!0),Vi=function(){return"ASC"},qi="desc",Xi=fb("DESC",!0),Wi=function(){return"DESC"},Zi="all",Ki=fb("ALL",!0),Ji=function(){return"ALL"},zi="distinct",ra=fb("DISTINCT",!0),ta=function(){return"DISTINCT"},na="between",ea=fb("BETWEEN",!0),ua=function(){return"BETWEEN"},oa="in",sa=fb("IN",!0),ia=function(){return"IN"},aa="is",ca=fb("IS",!0),fa=function(){return"IS"},la="like",va=fb("LIKE",!0),ba=function(){return"LIKE"},pa="exists",da=fb("EXISTS",!0),La=function(){return"EXISTS"},Ca="not",ha=fb("NOT",!0),wa=function(){return"NOT"},Ea="and",ya=fb("AND",!0),Aa=function(){return"AND"},Ta="or",ma=fb("OR",!0),Sa=function(){return"OR"},ga="count",Na=fb("COUNT",!0),Ia=function(){return"COUNT"},Ra="max",_a=fb("MAX",!0),xa=function(){return"MAX"},Oa="min",Ua=fb("MIN",!0),Ma=function(){return"MIN"},$a="sum",Da=fb("SUM",!0),ka=function(){return"SUM"},Pa="avg",Fa=fb("AVG",!0),ja=function(){return"AVG"},Ha="call",Ba=fb("CALL",!0),Qa=function(){return"CALL"},Ga="case",Ya=fb("CASE",!0),Va="when",qa=fb("WHEN",!0),Xa="then",Wa=fb("THEN",!0),Za="else",Ka=fb("ELSE",!0),Ja="end",za=fb("END",!0),rc="cast",tc=fb("CAST",!0),nc="char",ec=fb("CHAR",!0),uc=function(){return"CHAR"},oc="varchar",sc=fb("VARCHAR",!0),ic=function(){return"VARCHAR"},ac="numeric",cc=fb("NUMERIC",!0),fc=function(){return"NUMERIC"},lc="decimal",vc=fb("DECIMAL",!0),bc=function(){return"DECIMAL"},pc="signed",dc=fb("SIGNED",!0),Lc=function(){return"SIGNED"},Cc="unsigned",hc=fb("UNSIGNED",!0),wc=function(){return"UNSIGNED"},Ec="int",yc=fb("INT",!0),Ac=function(){return"INT"},Tc="zerofill",mc=fb("ZEROFILL",!0),Sc=function(){return"ZEROFILL"},gc="integer",Nc=fb("INTEGER",!0),Ic=function(){return"INTEGER"},Rc="json",_c=fb("JSON",!0),xc=function(){return"JSON"},Oc="smallint",Uc=fb("SMALLINT",!0),Mc=function(){return"SMALLINT"},$c="tinyint",Dc=fb("TINYINT",!0),kc=function(){return"TINYINT"},Pc="tinytext",Fc=fb("TINYTEXT",!0),jc=function(){return"TINYTEXT"},Hc="text",Bc=fb("TEXT",!0),Qc=function(){return"TEXT"},Gc="mediumtext",Yc=fb("MEDIUMTEXT",!0),Vc=function(){return"MEDIUMTEXT"},qc="longtext",Xc=fb("LONGTEXT",!0),Wc=function(){return"LONGTEXT"},Zc="bigint",Kc=fb("BIGINT",!0),Jc=function(){return"BIGINT"},zc="float",rf=fb("FLOAT",!0),tf=function(){return"FLOAT"},nf="double",ef=fb("DOUBLE",!0),uf=function(){return"DOUBLE"},of="date",sf=fb("DATE",!0),af=function(){return"DATE"},cf="time",ff=fb("TIME",!0),lf=function(){return"TIME"},vf="timestamp",bf=fb("TIMESTAMP",!0),pf=function(){return"TIMESTAMP"},df="truncate",Lf=fb("TRUNCATE",!0),Cf=function(){return"TRUNCATE"},hf="user",wf=fb("USER",!0),Ef=function(){return"USER"},yf="current_date",Af=fb("CURRENT_DATE",!0),Tf=function(){return"CURRENT_DATE"},mf=(fb("ADDDATE",!0),"interval"),Sf=fb("INTERVAL",!0),gf=function(){return"INTERVAL"},Nf="year",If=fb("YEAR",!0),Rf=function(){return"YEAR"},_f="month",xf=fb("MONTH",!0),Of=function(){return"MONTH"},Uf="day",Mf=fb("DAY",!0),$f=function(){return"DAY"},Df="hour",kf=fb("HOUR",!0),Pf=function(){return"HOUR"},Ff="minute",jf=fb("MINUTE",!0),Hf=function(){return"MINUTE"},Bf="second",Qf=fb("SECOND",!0),Gf=function(){return"SECOND"},Yf="current_time",Vf=fb("CURRENT_TIME",!0),qf=function(){return"CURRENT_TIME"},Xf="current_timestamp",Wf=fb("CURRENT_TIMESTAMP",!0),Zf=function(){return"CURRENT_TIMESTAMP"},Kf="current_user",Jf=fb("CURRENT_USER",!0),zf=function(){return"CURRENT_USER"},rl="session_user",tl=fb("SESSION_USER",!0),nl=function(){return"SESSION_USER"},el="system_user",ul=fb("SYSTEM_USER",!0),ol=function(){return"SYSTEM_USER"},sl="global",il=fb("GLOBAL",!0),al=function(){return"GLOBAL"},cl="session",fl=fb("SESSION",!0),ll=function(){return"SESSION"},vl=function(){return"LOCAL"},bl="persist",pl=fb("PERSIST",!0),dl=function(){return"PERSIST"},Ll="persist_only",Cl=fb("PERSIST_ONLY",!0),hl=function(){return"PERSIST_ONLY"},wl="@",El=fb("@",!1),yl="@@",Al=fb("@@",!1),Tl="$",ml=fb("$",!1),Sl="return",gl=fb("return",!0),Nl=":=",Il=fb(":=",!1),Rl="dual",_l=fb("DUAL",!0),xl="add",Ol=fb("ADD",!0),Ul=function(){return"ADD"},Ml="column",$l=fb("COLUMN",!0),Dl=function(){return"COLUMN"},kl="index",Pl=fb("INDEX",!0),Fl=function(){return"INDEX"},jl=function(){return"KEY"},Hl="fulltext",Bl=fb("FULLTEXT",!0),Ql=function(){return"FULLTEXT"},Gl="spatial",Yl=fb("SPATIAL",!0),Vl=function(){return"SPATIAL"},ql=function(){return"UNIQUE"},Xl=function(){return"KEY_BLOCK_SIZE"},Wl="comment",Zl=fb("COMMENT",!0),Kl=function(){return"COMMENT"},Jl="constraint",zl=fb("CONSTRAINT",!0),rv=function(){return"CONSTRAINT"},tv="references",nv=fb("REFERENCES",!0),ev=function(){return"REFERENCES"},uv="sql_calc_found_rows",ov=fb("SQL_CALC_FOUND_ROWS",!0),sv="sql_cache",iv=fb("SQL_CACHE",!0),av="sql_no_cache",cv=fb("SQL_NO_CACHE",!0),fv="sql_small_result",lv=fb("SQL_SMALL_RESULT",!0),vv="sql_big_result",bv=fb("SQL_BIG_RESULT",!0),pv="sql_buffer_result",dv=fb("SQL_BUFFER_RESULT",!0),Lv=",",Cv=fb(",",!1),hv="[",wv=fb("[",!1),Ev="]",yv=fb("]",!1),Av=";",Tv=fb(";",!1),mv="||",Sv=fb("||",!1),gv="&&",Nv=fb("&&",!1),Iv="/*",Rv=fb("/*",!1),_v="*/",xv=fb("*/",!1),Ov="--",Uv=fb("--",!1),Mv="#",$v=fb("#",!1),Dv=function(r,t,n){return{type:r.toLowerCase(),keyword:r.toLowerCase(),symbol:t,value:n}},kv={type:"any"},Pv=/^[ \t\n\r]/,Fv=lb([" ","\t","\n","\r"],!1,!1),jv=function(){return EL=[],!0},Hv=f