sumak 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +424 -51
- package/dist/_chunks/base.mjs +1 -1
- package/dist/_chunks/index.d.mts +31 -14
- package/dist/_chunks/mssql.d.mts +11 -0
- package/dist/_chunks/mssql.mjs +1 -0
- package/dist/_chunks/mysql.d.mts +2 -1
- package/dist/_chunks/mysql.mjs +1 -1
- package/dist/_chunks/pg.d.mts +1 -1
- package/dist/_chunks/sqlite.d.mts +2 -1
- package/dist/_chunks/sqlite.mjs +1 -1
- package/dist/_chunks/types.d.mts +68 -4
- package/dist/index.d.mts +265 -118
- package/dist/index.mjs +3 -3
- package/dist/mssql.d.mts +2 -0
- package/dist/mssql.mjs +1 -0
- package/dist/schema.d.mts +1 -1
- package/package.json +18 -13
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{i as e,n as t,r as n,t as r}from"./_chunks/base.mjs";import{n as i,t as a}from"./_chunks/pg.mjs";import{i as o,n as s,r as ee,t as te}from"./_chunks/errors.mjs";import{n as ne,t as re}from"./_chunks/mysql.mjs";import{n as ie,t as ae}from"./_chunks/sqlite.mjs";import{C as oe,S as se,_ as ce,a as le,b as ue,c as de,d as fe,f as c,g as pe,h as me,i as he,l as ge,m as _e,n as ve,o as ye,p as be,r as xe,s as Se,t as Ce,u as we,v as Te,x as Ee,y as De}from"./_chunks/schema.mjs";function l(e,t,n){return Object.freeze({type:`table_ref`,name:e,alias:t,schema:n})}function u(){return Object.freeze({type:`select`,distinct:!1,columns:Object.freeze([]),joins:Object.freeze([]),groupBy:Object.freeze([]),orderBy:Object.freeze([]),ctes:Object.freeze([]),forUpdate:!1})}function d(e){return Object.freeze({type:`insert`,table:e,columns:Object.freeze([]),values:Object.freeze([]),returning:Object.freeze([]),ctes:Object.freeze([])})}function f(e){return Object.freeze({type:`update`,table:e,set:Object.freeze([]),returning:Object.freeze([]),ctes:Object.freeze([])})}function p(e){return Object.freeze({type:`delete`,table:e,returning:Object.freeze([]),ctes:Object.freeze([])})}function m(e,t){return{type:`column_ref`,column:e,table:t}}function Oe(e,t,n){return{type:`column_ref`,column:e,table:n,alias:t}}function h(e){return{type:`literal`,value:e}}function g(e){return{type:`star`,table:e}}function _(e,t){return{type:`param`,index:e,value:t}}function ke(e,t=[]){return{type:`raw`,sql:e,params:t}}function Ae(e,t){return{type:`subquery`,query:e,alias:t}}function v(e,t,n){return{type:`function_call`,name:e,args:t,alias:n}}function y(e,t,n){return{type:`binary_op`,op:e,left:t,right:n}}function b(e,t,n=`prefix`){return{type:`unary_op`,op:e,operand:t,position:n}}function x(e,t){return y(`AND`,e,t)}function S(e,t){return y(`OR`,e,t)}function C(e,t){return y(`=`,e,t)}function je(e,t){return y(`!=`,e,t)}function Me(e,t){return y(`>`,e,t)}function Ne(e,t){return y(`>=`,e,t)}function Pe(e,t){return y(`<`,e,t)}function Fe(e,t){return y(`<=`,e,t)}function Ie(e,t){return y(`LIKE`,e,t)}function Le(e,t,n,r=!1){return{type:`between`,expr:e,low:t,high:n,negated:r}}function Re(e,t,n=!1){return{type:`in`,expr:e,values:t,negated:n}}function w(e,t=!1){return{type:`is_null`,expr:e,negated:t}}function ze(e,t){return{type:`cast`,expr:e,dataType:t}}function Be(e,t=!1){return{type:`exists`,query:e,negated:t}}function Ve(e){return b(`NOT`,e)}var He=class{transform(e){switch(e.type){case`select`:return this.transformSelect(e);case`insert`:return this.transformInsert(e);case`update`:return this.transformUpdate(e);case`delete`:return this.transformDelete(e);default:return this.transformExpression(e)}}transformSelect(e){return{...e,columns:e.columns.map(e=>this.transformExpression(e)),where:e.where?this.transformExpression(e.where):void 0,having:e.having?this.transformExpression(e.having):void 0,joins:e.joins.map(e=>({...e,on:e.on?this.transformExpression(e.on):void 0})),orderBy:e.orderBy.map(e=>({...e,expr:this.transformExpression(e.expr)}))}}transformInsert(e){return{...e,values:e.values.map(e=>e.map(e=>this.transformExpression(e)))}}transformUpdate(e){return{...e,set:e.set.map(e=>({...e,value:this.transformExpression(e.value)})),where:e.where?this.transformExpression(e.where):void 0}}transformDelete(e){return{...e,where:e.where?this.transformExpression(e.where):void 0}}transformExpression(e){switch(e.type){case`binary_op`:return{...e,left:this.transformExpression(e.left),right:this.transformExpression(e.right)};case`unary_op`:return{...e,operand:this.transformExpression(e.operand)};case`function_call`:return{...e,args:e.args.map(e=>this.transformExpression(e))};case`between`:return{...e,expr:this.transformExpression(e.expr),low:this.transformExpression(e.low),high:this.transformExpression(e.high)};case`in`:return{...e,expr:this.transformExpression(e.expr),values:Array.isArray(e.values)?e.values.map(e=>this.transformExpression(e)):e.values};case`is_null`:return{...e,expr:this.transformExpression(e.expr)};case`cast`:return{...e,expr:this.transformExpression(e.expr)};case`json_access`:return{...e,expr:this.transformExpression(e.expr)};case`array_expr`:return{...e,elements:e.elements.map(e=>this.transformExpression(e))};case`window_function`:return{...e,fn:this.transformExpression(e.fn),partitionBy:e.partitionBy.map(e=>this.transformExpression(e)),orderBy:e.orderBy.map(e=>({...e,expr:this.transformExpression(e.expr)}))};default:return e}}};function Ue(e,t){switch(e.type){case`select`:return t.visitSelect(e);case`insert`:return t.visitInsert(e);case`update`:return t.visitUpdate(e);case`delete`:return t.visitDelete(e);default:return t.visitExpression(e)}}var T=class e{node;constructor(e){this.node=e??u()}columns(...t){let n=t.map(e=>typeof e==`string`?m(e):e);return new e({...this.node,columns:[...this.node.columns,...n]})}allColumns(){return new e({...this.node,columns:[...this.node.columns,g()]})}distinct(){return new e({...this.node,distinct:!0})}from(t,n){if(typeof t==`string`){let r={type:`table_ref`,name:t,alias:n};return new e({...this.node,from:r})}return n&&t.type!==`subquery`?new e({...this.node,from:{...t,alias:n}}):new e({...this.node,from:t})}where(t){return new e({...this.node,where:t})}join(t,n,r,i){let a={type:`join`,joinType:t,table:typeof n==`string`?{type:`table_ref`,name:n,alias:i}:n,on:r};return new e({...this.node,joins:[...this.node.joins,a]})}innerJoin(e,t,n){return this.join(`INNER`,e,t,n)}leftJoin(e,t,n){return this.join(`LEFT`,e,t,n)}rightJoin(e,t,n){return this.join(`RIGHT`,e,t,n)}groupBy(...t){let n=t.map(e=>typeof e==`string`?m(e):e);return new e({...this.node,groupBy:[...this.node.groupBy,...n]})}having(t){return new e({...this.node,having:t})}orderBy(t,n=`ASC`,r){let i={expr:typeof t==`string`?m(t):t,direction:n,nulls:r};return new e({...this.node,orderBy:[...this.node.orderBy,i]})}limit(t){return new e({...this.node,limit:t})}offset(t){return new e({...this.node,offset:t})}forUpdate(){return new e({...this.node,forUpdate:!0})}with(t,n,r=!1){let i={name:t,query:n,recursive:r};return new e({...this.node,ctes:[...this.node.ctes,i]})}union(e){return this.setOp(`UNION`,e)}unionAll(e){return this.setOp(`UNION ALL`,e)}intersect(e){return this.setOp(`INTERSECT`,e)}except(e){return this.setOp(`EXCEPT`,e)}setOp(t,n){return new e({...this.node,setOp:{op:t,query:n}})}build(){return{...this.node}}};function We(...e){let t=new T;return e.length>0?t.columns(...e):t.allColumns()}var E=class e{node;paramIndex;constructor(e,t=0){this.node=e??d({name:``}),this.paramIndex=t}into(t){let n=typeof t==`string`?{type:`table_ref`,name:t}:t;return new e({...this.node,table:n},this.paramIndex)}columns(...t){return new e({...this.node,columns:[...this.node.columns,...t]},this.paramIndex)}values(...t){let n=this.paramIndex,r=t.map(e=>{let t=_(n,e);return n++,t});return new e({...this.node,values:[...this.node.values,r]},n)}returning(...t){return new e({...this.node,returning:[...this.node.returning,...t]},this.paramIndex)}onConflictDoNothing(...t){let n={columns:t,action:`nothing`};return new e({...this.node,onConflict:n},this.paramIndex)}onConflictDoUpdate(t,n,r){let i={columns:t,action:{set:n},where:r};return new e({...this.node,onConflict:i},this.paramIndex)}with(t,n,r=!1){let i={name:t,query:n,recursive:r};return new e({...this.node,ctes:[...this.node.ctes,i]},this.paramIndex)}build(){return{...this.node}}};function Ge(e){return new E().into(e)}var D=class e{node;constructor(e){this.node=e??f({name:``})}table(t){let n=typeof t==`string`?{type:`table_ref`,name:t}:t;return new e({...this.node,table:n})}set(t,n){return new e({...this.node,set:[...this.node.set,{column:t,value:n}]})}where(t){return new e({...this.node,where:t})}from(t){let n=typeof t==`string`?{type:`table_ref`,name:t}:t;return new e({...this.node,from:n})}returning(...t){return new e({...this.node,returning:[...this.node.returning,...t]})}with(t,n,r=!1){let i={name:t,query:n,recursive:r};return new e({...this.node,ctes:[...this.node.ctes,i]})}build(){return{...this.node}}};function Ke(e){return new D().table(e)}var O=class e{node;constructor(e){this.node=e??p({name:``})}from(t){let n=typeof t==`string`?{type:`table_ref`,name:t}:t;return new e({...this.node,table:n})}where(t){return new e({...this.node,where:t})}returning(...t){return new e({...this.node,returning:[...this.node.returning,...t]})}with(t,n,r=!1){let i={name:t,query:n,recursive:r};return new e({...this.node,ctes:[...this.node.ctes,i]})}build(){return{...this.node}}};function qe(e){return new O().from(e)}const k=new Set(`SELECT.FROM.WHERE.AND.OR.JOIN.INNER JOIN.LEFT JOIN.RIGHT JOIN.FULL JOIN.CROSS JOIN.ON.GROUP BY.HAVING.ORDER BY.LIMIT.OFFSET.INSERT INTO.VALUES.UPDATE.SET.DELETE FROM.RETURNING.WITH.WITH RECURSIVE.UNION.UNION ALL.INTERSECT.EXCEPT.FOR UPDATE.ON CONFLICT.DO NOTHING.DO UPDATE SET`.split(`.`));function Je(e,t={}){let n=t.indent??` `,r=[],i=0,a=Ye(e),o=0;for(;o<a.length;){let e=a[o];if(e===`(`){i++,A(r,e),o++;continue}if(e===`)`){i=Math.max(0,i-1),A(r,e),o++;continue}let t=o+1<a.length?`${e} ${a[o+1]}`:``,s=o+2<a.length?`${e} ${a[o+1]} ${a[o+2]}`:``;if(k.has(s.toUpperCase())){r.push(`${n.repeat(i)}${s}`),o+=3;continue}if(k.has(t.toUpperCase())){r.push(`${n.repeat(i)}${t}`),o+=2;continue}if(k.has(e.toUpperCase())){r.push(`${n.repeat(i)}${e}`),o++;continue}A(r,e),o++}return r.join(`
|
|
2
|
-
`)}function
|
|
3
|
-
`+` `.repeat(e),r=e);break;case`nest`:i.push([e+o.indent,a,o.doc]);break;case`group`:if(a===`flat`)i.push([e,`flat`,o.doc]);else{let n=tt(o.doc);n!==null&&r+n<=t?i.push([e,`flat`,o.doc]):i.push([e,`break`,o.doc])}break;case`concat`:for(let t=o.docs.length-1;t>=0;t--)i.push([e,a,o.docs[t]]);break}}return n}function tt(e){let t=0,n=[e];for(;n.length>0;){let e=n.pop();switch(e.tag){case`empty`:break;case`text`:t+=e.text.length;break;case`line`:t+=1;break;case`nest`:n.push(e.doc);break;case`group`:n.push(e.doc);break;case`concat`:for(let t=e.docs.length-1;t>=0;t--)n.push(e.docs[t]);break}}return t}var F=class{_node;constructor(e,t){this._node=m(e,t)}eq(e){return B(z(`=`,this._node,R(e)))}neq(e){return B(z(`!=`,this._node,R(e)))}gt(e){return B(z(`>`,this._node,R(e)))}gte(e){return B(z(`>=`,this._node,R(e)))}lt(e){return B(z(`<`,this._node,R(e)))}lte(e){return B(z(`<=`,this._node,R(e)))}like(e){return B(z(`LIKE`,this._node,h(e)))}in(e){return B({type:`in`,expr:this._node,values:e.map(e=>R(e)),negated:!1})}notIn(e){return B({type:`in`,expr:this._node,values:e.map(e=>R(e)),negated:!0})}isNull(){return B({type:`is_null`,expr:this._node,negated:!1})}isNotNull(){return B({type:`is_null`,expr:this._node,negated:!0})}between(e,t){return B({type:`between`,expr:this._node,low:R(e),high:R(t),negated:!1})}eqCol(e){return B(z(`=`,this._node,e._node))}toExpr(){return B(this._node)}};let I=0;function L(){I=0}function R(e){return _(I++,e)}function z(e,t,n){return{type:`binary_op`,op:e,left:t,right:n}}function B(e){return{node:e}}function V(e){return new Proxy({},{get(e,t){return new F(t,void 0)}})}function nt(e,t){return B(x(e.node,t.node))}function rt(e,t){return B(S(e.node,t.node))}function it(e){return B(h(e))}function at(e,...t){return B(v(e,t.map(e=>e.node)))}function ot(){return B(v(`COUNT`,[g()]))}function H(e){return e.node}var U=class e{_builder;_table;constructor(e,t){this._builder=e,this._table=t??``}select(...t){return new e(this._builder.columns(...t),this._table)}selectAll(){return new e(this._builder.allColumns(),this._table)}selectExpr(t,n){let r=H(t),i=r.type===`column_ref`||r.type===`function_call`?{...r,alias:n}:{type:`raw`,sql:``,params:[]};return new e(this._builder.columns(i),this._table)}distinct(){return new e(this._builder.distinct(),this._table)}where(t){if(typeof t==`function`){L();let n=t(V(this._table));return new e(this._builder.where(H(n)),this._table)}return new e(this._builder.where(H(t)),this._table)}innerJoin(t,n){let r=W(n,this._table,t);return new e(this._builder.innerJoin(t,H(r)),this._table)}leftJoin(t,n){let r=W(n,this._table,t);return new e(this._builder.leftJoin(t,H(r)),this._table)}rightJoin(t,n){let r=W(n,this._table,t);return new e(this._builder.rightJoin(t,H(r)),this._table)}groupBy(...t){return new e(this._builder.groupBy(...t),this._table)}having(t){if(typeof t==`function`){L();let n=t(V(this._table));return new e(this._builder.having(H(n)),this._table)}return new e(this._builder.having(H(t)),this._table)}orderBy(t,n=`ASC`,r){return new e(this._builder.orderBy(t,n,r),this._table)}limit(t){return new e(this._builder.limit({type:`literal`,value:t}),this._table)}offset(t){return new e(this._builder.offset({type:`literal`,value:t}),this._table)}forUpdate(){return new e(this._builder.forUpdate(),this._table)}with(t,n,r=!1){return new e(this._builder.with(t,n,r),this._table)}union(t){return new e(this._builder.union(t.build()),this._table)}unionAll(t){return new e(this._builder.unionAll(t.build()),this._table)}build(){return this._builder.build()}compile(e){return e.print(this.build())}};function st(e,t){return new Proxy({},{get(e,t){return new Proxy({},{get(e,n){return new F(n,t)}})}})}function W(e,t,n){return typeof e==`function`?e(st(t,n)):e}var G=class e{_builder;_paramIdx;constructor(e,t=0){this._builder=new E().into(e),this._paramIdx=t}_withBuilder(t,n){let r=new e(``);return r._builder=t,r._paramIdx=n,r}values(e){let t=Object.entries(e),n=t.map(([e])=>e),r=t.map(([e,t])=>{let n=_(this._paramIdx,t);return this._paramIdx++,n}),i=this._builder;return i.build().columns.length===0&&(i=i.columns(...n)),i=new E({...i.build(),values:[...i.build().values,r]},this._paramIdx),this._withBuilder(i,this._paramIdx)}returning(...e){let t=e.map(e=>({type:`column_ref`,column:e}));return new K(new E({...this._builder.build(),returning:t},this._paramIdx))}returningAll(){return new K(new E({...this._builder.build(),returning:[g()]},this._paramIdx))}onConflictDoNothing(...e){return this._withBuilder(this._builder.onConflictDoNothing(...e),this._paramIdx)}onConflictDoUpdate(e,t){return this._withBuilder(this._builder.onConflictDoUpdate(e,t.map(e=>({column:e.column,value:H(e.value)}))),this._paramIdx)}build(){return this._builder.build()}compile(e){return e.print(this.build())}},K=class{_builder;constructor(e){this._builder=e}build(){return this._builder.build()}compile(e){return e.print(this.build())}},q=class e{_builder;_paramIdx;constructor(e,t=0){this._builder=new D().table(e),this._paramIdx=t}_with(t,n){let r=new e(``);return r._builder=t,r._paramIdx=n,r}set(e){let t=this._builder,n=this._paramIdx;for(let[r,i]of Object.entries(e))i!==void 0&&(t=t.set(r,_(n,i)),n++);return this._with(t,n)}setExpr(e,t){return this._with(this._builder.set(e,H(t)),this._paramIdx)}where(e){if(typeof e==`function`){L();let t=e(V(this._table));return this._with(this._builder.where(H(t)),this._paramIdx)}return this._with(this._builder.where(H(e)),this._paramIdx)}get _table(){return this._builder.build().table.name}returning(...e){let t=e.map(e=>({type:`column_ref`,column:e}));return new J(new D({...this._builder.build(),returning:t}))}returningAll(){return new J(new D({...this._builder.build(),returning:[g()]}))}build(){return this._builder.build()}compile(e){return e.print(this.build())}},J=class{_builder;constructor(e){this._builder=e}build(){return this._builder.build()}compile(e){return e.print(this.build())}},Y=class e{_builder;constructor(e){this._builder=new O().from(e)}_with(t){let n=new e(``);return n._builder=t,n}where(e){if(typeof e==`function`){L();let t=this._builder.build().table.name,n=e(V(t));return this._with(this._builder.where(H(n)))}return this._with(this._builder.where(H(e)))}returning(...e){let t=e.map(e=>({type:`column_ref`,column:e}));return new X(new O({...this._builder.build(),returning:t}))}returningAll(){return new X(new O({...this._builder.build(),returning:[g()]}))}build(){return this._builder.build()}compile(e){return e.print(this.build())}},X=class{_builder;constructor(e){this._builder=e}build(){return this._builder.build()}compile(e){return e.print(this.build())}},Z=class{plugins;constructor(e){this.plugins=Object.freeze([...e])}transformNode(e){let t=e;for(let e of this.plugins)e.transformNode&&(t=e.transformNode(t));return t}transformQuery(e){let t=e;for(let e of this.plugins)e.transformQuery&&(t=e.transformQuery(t));return t}transformResult(e){let t=e;for(let e of this.plugins)e.transformResult&&(t=e.transformResult(t));return t}},Q=class{_hooks=new Map;hook(e,t){return this._hooks.has(e)||this._hooks.set(e,[]),this._hooks.get(e).push(t),()=>{let n=this._hooks.get(e);if(n){let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}callHook(e,...t){let n=this._hooks.get(e);if(!n||n.length===0)return;let r;for(let i of n){let n=i(...t);n!==void 0&&(r=n,e!==`result:transform`&&t[0]&&typeof t[0]==`object`&&`node`in t[0]&&(t[0].node=n))}return r}hasHook(e){let t=this._hooks.get(e);return t!==void 0&&t.length>0}removeHook(e){this._hooks.delete(e)}removeAllHooks(){this._hooks.clear()}};function ct(e){return new $(e.dialect,e.plugins??[])}var $=class{_dialect;_plugins;_hooks;constructor(e,t=[]){this._dialect=e,this._plugins=new Z(t),this._hooks=new Q}hook(e,t){return this._hooks.hook(e,t)}selectFrom(e,t){return new U(new T().from(e,t),e)}insertInto(e){return new G(e)}update(e){return new q(e)}deleteFrom(e){return new Y(e)}compile(e){let t=this._plugins.transformNode(e),n=this._extractTableName(t);switch(t.type){case`select`:{let e=this._hooks.callHook(`select:before`,{node:t,table:n});e&&(t=e);break}case`insert`:{let e=this._hooks.callHook(`insert:before`,{node:t,table:n});e&&(t=e);break}case`update`:{let e=this._hooks.callHook(`update:before`,{node:t,table:n});e&&(t=e);break}case`delete`:{let e=this._hooks.callHook(`delete:before`,{node:t,table:n});e&&(t=e);break}}let r=this._hooks.callHook(`query:before`,{node:t,table:n});r&&(t=r);let i=this._dialect.createPrinter().print(t);i=this._plugins.transformQuery(i);let a=this._hooks.callHook(`query:after`,{node:t,table:n,query:i});return a&&(i=a),i}transformResult(e){let t=this._plugins.transformResult(e),n=this._hooks.callHook(`result:transform`,t);return n&&(t=n),t}printer(){return this._dialect.createPrinter()}_extractTableName(e){switch(e.type){case`select`:return e.from?.type===`table_ref`?e.from.name:void 0;case`insert`:return e.table.name;case`update`:return e.table.name;case`delete`:return e.table.name;default:return}}},lt=class{name=`with-schema`;schema;constructor(e){this.schema=e}transformNode(e){switch(e.type){case`select`:return this.transformSelect(e);case`insert`:return this.transformInsert(e);case`update`:return this.transformUpdate(e);case`delete`:return this.transformDelete(e);default:return e}}addSchema(e){return e.schema?e:{...e,schema:this.schema}}transformSelect(e){return{...e,from:e.from?e.from.type===`table_ref`?this.addSchema(e.from):e.from:void 0,joins:e.joins.map(e=>({...e,table:e.table.type===`table_ref`?this.addSchema(e.table):e.table}))}}transformInsert(e){return{...e,table:this.addSchema(e.table)}}transformUpdate(e){return{...e,table:this.addSchema(e.table),from:e.from?this.addSchema(e.from):void 0}}transformDelete(e){return{...e,table:this.addSchema(e.table)}}},ut=class{name=`soft-delete`;tables;column;constructor(e){this.tables=new Set(e.tables),this.column=e.column??`deleted_at`}transformNode(e){switch(e.type){case`select`:return this.transformSelect(e);case`update`:return this.transformUpdate(e);case`delete`:return this.transformDelete(e);default:return e}}isTargetTable(e){return this.tables.has(e)}softDeleteCondition(){return w(m(this.column))}addCondition(e){let t=this.softDeleteCondition();return e?x(e,t):t}transformSelect(e){return!e.from||e.from.type!==`table_ref`||!this.isTargetTable(e.from.name)?e:{...e,where:this.addCondition(e.where)}}transformUpdate(e){return this.isTargetTable(e.table.name)?{...e,where:this.addCondition(e.where)}:e}transformDelete(e){return this.isTargetTable(e.table.name)?{...e,where:this.addCondition(e.where)}:e}},dt=class{name=`camel-case`;transformResult(e){return e.map(e=>{let t={};for(let n of Object.keys(e))t[ft(n)]=e[n];return t})}};function ft(e){return e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}export{He as ASTTransformer,r as BasePrinter,dt as CamelCasePlugin,F as Col,ve as ColumnBuilder,O as DeleteBuilder,te as EmptyQueryError,Q as Hookable,E as InsertBuilder,s as InvalidExpressionError,ne as MysqlPrinter,i as PgPrinter,Z as PluginManager,T as SelectBuilder,ut as SoftDeletePlugin,ie as SqlitePrinter,$ as Sumak,ee as SumakError,Y as TypedDeleteBuilder,X as TypedDeleteReturningBuilder,G as TypedInsertBuilder,K as TypedInsertReturningBuilder,U as TypedSelectBuilder,q as TypedUpdateBuilder,J as TypedUpdateReturningBuilder,o as UnsupportedDialectFeatureError,D as UpdateBuilder,lt as WithSchemaPlugin,nt as and,Le as between,xe as bigint,he as bigserial,y as binOp,le as boolean,ye as bytea,ze as cast,Se as char,m as col,Oe as colAs,ot as count,p as createDeleteNode,d as createInsertNode,u as createSelectNode,f as createUpdateNode,de as date,Ce as defineTable,qe as deleteFrom,P as docConcat,j as docEmpty,Ze as docGroup,Qe as docJoin,N as docLine,Xe as docNest,et as docRender,M as docText,$e as docTextLine,ge as doublePrecision,we as enumType,C as eq,Be as exists,v as fn,t as formatParam,Je as formatSQL,Me as gt,Ne as gte,Re as inList,Ge as insert,fe as integer,w as isNull,c as json,be as jsonb,Ie as like,h as lit,Pe as lt,Fe as lte,re as mysqlDialect,je as neq,Ve as not,_e as numeric,rt as or,_ as param,a as pgDialect,n as quoteIdentifier,e as quoteTableRef,ke as raw,me as real,L as resetParams,We as select,pe as serial,ce as smallint,at as sqlFn,ae as sqliteDialect,g as star,Ae as subquery,ct as sumak,l as tableRef,Te as text,De as time,ue as timestamp,Ee as timestamptz,b as unaryOp,Ke as update,se as uuid,it as val,oe as varchar,Ue as visitNode};
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"./_chunks/base.mjs";import{n as i,t as a}from"./_chunks/pg.mjs";import{i as o,n as s,r as ee,t as te}from"./_chunks/errors.mjs";import{n as ne,t as re}from"./_chunks/mssql.mjs";import{n as ie,t as ae}from"./_chunks/mysql.mjs";import{n as oe,t as se}from"./_chunks/sqlite.mjs";import{C as ce,S as le,_ as ue,a as de,b as fe,c as pe,d as me,f as he,g as ge,h as _e,i as ve,l as ye,m as be,n as xe,o as Se,p as Ce,r as we,s as Te,t as Ee,u as De,v as Oe,x as ke,y as Ae}from"./_chunks/schema.mjs";function c(e,t,n,r){return{type:`merge`,target:e,source:t,sourceAlias:n,on:r,whens:[],ctes:[]}}function je(e,t,n){return Object.freeze({type:`table_ref`,name:e,alias:t,schema:n})}function l(){return{type:`select`,distinct:!1,columns:[],joins:[],groupBy:[],orderBy:[],ctes:[],forUpdate:!1}}function u(e){return{type:`insert`,table:e,columns:[],values:[],returning:[],ctes:[]}}function d(e){return{type:`update`,table:e,set:[],returning:[],ctes:[]}}function f(e){return{type:`delete`,table:e,returning:[],ctes:[]}}function p(e,t){return{type:`column_ref`,column:e,table:t}}function Me(e,t,n){return{type:`column_ref`,column:e,table:n,alias:t}}function m(e){return{type:`literal`,value:e}}function h(e){return{type:`star`,table:e}}function g(e,t){return{type:`param`,index:e,value:t}}function Ne(e,t=[]){return{type:`raw`,sql:e,params:t}}function Pe(e,t){return{type:`subquery`,query:e,alias:t}}function _(e,t,n){return{type:`function_call`,name:e,args:t,alias:n}}function v(e,t,n){return{type:`binary_op`,op:e,left:t,right:n}}function y(e,t,n=`prefix`){return{type:`unary_op`,op:e,operand:t,position:n}}function b(e,t){return v(`AND`,e,t)}function Fe(e,t){return v(`OR`,e,t)}function Ie(e,t){return v(`=`,e,t)}function Le(e,t){return v(`!=`,e,t)}function Re(e,t){return v(`>`,e,t)}function ze(e,t){return v(`>=`,e,t)}function Be(e,t){return v(`<`,e,t)}function Ve(e,t){return v(`<=`,e,t)}function He(e,t){return v(`LIKE`,e,t)}function Ue(e,t,n,r=!1){return{type:`between`,expr:e,low:t,high:n,negated:r}}function We(e,t,n=!1){return{type:`in`,expr:e,values:t,negated:n}}function x(e,t=!1){return{type:`is_null`,expr:e,negated:t}}function Ge(e,t){return{type:`cast`,expr:e,dataType:t}}function S(e,t=!1){return{type:`exists`,query:e,negated:t}}function Ke(e){return y(`NOT`,e)}var qe=class{transform(e){switch(e.type){case`select`:return this.transformSelect(e);case`insert`:return this.transformInsert(e);case`update`:return this.transformUpdate(e);case`delete`:return this.transformDelete(e);case`merge`:return this.transformMerge(e);default:return this.transformExpression(e)}}transformSelect(e){return{...e,columns:e.columns.map(e=>this.transformExpression(e)),where:e.where?this.transformExpression(e.where):void 0,having:e.having?this.transformExpression(e.having):void 0,joins:e.joins.map(e=>({...e,on:e.on?this.transformExpression(e.on):void 0})),orderBy:e.orderBy.map(e=>({...e,expr:this.transformExpression(e.expr)}))}}transformInsert(e){return{...e,values:e.values.map(e=>e.map(e=>this.transformExpression(e)))}}transformUpdate(e){return{...e,set:e.set.map(e=>({...e,value:this.transformExpression(e.value)})),where:e.where?this.transformExpression(e.where):void 0}}transformDelete(e){return{...e,where:e.where?this.transformExpression(e.where):void 0}}transformMerge(e){return{...e,on:this.transformExpression(e.on),whens:e.whens.map(e=>e.type===`matched`?{...e,condition:e.condition?this.transformExpression(e.condition):void 0,set:e.set?.map(e=>({...e,value:this.transformExpression(e.value)}))}:{...e,condition:e.condition?this.transformExpression(e.condition):void 0,values:e.values.map(e=>this.transformExpression(e))})}}transformExpression(e){switch(e.type){case`binary_op`:return{...e,left:this.transformExpression(e.left),right:this.transformExpression(e.right)};case`unary_op`:return{...e,operand:this.transformExpression(e.operand)};case`function_call`:return{...e,args:e.args.map(e=>this.transformExpression(e))};case`between`:return{...e,expr:this.transformExpression(e.expr),low:this.transformExpression(e.low),high:this.transformExpression(e.high)};case`in`:return{...e,expr:this.transformExpression(e.expr),values:Array.isArray(e.values)?e.values.map(e=>this.transformExpression(e)):e.values};case`is_null`:return{...e,expr:this.transformExpression(e.expr)};case`cast`:return{...e,expr:this.transformExpression(e.expr)};case`json_access`:return{...e,expr:this.transformExpression(e.expr)};case`array_expr`:return{...e,elements:e.elements.map(e=>this.transformExpression(e))};case`window_function`:return{...e,fn:this.transformExpression(e.fn),partitionBy:e.partitionBy.map(e=>this.transformExpression(e)),orderBy:e.orderBy.map(e=>({...e,expr:this.transformExpression(e.expr)}))};case`aliased_expr`:return{...e,expr:this.transformExpression(e.expr)};case`full_text_search`:return{...e,columns:e.columns.map(e=>this.transformExpression(e)),query:this.transformExpression(e.query)};default:return e}}};function Je(e,t){switch(e.type){case`select`:return t.visitSelect(e);case`insert`:return t.visitInsert(e);case`update`:return t.visitUpdate(e);case`delete`:return t.visitDelete(e);case`merge`:return t.visitMerge(e);default:return t.visitExpression(e)}}var C=class e{node;paramIndex;constructor(e,t=0){this.node=e??c({type:`table_ref`,name:``},{type:`table_ref`,name:``},`src`,{type:`literal`,value:!0}),this.paramIndex=t}into(t){let n=typeof t==`string`?{type:`table_ref`,name:t}:t;return new e({...this.node,target:n},this.paramIndex)}using(t,n){let r=typeof t==`string`?{type:`table_ref`,name:t}:t;return new e({...this.node,source:r,sourceAlias:n},this.paramIndex)}on(t){return new e({...this.node,on:t},this.paramIndex)}whenMatched(t){return new e({...this.node,whens:[...this.node.whens,t]},this.paramIndex)}whenNotMatched(t){return new e({...this.node,whens:[...this.node.whens,t]},this.paramIndex)}whenMatchedUpdate(e,t){let n={type:`matched`,action:`update`,set:e,condition:t};return this.whenMatched(n)}whenMatchedDelete(e){let t={type:`matched`,action:`delete`,condition:e};return this.whenMatched(t)}whenNotMatchedInsert(e,t,n){let r={type:`not_matched`,columns:e,values:t,condition:n};return this.whenNotMatched(r)}with(t,n,r=!1){let i={name:t,query:n,recursive:r};return new e({...this.node,ctes:[...this.node.ctes,i]},this.paramIndex)}build(){return{...this.node}}};function Ye(e){return new C().into(e)}var w=class e{node;constructor(e){this.node=e??l()}columns(...t){let n=t.map(e=>typeof e==`string`?p(e):e);return new e({...this.node,columns:[...this.node.columns,...n]})}allColumns(){return new e({...this.node,columns:[...this.node.columns,h()]})}distinct(){return new e({...this.node,distinct:!0})}from(t,n){if(typeof t==`string`){let r={type:`table_ref`,name:t,alias:n};return new e({...this.node,from:r})}return n&&t.type!==`subquery`?new e({...this.node,from:{...t,alias:n}}):new e({...this.node,from:t})}where(t){return new e({...this.node,where:t})}join(t,n,r,i){let a={type:`join`,joinType:t,table:typeof n==`string`?{type:`table_ref`,name:n,alias:i}:n,on:r};return new e({...this.node,joins:[...this.node.joins,a]})}innerJoin(e,t,n){return this.join(`INNER`,e,t,n)}leftJoin(e,t,n){return this.join(`LEFT`,e,t,n)}rightJoin(e,t,n){return this.join(`RIGHT`,e,t,n)}groupBy(...t){let n=t.map(e=>typeof e==`string`?p(e):e);return new e({...this.node,groupBy:[...this.node.groupBy,...n]})}having(t){return new e({...this.node,having:t})}orderBy(t,n=`ASC`,r){let i={expr:typeof t==`string`?p(t):t,direction:n,nulls:r};return new e({...this.node,orderBy:[...this.node.orderBy,i]})}limit(t){return new e({...this.node,limit:t})}offset(t){return new e({...this.node,offset:t})}forSystemTime(t){return!this.node.from||this.node.from.type!==`table_ref`?this:new e({...this.node,from:{...this.node.from,temporal:t}})}forUpdate(){return new e({...this.node,forUpdate:!0})}with(t,n,r=!1){let i={name:t,query:n,recursive:r};return new e({...this.node,ctes:[...this.node.ctes,i]})}union(e){return this.setOp(`UNION`,e)}unionAll(e){return this.setOp(`UNION ALL`,e)}intersect(e){return this.setOp(`INTERSECT`,e)}except(e){return this.setOp(`EXCEPT`,e)}setOp(t,n){return new e({...this.node,setOp:{op:t,query:n}})}build(){return{...this.node}}};function Xe(...e){let t=new w;return e.length>0?t.columns(...e):t.allColumns()}var T=class e{node;paramIndex;constructor(e,t=0){this.node=e??u({type:`table_ref`,name:``}),this.paramIndex=t}into(t){let n=typeof t==`string`?{type:`table_ref`,name:t}:t;return new e({...this.node,table:n},this.paramIndex)}columns(...t){return new e({...this.node,columns:[...this.node.columns,...t]},this.paramIndex)}values(...t){let n=this.paramIndex,r=t.map(e=>{let t=g(n,e);return n++,t});return new e({...this.node,values:[...this.node.values,r]},n)}returning(...t){return new e({...this.node,returning:[...this.node.returning,...t]},this.paramIndex)}onConflictDoNothing(...t){let n={columns:t,action:`nothing`};return new e({...this.node,onConflict:n},this.paramIndex)}onConflictDoUpdate(t,n,r){let i={columns:t,action:{set:n},where:r};return new e({...this.node,onConflict:i},this.paramIndex)}with(t,n,r=!1){let i={name:t,query:n,recursive:r};return new e({...this.node,ctes:[...this.node.ctes,i]},this.paramIndex)}build(){return{...this.node}}};function Ze(e){return new T().into(e)}var E=class e{node;constructor(e){this.node=e??d({type:`table_ref`,name:``})}table(t){let n=typeof t==`string`?{type:`table_ref`,name:t}:t;return new e({...this.node,table:n})}set(t,n){return new e({...this.node,set:[...this.node.set,{column:t,value:n}]})}where(t){return new e({...this.node,where:t})}from(t){let n=typeof t==`string`?{type:`table_ref`,name:t}:t;return new e({...this.node,from:n})}returning(...t){return new e({...this.node,returning:[...this.node.returning,...t]})}with(t,n,r=!1){let i={name:t,query:n,recursive:r};return new e({...this.node,ctes:[...this.node.ctes,i]})}build(){return{...this.node}}};function Qe(e){return new E().table(e)}var D=class e{node;constructor(e){this.node=e??f({type:`table_ref`,name:``})}from(t){let n=typeof t==`string`?{type:`table_ref`,name:t}:t;return new e({...this.node,table:n})}where(t){return new e({...this.node,where:t})}returning(...t){return new e({...this.node,returning:[...this.node.returning,...t]})}with(t,n,r=!1){let i={name:t,query:n,recursive:r};return new e({...this.node,ctes:[...this.node.ctes,i]})}build(){return{...this.node}}};function $e(e){return new D().from(e)}const O=new Set(`SELECT.FROM.WHERE.AND.OR.JOIN.INNER JOIN.LEFT JOIN.RIGHT JOIN.FULL JOIN.CROSS JOIN.ON.GROUP BY.HAVING.ORDER BY.LIMIT.OFFSET.INSERT INTO.VALUES.UPDATE.SET.DELETE FROM.RETURNING.WITH.WITH RECURSIVE.UNION.UNION ALL.INTERSECT.EXCEPT.FOR UPDATE.ON CONFLICT.DO NOTHING.DO UPDATE SET`.split(`.`));function et(e,t={}){let n=t.indent??` `,r=[],i=0,a=tt(e),o=0;for(;o<a.length;){let e=a[o];if(e===`(`){i++,k(r,e),o++;continue}if(e===`)`){i=Math.max(0,i-1),k(r,e),o++;continue}let t=o+1<a.length?`${e} ${a[o+1]}`:``,s=o+2<a.length?`${e} ${a[o+1]} ${a[o+2]}`:``;if(O.has(s.toUpperCase())){r.push(`${n.repeat(i)}${s}`),o+=3;continue}if(O.has(t.toUpperCase())){r.push(`${n.repeat(i)}${t}`),o+=2;continue}if(O.has(e.toUpperCase())){r.push(`${n.repeat(i)}${e}`),o++;continue}k(r,e),o++}return r.join(`
|
|
2
|
+
`)}function k(e,t){e.length===0?e.push(t):e[e.length-1]+=` ${t}`}function tt(e){let t=[],n=``;for(let r=0;r<e.length;r++){let i=e[r];if(i===`'`||i===`"`){for(n+=i,r++;r<e.length&&e[r]!==i;){if(e[r]===i&&r+1<e.length&&e[r+1]===i){n+=i+i,r+=2;continue}n+=e[r],r++}r<e.length&&(n+=e[r]);continue}if(i===`(`||i===`)`){n.trim()&&(t.push(n.trim()),n=``),t.push(i);continue}if(i===`,`||i===`;`){n.trim()&&(t.push(n.trim()),n=``),t.push(i);continue}if(/\s/.test(i)){n.trim()&&(t.push(n.trim()),n=``);continue}n+=i}return n.trim()&&t.push(n.trim()),t}function A(){return{tag:`empty`}}function j(e){return{tag:`text`,text:e}}function M(){return{tag:`line`}}function nt(e,t){return{tag:`nest`,indent:e,doc:t}}function rt(e){return{tag:`group`,doc:e}}function N(...e){let t=e.filter(e=>e.tag!==`empty`);return t.length===0?A():t.length===1?t[0]:{tag:`concat`,docs:t}}function it(e,t){if(t.length===0)return A();let n=[];for(let r=0;r<t.length;r++)r>0&&n.push(e),n.push(t[r]);return N(...n)}function at(e){return N(j(e),M())}function ot(e,t=80){let n=``,r=0,i=[[0,`break`,e]];for(;i.length>0;){let[e,a,o]=i.pop();switch(o.tag){case`empty`:break;case`text`:n+=o.text,r+=o.text.length;break;case`line`:a===`flat`?(n+=` `,r+=1):(n+=`
|
|
3
|
+
`+` `.repeat(e),r=e);break;case`nest`:i.push([e+o.indent,a,o.doc]);break;case`group`:if(a===`flat`)i.push([e,`flat`,o.doc]);else{let n=st(o.doc);n!==null&&r+n<=t?i.push([e,`flat`,o.doc]):i.push([e,`break`,o.doc])}break;case`concat`:for(let t=o.docs.length-1;t>=0;t--)i.push([e,a,o.docs[t]]);break}}return n}function st(e){let t=0,n=[e];for(;n.length>0;){let e=n.pop();switch(e.tag){case`empty`:break;case`text`:t+=e.text.length;break;case`line`:t+=1;break;case`nest`:n.push(e.doc);break;case`group`:n.push(e.doc);break;case`concat`:for(let t=e.docs.length-1;t>=0;t--)n.push(e.docs[t]);break}}return t}var P=class{_node;constructor(e,t){this._node=p(e,t)}eq(e){return z(R(`=`,this._node,L(e)))}neq(e){return z(R(`!=`,this._node,L(e)))}gt(e){return z(R(`>`,this._node,L(e)))}gte(e){return z(R(`>=`,this._node,L(e)))}lt(e){return z(R(`<`,this._node,L(e)))}lte(e){return z(R(`<=`,this._node,L(e)))}like(e){return z(R(`LIKE`,this._node,m(e)))}in(e){return z({type:`in`,expr:this._node,values:e.map(e=>L(e)),negated:!1})}notIn(e){return z({type:`in`,expr:this._node,values:e.map(e=>L(e)),negated:!0})}isNull(){return z({type:`is_null`,expr:this._node,negated:!1})}isNotNull(){return z({type:`is_null`,expr:this._node,negated:!0})}between(e,t){return z({type:`between`,expr:this._node,low:L(e),high:L(t),negated:!1})}eqCol(e){return z(R(`=`,this._node,e._node))}toExpr(){return z(this._node)}};let F=0;function I(){F=0}function L(e){return g(F++,e)}function R(e,t,n){return{type:`binary_op`,op:e,left:t,right:n}}function z(e){return{node:e}}function B(e){return new Proxy({},{get(e,t){return new P(t,void 0)}})}function ct(e,t){return z(b(e.node,t.node))}function lt(e,t){return z(Fe(e.node,t.node))}function ut(e){return z(m(e))}function dt(e,...t){return z(_(e,t.map(e=>e.node)))}function ft(){return z(_(`COUNT`,[h()]))}function pt(e){return z(_(`SUM`,[e.node]))}function mt(e){return z(_(`AVG`,[e.node]))}function ht(e){return z(_(`MIN`,[e.node]))}function gt(e){return z(_(`MAX`,[e.node]))}function _t(e,t){return z(_(`COALESCE`,[e.node,t.node]))}function vt(e){return z(Ke(e.node))}function yt(e){return z(S(e))}function bt(e){return z(S(e,!0))}function xt(e,t){return z(Ge(e.node,t))}function St(e,t,n=`->`){return z({type:`json_access`,expr:e.node,path:t,operator:n})}function Ct(e,t,n){return z({type:`full_text_search`,columns:e.map(e=>e.node),query:t.node,mode:n?.mode,language:n?.language})}function wt(e){return new V(e?e.node:void 0,[])}var V=class e{_operand;_whens;_else;constructor(e,t,n){this._operand=e,this._whens=t,this._else=n}when(t,n){return new e(this._operand,[...this._whens,{condition:t.node,result:n.node}])}else_(t){return new e(this._operand,this._whens,t.node)}end(){return z({type:`case`,operand:this._operand,whens:this._whens,else_:this._else})}};function H(e){return e.node}var U=class e{_builder;constructor(e){this._builder=new D().from(e)}_with(t){let n=new e(``);return n._builder=t,n}where(e){if(typeof e==`function`){I();let t=this._builder.build().table.name,n=e(B(t));return this._with(this._builder.where(H(n)))}return this._with(this._builder.where(H(e)))}returning(...e){let t=e.map(e=>({type:`column_ref`,column:e}));return new W(new D({...this._builder.build(),returning:t}))}returningAll(){return new W(new D({...this._builder.build(),returning:[h()]}))}with(e,t,n=!1){return this._with(this._builder.with(e,t,n))}build(){return this._builder.build()}compile(e){return e.print(this.build())}},W=class{_builder;constructor(e){this._builder=e}build(){return this._builder.build()}compile(e){return e.print(this.build())}},G=class e{_builder;_paramIdx;constructor(e,t=0){this._builder=new T().into(e),this._paramIdx=t}_withBuilder(t,n){let r=new e(``);return r._builder=t,r._paramIdx=n,r}values(e){let t=Object.entries(e),n=t.map(([e])=>e),r=t.map(([e,t])=>{let n=g(this._paramIdx,t);return this._paramIdx++,n}),i=this._builder;return i.build().columns.length===0&&(i=i.columns(...n)),i=new T({...i.build(),values:[...i.build().values,r]},this._paramIdx),this._withBuilder(i,this._paramIdx)}returning(...e){let t=e.map(e=>({type:`column_ref`,column:e}));return new K(new T({...this._builder.build(),returning:t},this._paramIdx))}returningAll(){return new K(new T({...this._builder.build(),returning:[h()]},this._paramIdx))}onConflictDoNothing(...e){return this._withBuilder(this._builder.onConflictDoNothing(...e),this._paramIdx)}onConflictDoUpdate(e,t){return this._withBuilder(this._builder.onConflictDoUpdate(e,t.map(e=>({column:e.column,value:H(e.value)}))),this._paramIdx)}with(e,t,n=!1){return this._withBuilder(this._builder.with(e,t,n),this._paramIdx)}build(){return this._builder.build()}compile(e){return e.print(this.build())}},K=class{_builder;constructor(e){this._builder=e}build(){return this._builder.build()}compile(e){return e.print(this.build())}};function q(e,t){let n=e=>new Proxy({},{get(t,n){return new P(n,e)}});return{target:n(e),source:n(t)}}var J=class e{_builder;_targetTable;_sourceAlias;_paramIdx;constructor(e,t,n,r,i=0){this._targetTable=e,this._sourceAlias=n,this._paramIdx=i,this._builder=new C().into(e).using(t,n).on(H(r))}_with(t,n){let r=new e(``,``,``,{node:{type:`literal`,value:!0}});return r._builder=t,r._targetTable=this._targetTable,r._sourceAlias=this._sourceAlias,r._paramIdx=n,r}whenMatchedThenUpdate(e,t){let n=this._paramIdx,r=[];for(let[t,i]of Object.entries(e))i!==void 0&&(r.push({column:t,value:g(n,i)}),n++);let i;return t&&(I(),i=H(t(q(this._targetTable,this._sourceAlias)))),this._with(this._builder.whenMatchedUpdate(r,i),n)}whenMatchedThenDelete(e){let t;return e&&(I(),t=H(e(q(this._targetTable,this._sourceAlias)))),this._with(this._builder.whenMatchedDelete(t),this._paramIdx)}whenNotMatchedThenInsert(e,t){let n=this._paramIdx,r=Object.entries(e),i=r.map(([e])=>e),a=r.map(([e,t])=>{let r=g(n,t);return n++,r}),o;return t&&(I(),o=H(t(q(this._targetTable,this._sourceAlias)))),this._with(this._builder.whenNotMatchedInsert(i,a,o),n)}with(e,t,n=!1){return this._with(this._builder.with(e,t,n),this._paramIdx)}build(){return this._builder.build()}compile(e){return e.print(this.build())}},Y=class e{_builder;_table;constructor(e,t){this._builder=e,this._table=t??``}select(...t){return new e(this._builder.columns(...t),this._table)}selectAll(){return new e(this._builder.allColumns(),this._table)}selectExpr(t,n){let r=Et(H(t),n);return new e(this._builder.columns(r),this._table)}distinct(){return new e(this._builder.distinct(),this._table)}where(t){if(typeof t==`function`){I();let n=t(B(this._table));return new e(this._builder.where(H(n)),this._table)}return new e(this._builder.where(H(t)),this._table)}innerJoin(t,n){let r=X(n,this._table,t);return new e(this._builder.innerJoin(t,H(r)),this._table)}leftJoin(t,n){let r=X(n,this._table,t);return new e(this._builder.leftJoin(t,H(r)),this._table)}rightJoin(t,n){let r=X(n,this._table,t);return new e(this._builder.rightJoin(t,H(r)),this._table)}groupBy(...t){return new e(this._builder.groupBy(...t),this._table)}having(t){if(typeof t==`function`){I();let n=t(B(this._table));return new e(this._builder.having(H(n)),this._table)}return new e(this._builder.having(H(t)),this._table)}orderBy(t,n=`ASC`,r){return new e(this._builder.orderBy(t,n,r),this._table)}limit(t){return new e(this._builder.limit({type:`literal`,value:t}),this._table)}offset(t){return new e(this._builder.offset({type:`literal`,value:t}),this._table)}forSystemTime(t){return new e(this._builder.forSystemTime(t),this._table)}forUpdate(){return new e(this._builder.forUpdate(),this._table)}with(t,n,r=!1){return new e(this._builder.with(t,n,r),this._table)}union(t){return new e(this._builder.union(t.build()),this._table)}unionAll(t){return new e(this._builder.unionAll(t.build()),this._table)}intersect(t){return new e(this._builder.intersect(t.build()),this._table)}except(t){return new e(this._builder.except(t.build()),this._table)}fullJoin(t,n){let r=X(n,this._table,t);return new e(this._builder.join(`FULL`,t,H(r)),this._table)}crossJoin(t){return new e(this._builder.join(`CROSS`,t),this._table)}build(){return this._builder.build()}compile(e){return e.print(this.build())}};function Tt(e,t){return new Proxy({},{get(e,t){return new Proxy({},{get(e,n){return new P(n,t)}})}})}function Et(e,t){return e.type===`column_ref`||e.type===`function_call`||e.type===`json_access`||e.type===`window_function`?{...e,alias:t}:{type:`aliased_expr`,expr:e,alias:t}}function X(e,t,n){return typeof e==`function`?e(Tt(t,n)):e}var Z=class e{_builder;_paramIdx;constructor(e,t=0){this._builder=new E().table(e),this._paramIdx=t}_with(t,n){let r=new e(``);return r._builder=t,r._paramIdx=n,r}set(e){let t=this._builder,n=this._paramIdx;for(let[r,i]of Object.entries(e))i!==void 0&&(t=t.set(r,g(n,i)),n++);return this._with(t,n)}setExpr(e,t){return this._with(this._builder.set(e,H(t)),this._paramIdx)}where(e){if(typeof e==`function`){I();let t=e(B(this._table));return this._with(this._builder.where(H(t)),this._paramIdx)}return this._with(this._builder.where(H(e)),this._paramIdx)}get _table(){return this._builder.build().table.name}returning(...e){let t=e.map(e=>({type:`column_ref`,column:e}));return new Q(new E({...this._builder.build(),returning:t}))}returningAll(){return new Q(new E({...this._builder.build(),returning:[h()]}))}from(e){return this._with(this._builder.from(e),this._paramIdx)}with(e,t,n=!1){return this._with(this._builder.with(e,t,n),this._paramIdx)}build(){return this._builder.build()}compile(e){return e.print(this.build())}},Q=class{_builder;constructor(e){this._builder=e}build(){return this._builder.build()}compile(e){return e.print(this.build())}},Dt=class{_hooks=new Map;hook(e,t){return this._hooks.has(e)||this._hooks.set(e,[]),this._hooks.get(e).push(t),()=>{let n=this._hooks.get(e);if(n){let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}callHook(e,...t){let n=this._hooks.get(e);if(!n||n.length===0)return;let r;for(let i of n){let n=i(...t);n!==void 0&&(r=n,e!==`result:transform`&&t[0]&&typeof t[0]==`object`&&`node`in t[0]&&(t[0].node=n))}return r}hasHook(e){let t=this._hooks.get(e);return t!==void 0&&t.length>0}removeHook(e){this._hooks.delete(e)}removeAllHooks(){this._hooks.clear()}},Ot=class{plugins;constructor(e){this.plugins=Object.freeze([...e])}transformNode(e){let t=e;for(let e of this.plugins)e.transformNode&&(t=e.transformNode(t));return t}transformQuery(e){let t=e;for(let e of this.plugins)e.transformQuery&&(t=e.transformQuery(t));return t}transformResult(e){let t=e;for(let e of this.plugins)e.transformResult&&(t=e.transformResult(t));return t}};function kt(e){return new $(e.dialect,e.plugins??[])}var $=class{_dialect;_plugins;_hooks;constructor(e,t=[]){this._dialect=e,this._plugins=new Ot(t),this._hooks=new Dt}hook(e,t){return this._hooks.hook(e,t)}selectFrom(e,t){return new Y(new w().from(e,t),e)}insertInto(e){return new G(e)}update(e){return new Z(e)}deleteFrom(e){return new U(e)}mergeInto(e,t,n,r){let i=e=>new Proxy({},{get(t,n){return new P(n,e)}});return new J(e,t,n,r({target:i(e),source:i(n)}))}compile(e){let t=this._plugins.transformNode(e),n=this._extractTableName(t);switch(t.type){case`select`:{let e=this._hooks.callHook(`select:before`,{node:t,table:n});e&&(t=e);break}case`insert`:{let e=this._hooks.callHook(`insert:before`,{node:t,table:n});e&&(t=e);break}case`update`:{let e=this._hooks.callHook(`update:before`,{node:t,table:n});e&&(t=e);break}case`delete`:{let e=this._hooks.callHook(`delete:before`,{node:t,table:n});e&&(t=e);break}}let r=this._hooks.callHook(`query:before`,{node:t,table:n});r&&(t=r);let i=this._dialect.createPrinter().print(t);i=this._plugins.transformQuery(i);let a=this._hooks.callHook(`query:after`,{node:t,table:n,query:i});return a&&(i=a),i}transformResult(e){let t=this._plugins.transformResult(e),n=this._hooks.callHook(`result:transform`,t);return n&&(t=n),t}printer(){return this._dialect.createPrinter()}_extractTableName(e){switch(e.type){case`select`:return e.from?.type===`table_ref`?e.from.name:void 0;case`insert`:return e.table.name;case`update`:return e.table.name;case`delete`:return e.table.name;case`merge`:return e.target.name;default:return}}},At=class{name=`with-schema`;schema;constructor(e){this.schema=e}transformNode(e){switch(e.type){case`select`:return this.transformSelect(e);case`insert`:return this.transformInsert(e);case`update`:return this.transformUpdate(e);case`delete`:return this.transformDelete(e);default:return e}}addSchema(e){return e.schema?e:{...e,schema:this.schema}}transformSelect(e){return{...e,from:e.from?e.from.type===`table_ref`?this.addSchema(e.from):e.from:void 0,joins:e.joins.map(e=>({...e,table:e.table.type===`table_ref`?this.addSchema(e.table):e.table}))}}transformInsert(e){return{...e,table:this.addSchema(e.table)}}transformUpdate(e){return{...e,table:this.addSchema(e.table),from:e.from?this.addSchema(e.from):void 0}}transformDelete(e){return{...e,table:this.addSchema(e.table)}}},jt=class{name=`soft-delete`;tables;column;constructor(e){this.tables=new Set(e.tables),this.column=e.column??`deleted_at`}transformNode(e){switch(e.type){case`select`:return this.transformSelect(e);case`update`:return this.transformUpdate(e);case`delete`:return this.transformDelete(e);default:return e}}isTargetTable(e){return this.tables.has(e)}softDeleteCondition(){return x(p(this.column))}addCondition(e){let t=this.softDeleteCondition();return e?b(e,t):t}transformSelect(e){return!e.from||e.from.type!==`table_ref`||!this.isTargetTable(e.from.name)?e:{...e,where:this.addCondition(e.where)}}transformUpdate(e){return this.isTargetTable(e.table.name)?{...e,where:this.addCondition(e.where)}:e}transformDelete(e){return this.isTargetTable(e.table.name)?{...e,where:this.addCondition(e.where)}:e}},Mt=class{name=`camel-case`;transformResult(e){return e.map(e=>{let t={};for(let n of Object.keys(e))t[Nt(n)]=e[n];return t})}};function Nt(e){return e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}export{qe as ASTTransformer,r as BasePrinter,Mt as CamelCasePlugin,V as CaseBuilder,P as Col,xe as ColumnBuilder,D as DeleteBuilder,te as EmptyQueryError,Dt as Hookable,T as InsertBuilder,s as InvalidExpressionError,C as MergeBuilder,ne as MssqlPrinter,ie as MysqlPrinter,i as PgPrinter,Ot as PluginManager,w as SelectBuilder,jt as SoftDeletePlugin,oe as SqlitePrinter,$ as Sumak,ee as SumakError,U as TypedDeleteBuilder,W as TypedDeleteReturningBuilder,G as TypedInsertBuilder,K as TypedInsertReturningBuilder,J as TypedMergeBuilder,Y as TypedSelectBuilder,Z as TypedUpdateBuilder,Q as TypedUpdateReturningBuilder,o as UnsupportedDialectFeatureError,E as UpdateBuilder,At as WithSchemaPlugin,ct as and,mt as avg,Ue as between,we as bigint,ve as bigserial,v as binOp,de as boolean,Se as bytea,wt as case_,xt as cast,Te as char,_t as coalesce,p as col,Me as colAs,ft as count,f as createDeleteNode,u as createInsertNode,c as createMergeNode,l as createSelectNode,d as createUpdateNode,pe as date,Ee as defineTable,$e as deleteFrom,N as docConcat,A as docEmpty,rt as docGroup,it as docJoin,M as docLine,nt as docNest,ot as docRender,j as docText,at as docTextLine,ye as doublePrecision,De as enumType,Ie as eq,yt as exists,_ as fn,t as formatParam,et as formatSQL,Re as gt,ze as gte,We as inList,Ze as insert,me as integer,x as isNull,he as json,St as jsonRef,Ce as jsonb,He as like,m as lit,Be as lt,Ve as lte,gt as max,Ye as merge,ht as min,re as mssqlDialect,ae as mysqlDialect,Le as neq,vt as not,bt as notExists,be as numeric,lt as or,g as param,a as pgDialect,n as quoteIdentifier,e as quoteTableRef,Ne as raw,_e as real,I as resetParams,Xe as select,ge as serial,ue as smallint,dt as sqlFn,se as sqliteDialect,h as star,Pe as subquery,pt as sum,kt as sumak,je as tableRef,Oe as text,Ct as textSearch,Ae as time,fe as timestamp,ke as timestamptz,y as unaryOp,Qe as update,le as uuid,ut as val,ce as varchar,Je as visitNode};
|
package/dist/mssql.d.mts
ADDED
package/dist/mssql.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./_chunks/mssql.mjs";export{e as MssqlPrinter,t as mssqlDialect};
|
package/dist/schema.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as InsertType, C as timestamp, D as ColumnType, E as varchar, F as Selectable, I as UpdateType, L as Updateable, M as Nullable, O as Generated, P as SelectType, S as time, T as uuid, _ as numeric, a as ColumnDef, b as smallint, c as boolean, d as date, f as doublePrecision, g as jsonb, h as json, i as ColumnBuilder, j as Insertable, k as GeneratedAlways, l as bytea, m as integer, n as TableDefinition, o as bigint, p as enumType, r as defineTable, s as bigserial, t as InferTable, u as char, v as real, w as timestamptz, x as text, y as serial } from "./_chunks/index.mjs";
|
|
2
2
|
export { ColumnBuilder, type ColumnDef, type ColumnType, type Generated, type GeneratedAlways, type InferTable, type InsertType, type Insertable, type Nullable, type SelectType, type Selectable, type TableDefinition, type UpdateType, type Updateable, bigint, bigserial, boolean, bytea, char, date, defineTable, doublePrecision, enumType, integer, json, jsonb, numeric, real, serial, smallint, text, time, timestamp, timestamptz, uuid, varchar };
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sumak",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Type-safe SQL query builder with powerful SQL printers. Zero dependencies, tree-shakeable. Pure TypeScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"database",
|
|
7
7
|
"esm",
|
|
8
|
+
"mssql",
|
|
8
9
|
"mysql",
|
|
9
10
|
"orm",
|
|
10
11
|
"postgresql",
|
|
@@ -42,6 +43,10 @@
|
|
|
42
43
|
"types": "./dist/pg.d.mts",
|
|
43
44
|
"default": "./dist/pg.mjs"
|
|
44
45
|
},
|
|
46
|
+
"./mssql": {
|
|
47
|
+
"types": "./dist/mssql.d.mts",
|
|
48
|
+
"default": "./dist/mssql.mjs"
|
|
49
|
+
},
|
|
45
50
|
"./mysql": {
|
|
46
51
|
"types": "./dist/mysql.d.mts",
|
|
47
52
|
"default": "./dist/mysql.mjs"
|
|
@@ -55,18 +60,8 @@
|
|
|
55
60
|
"default": "./dist/schema.mjs"
|
|
56
61
|
}
|
|
57
62
|
},
|
|
58
|
-
"scripts": {
|
|
59
|
-
"build": "obuild",
|
|
60
|
-
"dev": "vitest",
|
|
61
|
-
"lint": "oxlint . && oxfmt --check .",
|
|
62
|
-
"lint:fix": "oxlint . --fix && oxfmt .",
|
|
63
|
-
"fmt": "oxfmt .",
|
|
64
|
-
"test": "pnpm lint && pnpm typecheck && vitest run",
|
|
65
|
-
"typecheck": "tsgo --noEmit",
|
|
66
|
-
"release": "pnpm test && pnpm build && bumpp --commit --tag --push --all",
|
|
67
|
-
"prepack": "pnpm build"
|
|
68
|
-
},
|
|
69
63
|
"devDependencies": {
|
|
64
|
+
"@electric-sql/pglite": "^0.4.3",
|
|
70
65
|
"@typescript/native-preview": "7.0.0-dev.20260316.1",
|
|
71
66
|
"@vitest/coverage-v8": "^4.1.1",
|
|
72
67
|
"bumpp": "^11.0.1",
|
|
@@ -75,5 +70,15 @@
|
|
|
75
70
|
"oxlint": "^1.57.0",
|
|
76
71
|
"typescript": "^6.0.2",
|
|
77
72
|
"vitest": "^4.1.1"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"build": "obuild",
|
|
76
|
+
"dev": "vitest",
|
|
77
|
+
"lint": "oxlint . && oxfmt --check .",
|
|
78
|
+
"lint:fix": "oxlint . --fix && oxfmt .",
|
|
79
|
+
"fmt": "oxfmt .",
|
|
80
|
+
"test": "pnpm lint && pnpm typecheck && vitest run",
|
|
81
|
+
"typecheck": "tsgo --noEmit",
|
|
82
|
+
"release": "pnpm test && pnpm build && bumpp --commit --tag --push --all"
|
|
78
83
|
}
|
|
79
|
-
}
|
|
84
|
+
}
|