UNPKG

@omer-x/buttler

Version:

automates CI/CD workflows using Docker and GitHub webhooks

13 lines 58.9 kB
"use strict";exports.id=754,exports.ids=[754],exports.modules={2754:(e,t,i)=>{let s,r;i.d(t,{default:()=>tk});var n=i(76760),l=i.n(n),a=i(87550),o=i.n(a);let u=Symbol.for("drizzle:entityKind");function c(e,t){if(!e||"object"!=typeof e)return!1;if(e instanceof t)return!0;if(!Object.prototype.hasOwnProperty.call(t,u))throw Error(`Class "${t.name??"<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);let i=Object.getPrototypeOf(e).constructor;if(i)for(;i;){if(u in i&&i[u]===t[u])return!0;i=Object.getPrototypeOf(i)}return!1}Symbol.for("drizzle:hasOwnEntityKind");class h{static [u]="ConsoleLogWriter";write(e){console.log(e)}}class d{static [u]="DefaultLogger";writer;constructor(e){this.writer=e?.writer??new h}logQuery(e,t){let i=t.map(e=>{try{return JSON.stringify(e)}catch{return String(e)}}),s=i.length?` -- params: [${i.join(", ")}]`:"";this.writer.write(`Query: ${e}${s}`)}}class f{static [u]="NoopLogger";logQuery(){}}let m=Symbol.for("drizzle:Name"),p=Symbol.for("drizzle:Schema"),g=Symbol.for("drizzle:Columns"),y=Symbol.for("drizzle:ExtraConfigColumns"),b=Symbol.for("drizzle:OriginalName"),w=Symbol.for("drizzle:BaseName"),S=Symbol.for("drizzle:IsAlias"),$=Symbol.for("drizzle:ExtraConfigBuilder"),v=Symbol.for("drizzle:IsDrizzleTable");class N{static [u]="Table";static Symbol={Name:m,Schema:p,OriginalName:b,Columns:g,ExtraConfigColumns:y,BaseName:w,IsAlias:S,ExtraConfigBuilder:$};[m];[b];[p];[g];[y];[w];[S]=!1;[v]=!0;[$]=void 0;constructor(e,t,i){this[m]=this[b]=e,this[p]=t,this[w]=i}}function q(e){return`${e[p]??"public"}.${e[m]}`}class C{constructor(e,t){this.table=e,this.config=t,this.name=t.name,this.keyAsName=t.keyAsName,this.notNull=t.notNull,this.default=t.default,this.defaultFn=t.defaultFn,this.onUpdateFn=t.onUpdateFn,this.hasDefault=t.hasDefault,this.primary=t.primaryKey,this.isUnique=t.isUnique,this.uniqueName=t.uniqueName,this.uniqueType=t.uniqueType,this.dataType=t.dataType,this.columnType=t.columnType,this.generated=t.generated,this.generatedIdentity=t.generatedIdentity}static [u]="Column";name;keyAsName;primary;notNull;default;defaultFn;onUpdateFn;hasDefault;isUnique;uniqueName;uniqueType;dataType;columnType;enumValues=void 0;generated=void 0;generatedIdentity=void 0;config;mapFromDriverValue(e){return e}mapToDriverValue(e){return e}shouldDisableInsert(){return void 0!==this.config.generated&&"byDefault"!==this.config.generated.type}}let Q=Symbol.for("drizzle:PgInlineForeignKeys"),T=Symbol.for("drizzle:EnableRLS");class x extends N{static [u]="PgTable";static Symbol=Object.assign({},N.Symbol,{InlineForeignKeys:Q,EnableRLS:T});[Q]=[];[T]=!1;[N.Symbol.ExtraConfigBuilder]=void 0}class L{static [u]="PgPrimaryKeyBuilder";columns;name;constructor(e,t){this.columns=e,this.name=t}build(e){return new O(e,this.columns,this.name)}}class O{constructor(e,t,i){this.table=e,this.columns=t,this.name=i}static [u]="PgPrimaryKey";columns;name;getName(){return this.name??`${this.table[x.Symbol.Name]}_${this.columns.map(e=>e.name).join("_")}_pk`}}class A{static [u]="ColumnBuilder";config;constructor(e,t,i){this.config={name:e,keyAsName:""===e,notNull:!1,default:void 0,hasDefault:!1,primaryKey:!1,isUnique:!1,uniqueName:void 0,uniqueType:void 0,dataType:t,columnType:i,generated:void 0}}$type(){return this}notNull(){return this.config.notNull=!0,this}default(e){return this.config.default=e,this.config.hasDefault=!0,this}$defaultFn(e){return this.config.defaultFn=e,this.config.hasDefault=!0,this}$default=this.$defaultFn;$onUpdateFn(e){return this.config.onUpdateFn=e,this.config.hasDefault=!0,this}$onUpdate=this.$onUpdateFn;primaryKey(){return this.config.primaryKey=!0,this.config.notNull=!0,this}setName(e){""===this.config.name&&(this.config.name=e)}}class j{static [u]="PgForeignKeyBuilder";reference;_onUpdate="no action";_onDelete="no action";constructor(e,t){this.reference=()=>{let{name:t,columns:i,foreignColumns:s}=e();return{name:t,columns:i,foreignTable:s[0].table,foreignColumns:s}},t&&(this._onUpdate=t.onUpdate,this._onDelete=t.onDelete)}onUpdate(e){return this._onUpdate=void 0===e?"no action":e,this}onDelete(e){return this._onDelete=void 0===e?"no action":e,this}build(e){return new _(e,this)}}class _{constructor(e,t){this.table=e,this.reference=t.reference,this.onUpdate=t._onUpdate,this.onDelete=t._onDelete}static [u]="PgForeignKey";reference;onUpdate;onDelete;getName(){let{name:e,columns:t,foreignColumns:i}=this.reference(),s=t.map(e=>e.name),r=i.map(e=>e.name),n=[this.table[m],...s,i[0].table[m],...r];return e??`${n.join("_")}_fk`}}function B(e,...t){return e(...t)}function F(e,t){return`${e[m]}_${t.join("_")}_unique`}class E{constructor(e,t){this.name=t,this.columns=e}static [u]=null;columns;nullsNotDistinctConfig=!1;nullsNotDistinct(){return this.nullsNotDistinctConfig=!0,this}build(e){return new R(e,this.columns,this.nullsNotDistinctConfig,this.name)}}class P{static [u]=null;name;constructor(e){this.name=e}on(...e){return new E(e,this.name)}}class R{constructor(e,t,i,s){this.table=e,this.columns=t,this.name=s??F(this.table,this.columns.map(e=>e.name)),this.nullsNotDistinct=i}static [u]=null;columns;name;nullsNotDistinct=!1;getName(){return this.name}}function D(e,t,i){for(let s=t;s<e.length;s++){let r=e[s];if("\\"===r){s++;continue}if('"'===r)return[e.slice(t,s).replace(/\\/g,""),s+1];if(!i&&(","===r||"}"===r))return[e.slice(t,s).replace(/\\/g,""),s]}return[e.slice(t).replace(/\\/g,""),e.length]}class z extends A{foreignKeyConfigs=[];static [u]="PgColumnBuilder";array(e){return new K(this.config.name,this,e)}references(e,t={}){return this.foreignKeyConfigs.push({ref:e,actions:t}),this}unique(e,t){return this.config.isUnique=!0,this.config.uniqueName=e,this.config.uniqueType=t?.nulls,this}generatedAlwaysAs(e){return this.config.generated={as:e,type:"always",mode:"stored"},this}buildForeignKeys(e,t){return this.foreignKeyConfigs.map(({ref:i,actions:s})=>B((i,s)=>{let r=new j(()=>({columns:[e],foreignColumns:[i()]}));return s.onUpdate&&r.onUpdate(s.onUpdate),s.onDelete&&r.onDelete(s.onDelete),r.build(t)},i,s))}buildExtraConfigColumn(e){return new k(e,this.config)}}class I extends C{constructor(e,t){t.uniqueName||(t.uniqueName=F(e,[t.name])),super(e,t),this.table=e}static [u]="PgColumn"}class k extends I{static [u]="ExtraConfigColumn";getSQLType(){return this.getSQLType()}indexConfig={order:this.config.order??"asc",nulls:this.config.nulls??"last",opClass:this.config.opClass};defaultConfig={order:"asc",nulls:"last",opClass:void 0};asc(){return this.indexConfig.order="asc",this}desc(){return this.indexConfig.order="desc",this}nullsFirst(){return this.indexConfig.nulls="first",this}nullsLast(){return this.indexConfig.nulls="last",this}op(e){return this.indexConfig.opClass=e,this}}class M{static [u]=null;constructor(e,t,i,s){this.name=e,this.keyAsName=t,this.type=i,this.indexConfig=s}name;keyAsName;type;indexConfig}class K extends z{static [u]="PgArrayBuilder";constructor(e,t,i){super(e,"array","PgArray"),this.config.baseBuilder=t,this.config.size=i}build(e){let t=this.config.baseBuilder.build(e);return new U(e,this.config,t)}}class U extends I{constructor(e,t,i,s){super(e,t),this.baseColumn=i,this.range=s,this.size=t.size}size;static [u]="PgArray";getSQLType(){return`${this.baseColumn.getSQLType()}[${"number"==typeof this.size?this.size:""}]`}mapFromDriverValue(e){return"string"==typeof e&&(e=function(e){let[t]=function e(t,i=0){let s=[],r=i,n=!1;for(;r<t.length;){let l=t[r];if(","===l){(n||r===i)&&s.push(""),n=!0,r++;continue}if(n=!1,"\\"===l){r+=2;continue}if('"'===l){let[e,i]=D(t,r+1,!0);s.push(e),r=i;continue}if("}"===l)return[s,r+1];if("{"===l){let[i,n]=e(t,r+1);s.push(i),r=n;continue}let[a,o]=D(t,r,!1);s.push(a),r=o}return[s,r]}(e,1);return t}(e)),e.map(e=>this.baseColumn.mapFromDriverValue(e))}mapToDriverValue(e,t=!1){let i=e.map(e=>null===e?null:c(this.baseColumn,U)?this.baseColumn.mapToDriverValue(e,!0):this.baseColumn.mapToDriverValue(e));return t?i:function e(t){return`{${t.map(t=>Array.isArray(t)?e(t):"string"==typeof t?`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:`${t}`).join(",")}}`}(i)}}let V=Symbol.for("drizzle:isPgEnum");class J extends z{static [u]="PgEnumColumnBuilder";constructor(e,t){super(e,"string","PgEnumColumn"),this.config.enum=t}build(e){return new W(e,this.config)}}class W extends I{static [u]="PgEnumColumn";enum=this.config.enum;enumValues=this.config.enum.enumValues;constructor(e,t){super(e,t),this.enum=t.enum}getSQLType(){return this.enum.enumName}}class Y{static [u]="Subquery";constructor(e,t,i,s=!1){this._={brand:"Subquery",sql:e,selectedFields:t,alias:i,isWith:s}}}class G extends Y{static [u]="WithSubquery"}let Z={startActiveSpan:(e,t)=>s?(r||(r=s.trace.getTracer("drizzle-orm","0.37.0")),B((i,s)=>s.startActiveSpan(e,e=>{try{return t(e)}catch(t){throw e.setStatus({code:i.SpanStatusCode.ERROR,message:t instanceof Error?t.message:"Unknown error"}),t}finally{e.end()}}),s,r)):t()},H=Symbol.for("drizzle:ViewBaseConfig");class X{static [u]=null}function ee(e){return null!=e&&"function"==typeof e.getSQL}class et{static [u]="StringChunk";value;constructor(e){this.value=Array.isArray(e)?e:[e]}getSQL(){return new ei([this])}}class ei{constructor(e){this.queryChunks=e}static [u]="SQL";decoder=er;shouldInlineParams=!1;append(e){return this.queryChunks.push(...e.queryChunks),this}toQuery(e){return Z.startActiveSpan("drizzle.buildSQL",t=>{let i=this.buildQueryFromSourceParams(this.queryChunks,e);return t?.setAttributes({"drizzle.query.text":i.sql,"drizzle.query.params":JSON.stringify(i.params)}),i})}buildQueryFromSourceParams(e,t){let i=Object.assign({},t,{inlineParams:t.inlineParams||this.shouldInlineParams,paramStartIndex:t.paramStartIndex||{value:0}}),{casing:s,escapeName:r,escapeParam:n,prepareTyping:l,inlineParams:a,paramStartIndex:o}=i;var u=e.map(e=>{if(c(e,et))return{sql:e.value.join(""),params:[]};if(c(e,es))return{sql:r(e.value),params:[]};if(void 0===e)return{sql:"",params:[]};if(Array.isArray(e)){let t=[new et("(")];for(let[i,s]of e.entries())t.push(s),i<e.length-1&&t.push(new et(", "));return t.push(new et(")")),this.buildQueryFromSourceParams(t,i)}if(c(e,ei))return this.buildQueryFromSourceParams(e.queryChunks,{...i,inlineParams:a||e.shouldInlineParams});if(c(e,N)){let t=e[N.Symbol.Schema],i=e[N.Symbol.Name];return{sql:void 0===t?r(i):r(t)+"."+r(i),params:[]}}if(c(e,C)){let i=s.getColumnCasing(e);if("indexes"===t.invokeSource)return{sql:r(i),params:[]};let n=e.table[N.Symbol.Schema];return{sql:e.table[S]||void 0===n?r(e.table[N.Symbol.Name])+"."+r(i):r(n)+"."+r(e.table[N.Symbol.Name])+"."+r(i),params:[]}}if(c(e,ec)){let t=e[H].schema,i=e[H].name;return{sql:void 0===t?r(i):r(t)+"."+r(i),params:[]}}if(c(e,el)){if(c(e.value,eo))return{sql:n(o.value++,e),params:[e],typings:["none"]};let t=null===e.value?null:e.encoder.mapToDriverValue(e.value);if(c(t,ei))return this.buildQueryFromSourceParams([t],i);if(a)return{sql:this.mapInlineParam(t,i),params:[]};let s=["none"];return l&&(s=[l(e.encoder)]),{sql:n(o.value++,t),params:[t],typings:s}}return c(e,eo)?{sql:n(o.value++,e),params:[e],typings:["none"]}:c(e,ei.Aliased)&&void 0!==e.fieldAlias?{sql:r(e.fieldAlias),params:[]}:c(e,Y)?e._.isWith?{sql:r(e._.alias),params:[]}:this.buildQueryFromSourceParams([new et("("),e._.sql,new et(") "),new es(e._.alias)],i):e&&"function"==typeof e&&V in e&&!0===e[V]?e.schema?{sql:r(e.schema)+"."+r(e.enumName),params:[]}:{sql:r(e.enumName),params:[]}:ee(e)?e.shouldOmitSQLParens?.()?this.buildQueryFromSourceParams([e.getSQL()],i):this.buildQueryFromSourceParams([new et("("),e.getSQL(),new et(")")],i):a?{sql:this.mapInlineParam(e,i),params:[]}:{sql:n(o.value++,e),params:[e],typings:["none"]}});let h={sql:"",params:[]};for(let e of u)h.sql+=e.sql,h.params.push(...e.params),e.typings?.length&&(h.typings||(h.typings=[]),h.typings.push(...e.typings));return h}mapInlineParam(e,{escapeString:t}){if(null===e)return"null";if("number"==typeof e||"boolean"==typeof e)return e.toString();if("string"==typeof e)return t(e);if("object"==typeof e){let i=e.toString();return"[object Object]"===i?t(JSON.stringify(e)):t(i)}throw Error("Unexpected param value: "+e)}getSQL(){return this}as(e){return void 0===e?this:new ei.Aliased(this,e)}mapWith(e){return this.decoder="function"==typeof e?{mapFromDriverValue:e}:e,this}inlineParams(){return this.shouldInlineParams=!0,this}if(e){return e?this:void 0}}class es{constructor(e){this.value=e}static [u]="Name";brand;getSQL(){return new ei([this])}}let er={mapFromDriverValue:e=>e},en={mapToDriverValue:e=>e};({...er,...en});class el{constructor(e,t=en){this.value=e,this.encoder=t}static [u]="Param";brand;getSQL(){return new ei([this])}}function ea(e,...t){let i=[];for(let[s,r]of((t.length>0||e.length>0&&""!==e[0])&&i.push(new et(e[0])),t.entries()))i.push(r,new et(e[s+1]));return new ei(i)}(e=>{e.empty=function(){return new ei([])},e.fromList=function(e){return new ei(e)},e.raw=function(e){return new ei([new et(e)])},e.join=function(e,t){let i=[];for(let[s,r]of e.entries())s>0&&void 0!==t&&i.push(t),i.push(r);return new ei(i)},e.identifier=function(e){return new es(e)},e.placeholder=function(e){return new eo(e)},e.param=function(e,t){return new el(e,t)}})(ea||(ea={})),(e=>{class t{constructor(e,t){this.sql=e,this.fieldAlias=t}static [u]="SQL.Aliased";isSelectionField=!1;getSQL(){return this.sql}clone(){return new t(this.sql,this.fieldAlias)}}e.Aliased=t})(ei||(ei={}));class eo{constructor(e){this.name=e}static [u]="Placeholder";getSQL(){return new ei([this])}}function eu(e,t){return e.map(e=>{if(c(e,eo)){if(!(e.name in t))throw Error(`No value for placeholder "${e.name}" was provided`);return t[e.name]}if(c(e,el)&&c(e.value,eo)){if(!(e.value.name in t))throw Error(`No value for placeholder "${e.value.name}" was provided`);return e.encoder.mapToDriverValue(t[e.value.name])}return e})}class ec{static [u]="View";[H];constructor({name:e,schema:t,selectedFields:i,query:s}){this[H]={name:e,originalName:e,schema:t,selectedFields:i,query:s,isExisting:!s,isAlias:!1}}getSQL(){return new ei([this])}}function eh(e,t){return"object"!=typeof t||null===t||!("mapToDriverValue"in t)||"function"!=typeof t.mapToDriverValue||ee(e)||c(e,el)||c(e,eo)||c(e,C)||c(e,N)||c(e,ec)?e:new el(e,t)}C.prototype.getSQL=function(){return new ei([this])},N.prototype.getSQL=function(){return new ei([this])},Y.prototype.getSQL=function(){return new ei([this])};let ed=(e,t)=>ea`${e} = ${eh(t,e)}`,ef=(e,t)=>ea`${e} <> ${eh(t,e)}`;function em(...e){let t=e.filter(e=>void 0!==e);if(0!==t.length)return new ei(1===t.length?t:[new et("("),ea.join(t,new et(" and ")),new et(")")])}function ep(...e){let t=e.filter(e=>void 0!==e);if(0!==t.length)return new ei(1===t.length?t:[new et("("),ea.join(t,new et(" or ")),new et(")")])}function eg(e){return ea`not ${e}`}let ey=(e,t)=>ea`${e} > ${eh(t,e)}`,eb=(e,t)=>ea`${e} >= ${eh(t,e)}`,ew=(e,t)=>ea`${e} < ${eh(t,e)}`,eS=(e,t)=>ea`${e} <= ${eh(t,e)}`;function e$(e,t){return Array.isArray(t)?0===t.length?ea`false`:ea`${e} in ${t.map(t=>eh(t,e))}`:ea`${e} in ${eh(t,e)}`}function ev(e,t){return Array.isArray(t)?0===t.length?ea`true`:ea`${e} not in ${t.map(t=>eh(t,e))}`:ea`${e} not in ${eh(t,e)}`}function eN(e){return ea`${e} is null`}function eq(e){return ea`${e} is not null`}function eC(e){return ea`exists ${e}`}function eQ(e){return ea`not exists ${e}`}function eT(e,t,i){return ea`${e} between ${eh(t,e)} and ${eh(i,e)}`}function ex(e,t,i){return ea`${e} not between ${eh(t,e)} and ${eh(i,e)}`}function eL(e,t){return ea`${e} like ${t}`}function eO(e,t){return ea`${e} not like ${t}`}function eA(e,t){return ea`${e} ilike ${t}`}function ej(e,t){return ea`${e} not ilike ${t}`}function e_(e){return ea`${e} asc`}function eB(e){return ea`${e} desc`}class eF{constructor(e,t,i){this.sourceTable=e,this.referencedTable=t,this.relationName=i,this.referencedTableName=t[N.Symbol.Name]}static [u]="Relation";referencedTableName;fieldName}class eE{constructor(e,t){this.table=e,this.config=t}static [u]="Relations"}class eP extends eF{constructor(e,t,i,s){super(e,t,i?.relationName),this.config=i,this.isNullable=s}static [u]="One";withFieldName(e){let t=new eP(this.sourceTable,this.referencedTable,this.config,this.isNullable);return t.fieldName=e,t}}class eR extends eF{constructor(e,t,i){super(e,t,i?.relationName),this.config=i}static [u]="Many";withFieldName(e){let t=new eR(this.sourceTable,this.referencedTable,this.config);return t.fieldName=e,t}}function eD(e){return{one:function(t,i){return new eP(e,t,i,i?.fields.reduce((e,t)=>e&&t.notNull,!0)??!1)},many:function(t,i){return new eR(e,t,i)}}}class ez{constructor(e){this.table=e}static [u]="ColumnAliasProxyHandler";get(e,t){return"table"===t?this.table:e[t]}}class eI{constructor(e,t){this.alias=e,this.replaceOriginalName=t}static [u]="TableAliasProxyHandler";get(e,t){if(t===N.Symbol.IsAlias)return!0;if(t===N.Symbol.Name||this.replaceOriginalName&&t===N.Symbol.OriginalName)return this.alias;if(t===H)return{...e[H],name:this.alias,isAlias:!0};if(t===N.Symbol.Columns){let t=e[N.Symbol.Columns];if(!t)return t;let i={};return Object.keys(t).map(s=>{i[s]=new Proxy(t[s],new ez(new Proxy(e,this)))}),i}let i=e[t];return c(i,C)?new Proxy(i,new ez(new Proxy(e,this))):i}}class ek{constructor(e){this.alias=e}static [u]=null;get(e,t){return"sourceTable"===t?eM(e.sourceTable,this.alias):e[t]}}function eM(e,t){return new Proxy(e,new eI(t,!1))}function eK(e,t){return new Proxy(e,new ez(new Proxy(e.table,new eI(t,!1))))}function eU(e,t){return new ei.Aliased(eV(e.sql,t),e.fieldAlias)}function eV(e,t){return ea.join(e.queryChunks.map(e=>c(e,C)?eK(e,t):c(e,ei)?eV(e,t):c(e,ei.Aliased)?eU(e,t):e))}class eJ{static [u]="SelectionProxyHandler";config;constructor(e){this.config={...e}}get(e,t){if("_"===t)return{...e._,selectedFields:new Proxy(e._.selectedFields,this)};if(t===H)return{...e[H],selectedFields:new Proxy(e[H].selectedFields,this)};if("symbol"==typeof t)return e[t];let i=(c(e,Y)?e._.selectedFields:c(e,ec)?e[H].selectedFields:e)[t];if(c(i,ei.Aliased)){if("sql"===this.config.sqlAliasedBehavior&&!i.isSelectionField)return i.sql;let e=i.clone();return e.isSelectionField=!0,e}if(c(i,ei)){if("sql"===this.config.sqlBehavior)return i;throw Error(`You tried to reference "${t}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`)}return c(i,C)?this.config.alias?new Proxy(i,new ez(new Proxy(i.table,new eI(this.config.alias,this.config.replaceOriginalName??!1)))):i:"object"!=typeof i||null===i?i:new Proxy(i,new eJ(this.config))}}function eW(e){return(e.replace(/['\u2019]/g,"").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).map(e=>e.toLowerCase()).join("_")}function eY(e){return(e.replace(/['\u2019]/g,"").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).reduce((e,t,i)=>e+(0===i?t.toLowerCase():`${t[0].toUpperCase()}${t.slice(1)}`),"")}function eG(e){return e}class eZ{static [u]="CasingCache";cache={};cachedTables={};convert;constructor(e){this.convert="snake_case"===e?eW:"camelCase"===e?eY:eG}getColumnCasing(e){if(!e.keyAsName)return e.name;let t=e.table[N.Symbol.Schema]??"public",i=e.table[N.Symbol.OriginalName],s=`${t}.${i}.${e.name}`;return this.cache[s]||this.cacheTable(e.table),this.cache[s]}cacheTable(e){let t=e[N.Symbol.Schema]??"public",i=e[N.Symbol.OriginalName],s=`${t}.${i}`;if(!this.cachedTables[s]){for(let t of Object.values(e[N.Symbol.Columns])){let e=`${s}.${t.name}`;this.cache[e]=this.convert(t.name)}this.cachedTables[s]=!0}}clearCache(){this.cache={},this.cachedTables={}}}class eH extends Error{static [u]="DrizzleError";constructor({message:e,cause:t}){super(e),this.name="DrizzleError",this.cause=t}}class eX extends eH{static [u]="TransactionRollbackError";constructor(){super({message:"Rollback"})}}function e0(e,t){return`${e[m]}_${t.join("_")}_unique`}class e1{constructor(e,t){this.name=t,this.columns=e}static [u]=null;columns;build(e){return new e2(e,this.columns,this.name)}}class e7{static [u]=null;name;constructor(e){this.name=e}on(...e){return new e1(e,this.name)}}class e2{constructor(e,t,i){this.table=e,this.columns=t,this.name=i??e0(this.table,this.columns.map(e=>e.name))}static [u]=null;columns;name;getName(){return this.name}}class e5 extends null{static [u]=null;foreignKeyConfigs=[];references(e,t={}){return this.foreignKeyConfigs.push({ref:e,actions:t}),this}unique(e){return this.config.isUnique=!0,this.config.uniqueName=e,this}generatedAlwaysAs(e,t){return this.config.generated={as:e,type:"always",mode:t?.mode??"virtual"},this}buildForeignKeys(e,t){return this.foreignKeyConfigs.map(({ref:i,actions:s})=>((i,s)=>{let r=new ForeignKeyBuilder(()=>({columns:[e],foreignColumns:[i()]}));return s.onUpdate&&r.onUpdate(s.onUpdate),s.onDelete&&r.onDelete(s.onDelete),r.build(t)})(i,s))}}class e4 extends C{constructor(e,t){t.uniqueName||(t.uniqueName=e0(e,[t.name])),super(e,t),this.table=e}static [u]="SQLiteColumn"}let e3=Symbol.for("drizzle:SQLiteInlineForeignKeys");class e6 extends N{static [u]="SQLiteTable";static Symbol=Object.assign({},N.Symbol,{InlineForeignKeys:e3});[N.Symbol.Columns];[e3]=[];[N.Symbol.ExtraConfigBuilder]=void 0}function e9(e,t,i){let s={},r=e.reduce((e,{path:r,field:n},l)=>{let a;a=c(n,C)?n:c(n,ei)?n.decoder:n.sql.decoder;let o=e;for(let[e,u]of r.entries())if(e<r.length-1)u in o||(o[u]={}),o=o[u];else{let e=t[l],h=o[u]=null===e?null:a.mapFromDriverValue(e);if(i&&c(n,C)&&2===r.length){let e=r[0];e in s?"string"==typeof s[e]&&s[e]!==n.table[m]&&(s[e]=!1):s[e]=null===h&&n.table[m]}}return e},{});if(i&&Object.keys(s).length>0)for(let[e,t]of Object.entries(s))"string"!=typeof t||i[t]||(r[e]=null);return r}function e8(e,t){return Object.entries(e).reduce((e,[i,s])=>{if("string"!=typeof i)return e;let r=t?[...t,i]:[i];return c(s,C)||c(s,ei)||c(s,ei.Aliased)?e.push({path:r,field:s}):c(s,N)?e.push(...e8(s[N.Symbol.Columns],r)):e.push(...e8(s,r)),e},[])}function te(e,t){let i=Object.keys(e),s=Object.keys(t);if(i.length!==s.length)return!1;for(let[e,t]of i.entries())if(t!==s[e])return!1;return!0}function tt(e,t){let i=Object.entries(t).filter(([,e])=>void 0!==e).map(([t,i])=>c(i,ei)||c(i,C)?[t,i]:[t,new el(i,e[N.Symbol.Columns][t])]);if(0===i.length)throw Error("No values to set");return Object.fromEntries(i)}function ti(e){return c(e,Y)?e._.alias:c(e,ec)?e[H].name:c(e,ei)?void 0:e[N.Symbol.IsAlias]?e[N.Symbol.Name]:e[N.Symbol.BaseName]}class ts extends ec{static [u]="SQLiteViewBase"}class tr{static [u]="SQLiteDialect";casing;constructor(e){this.casing=new eZ(e?.casing)}escapeName(e){return`"${e}"`}escapeParam(e){return"?"}escapeString(e){return`'${e.replace(/'/g,"''")}'`}buildWithCTE(e){if(!e?.length)return;let t=[ea`with `];for(let[i,s]of e.entries())t.push(ea`${ea.identifier(s._.alias)} as (${s._.sql})`),i<e.length-1&&t.push(ea`, `);return t.push(ea` `),ea.join(t)}buildDeleteQuery({table:e,where:t,returning:i,withList:s,limit:r,orderBy:n}){let l=this.buildWithCTE(s),a=i?ea` returning ${this.buildSelection(i,{isSingleTable:!0})}`:void 0,o=t?ea` where ${t}`:void 0,u=this.buildOrderBy(n),c=this.buildLimit(r);return ea`${l}delete from ${e}${o}${a}${u}${c}`}buildUpdateSet(e,t){let i=e[N.Symbol.Columns],s=Object.keys(i).filter(e=>void 0!==t[e]||i[e]?.onUpdateFn!==void 0),r=s.length;return ea.join(s.flatMap((e,s)=>{let n=i[e],l=t[e]??ea.param(n.onUpdateFn(),n),a=ea`${ea.identifier(this.casing.getColumnCasing(n))} = ${l}`;return s<r-1?[a,ea.raw(", ")]:[a]}))}buildUpdateQuery({table:e,set:t,where:i,returning:s,withList:r,joins:n,from:l,limit:a,orderBy:o}){let u=this.buildWithCTE(r),c=this.buildUpdateSet(e,t),h=l&&ea.join([ea.raw(" from "),this.buildFromTable(l)]),d=this.buildJoins(n),f=s?ea` returning ${this.buildSelection(s,{isSingleTable:!0})}`:void 0,m=i?ea` where ${i}`:void 0,p=this.buildOrderBy(o),g=this.buildLimit(a);return ea`${u}update ${e} set ${c}${h}${d}${m}${f}${p}${g}`}buildSelection(e,{isSingleTable:t=!1}={}){let i=e.length,s=e.flatMap(({field:e},s)=>{let r=[];if(c(e,ei.Aliased)&&e.isSelectionField)r.push(ea.identifier(e.fieldAlias));else if(c(e,ei.Aliased)||c(e,ei)){let i=c(e,ei.Aliased)?e.sql:e;t?r.push(new ei(i.queryChunks.map(e=>c(e,C)?ea.identifier(this.casing.getColumnCasing(e)):e))):r.push(i),c(e,ei.Aliased)&&r.push(ea` as ${ea.identifier(e.fieldAlias)}`)}else if(c(e,C)){let i=e.table[N.Symbol.Name];t?r.push(ea.identifier(this.casing.getColumnCasing(e))):r.push(ea`${ea.identifier(i)}.${ea.identifier(this.casing.getColumnCasing(e))}`)}return s<i-1&&r.push(ea`, `),r});return ea.join(s)}buildJoins(e){if(!e||0===e.length)return;let t=[];if(e)for(let[i,s]of e.entries()){0===i&&t.push(ea` `);let r=s.table;if(c(r,e6)){let e=r[e6.Symbol.Name],i=r[e6.Symbol.Schema],n=r[e6.Symbol.OriginalName],l=e===n?void 0:s.alias;t.push(ea`${ea.raw(s.joinType)} join ${i?ea`${ea.identifier(i)}.`:void 0}${ea.identifier(n)}${l&&ea` ${ea.identifier(l)}`} on ${s.on}`)}else t.push(ea`${ea.raw(s.joinType)} join ${r} on ${s.on}`);i<e.length-1&&t.push(ea` `)}return ea.join(t)}buildLimit(e){return"object"==typeof e||"number"==typeof e&&e>=0?ea` limit ${e}`:void 0}buildOrderBy(e){let t=[];if(e)for(let[i,s]of e.entries())t.push(s),i<e.length-1&&t.push(ea`, `);return t.length>0?ea` order by ${ea.join(t)}`:void 0}buildFromTable(e){return c(e,N)&&e[N.Symbol.OriginalName]!==e[N.Symbol.Name]?ea`${ea.identifier(e[N.Symbol.OriginalName])} ${ea.identifier(e[N.Symbol.Name])}`:e}buildSelectQuery({withList:e,fields:t,fieldsFlat:i,where:s,having:r,table:n,joins:l,orderBy:a,groupBy:o,limit:u,offset:h,distinct:d,setOperators:f}){let p=i??e8(t);for(let e of p){let t;if(c(e.field,C)&&e.field.table[m]!==(c(n,Y)?n._.alias:c(n,ts)?n[H].name:c(n,ei)?void 0:n[m])&&(t=e.field.table,!l?.some(({alias:e})=>e===(t[N.Symbol.IsAlias]?t[m]:t[N.Symbol.BaseName])))){let t=e.field.table[m];throw Error(`Your "${e.path.join("->")}" field references a column "${t}"."${e.field.name}", but the table "${t}" is not part of the query! Did you forget to join it?`)}}let g=!l||0===l.length,y=this.buildWithCTE(e),b=d?ea` distinct`:void 0,w=this.buildSelection(p,{isSingleTable:g}),S=this.buildFromTable(n),$=this.buildJoins(l),v=s?ea` where ${s}`:void 0,q=r?ea` having ${r}`:void 0,Q=[];if(o)for(let[e,t]of o.entries())Q.push(t),e<o.length-1&&Q.push(ea`, `);let T=Q.length>0?ea` group by ${ea.join(Q)}`:void 0,x=this.buildOrderBy(a),L=this.buildLimit(u),O=h?ea` offset ${h}`:void 0,A=ea`${y}select${b} ${w} from ${S}${$}${v}${T}${q}${x}${L}${O}`;return f.length>0?this.buildSetOperations(A,f):A}buildSetOperations(e,t){let[i,...s]=t;if(!i)throw Error("Cannot pass undefined values to any set operator");return 0===s.length?this.buildSetOperationQuery({leftSelect:e,setOperator:i}):this.buildSetOperations(this.buildSetOperationQuery({leftSelect:e,setOperator:i}),s)}buildSetOperationQuery({leftSelect:e,setOperator:{type:t,isAll:i,rightSelect:s,limit:r,orderBy:n,offset:l}}){let a,o=ea`${e.getSQL()} `,u=ea`${s.getSQL()}`;if(n&&n.length>0){let e=[];for(let t of n)if(c(t,e4))e.push(ea.identifier(t.name));else if(c(t,ei)){for(let e=0;e<t.queryChunks.length;e++){let i=t.queryChunks[e];c(i,e4)&&(t.queryChunks[e]=ea.identifier(this.casing.getColumnCasing(i)))}e.push(ea`${t}`)}else e.push(ea`${t}`);a=ea` order by ${ea.join(e,ea`, `)}`}let h="object"==typeof r||"number"==typeof r&&r>=0?ea` limit ${r}`:void 0,d=ea.raw(`${t} ${i?"all ":""}`),f=l?ea` offset ${l}`:void 0;return ea`${o}${d}${u}${a}${h}${f}`}buildInsertQuery({table:e,values:t,onConflict:i,returning:s,withList:r,select:n}){let l=[],a=Object.entries(e[N.Symbol.Columns]).filter(([e,t])=>!t.shouldDisableInsert()),o=a.map(([,e])=>ea.identifier(this.casing.getColumnCasing(e)));if(n)c(t,ei)?l.push(t):l.push(t.getSQL());else for(let[e,i]of(l.push(ea.raw("values ")),t.entries())){let s=[];for(let[e,t]of a){let r=i[e];if(void 0===r||c(r,el)&&void 0===r.value){let e;if(null!==t.default&&void 0!==t.default)e=c(t.default,ei)?t.default:ea.param(t.default,t);else if(void 0!==t.defaultFn){let i=t.defaultFn();e=c(i,ei)?i:ea.param(i,t)}else if(t.default||void 0===t.onUpdateFn)e=ea`null`;else{let i=t.onUpdateFn();e=c(i,ei)?i:ea.param(i,t)}s.push(e)}else s.push(r)}l.push(s),e<t.length-1&&l.push(ea`, `)}let u=this.buildWithCTE(r),h=ea.join(l),d=s?ea` returning ${this.buildSelection(s,{isSingleTable:!0})}`:void 0,f=i?ea` on conflict ${i}`:void 0;return ea`${u}insert into ${e} ${o} ${h}${f}${d}`}sqlToQuery(e,t){return e.toQuery({casing:this.casing,escapeName:this.escapeName,escapeParam:this.escapeParam,escapeString:this.escapeString,invokeSource:t})}buildRelationalQuery({fullSchema:e,schema:t,tableNamesMap:i,table:s,tableConfig:r,queryConfig:n,tableAlias:l,nestedQueryRelation:a,joinOn:o}){let u,h=[],d,f,m=[],p,g=[];if(!0===n)h=Object.entries(r.columns).map(([e,t])=>({dbKey:t.name,tsKey:e,field:eK(t,l),relationTableTsKey:void 0,isJson:!1,selection:[]}));else{let s=Object.fromEntries(Object.entries(r.columns).map(([e,t])=>[e,eK(t,l)]));if(n.where){let e="function"==typeof n.where?n.where(s,{and:em,between:eT,eq:ed,exists:eC,gt:ey,gte:eb,ilike:eA,inArray:e$,isNull:eN,isNotNull:eq,like:eL,lt:ew,lte:eS,ne:ef,not:eg,notBetween:ex,notExists:eQ,notLike:eO,notIlike:ej,notInArray:ev,or:ep,sql:ea}):n.where;p=e&&eV(e,l)}let a=[],o=[];if(n.columns){let e=!1;for(let[t,i]of Object.entries(n.columns))void 0!==i&&t in r.columns&&(e||!0!==i||(e=!0),o.push(t));o.length>0&&(o=e?o.filter(e=>n.columns?.[e]===!0):Object.keys(r.columns).filter(e=>!o.includes(e)))}else o=Object.keys(r.columns);for(let e of o){let t=r.columns[e];a.push({tsKey:e,value:t})}let u=[];if(n.with&&(u=Object.entries(n.with).filter(e=>!!e[1]).map(([e,t])=>({tsKey:e,queryConfig:t,relation:r.relations[e]}))),n.extras)for(let[e,t]of Object.entries("function"==typeof n.extras?n.extras(s,{sql:ea}):n.extras))a.push({tsKey:e,value:eU(t,l)});for(let{tsKey:e,value:t}of a)h.push({dbKey:c(t,ei.Aliased)?t.fieldAlias:r.columns[e].name,tsKey:e,field:c(t,C)?eK(t,l):t,relationTableTsKey:void 0,isJson:!1,selection:[]});let g="function"==typeof n.orderBy?n.orderBy(s,{sql:ea,asc:e_,desc:eB}):n.orderBy??[];for(let{tsKey:s,queryConfig:r,relation:a}of(Array.isArray(g)||(g=[g]),m=g.map(e=>c(e,C)?eK(e,l):eV(e,l)),d=n.limit,f=n.offset,u)){let n=function(e,t,i){if(c(i,eP)&&i.config)return{fields:i.config.fields,references:i.config.references};let s=t[q(i.referencedTable)];if(!s)throw Error(`Table "${i.referencedTable[N.Symbol.Name]}" not found in schema`);let r=e[s];if(!r)throw Error(`Table "${s}" not found in schema`);let n=i.sourceTable,l=t[q(n)];if(!l)throw Error(`Table "${n[N.Symbol.Name]}" not found in schema`);let a=[];for(let e of Object.values(r.relations))(i.relationName&&i!==e&&e.relationName===i.relationName||!i.relationName&&e.referencedTable===i.sourceTable)&&a.push(e);if(a.length>1)throw i.relationName?Error(`There are multiple relations with name "${i.relationName}" in table "${s}"`):Error(`There are multiple relations between "${s}" and "${i.sourceTable[N.Symbol.Name]}". Please specify relation name`);if(a[0]&&c(a[0],eP)&&a[0].config)return{fields:a[0].config.references,references:a[0].config.fields};throw Error(`There is not enough information to infer relation "${l}.${i.fieldName}"`)}(t,i,a),o=i[q(a.referencedTable)],u=`${l}_${s}`,d=em(...n.fields.map((e,t)=>ed(eK(n.references[t],u),eK(e,l)))),f=this.buildRelationalQuery({fullSchema:e,schema:t,tableNamesMap:i,table:e[o],tableConfig:t[o],queryConfig:c(a,eP)?!0===r?{limit:1}:{...r,limit:1}:r,tableAlias:u,joinOn:d,nestedQueryRelation:a}),m=ea`(${f.sql})`.as(s);h.push({dbKey:s,tsKey:s,field:m,relationTableTsKey:o,isJson:!0,selection:f.selection})}}if(0===h.length)throw new eH({message:`No fields selected for table "${r.tsName}" ("${l}"). You need to have at least one item in "columns", "with" or "extras". If you need to select all columns, omit the "columns" key or set it to undefined.`});if(p=em(o,p),a){let e=ea`json_array(${ea.join(h.map(({field:e})=>c(e,e4)?ea.identifier(this.casing.getColumnCasing(e)):c(e,ei.Aliased)?e.sql:e),ea`, `)})`;c(a,eR)&&(e=ea`coalesce(json_group_array(${e}), json_array())`);let t=[{dbKey:"data",tsKey:"data",field:e.as("data"),isJson:!0,relationTableTsKey:r.tsName,selection:h}];void 0!==d||void 0!==f||m.length>0?(u=this.buildSelectQuery({table:eM(s,l),fields:{},fieldsFlat:[{path:[],field:ea.raw("*")}],where:p,limit:d,offset:f,orderBy:m,setOperators:[]}),p=void 0,d=void 0,f=void 0,m=void 0):u=eM(s,l),u=this.buildSelectQuery({table:c(u,e6)?u:new Y(u,{},l),fields:{},fieldsFlat:t.map(({field:e})=>({path:[],field:c(e,C)?eK(e,l):e})),joins:g,where:p,limit:d,offset:f,orderBy:m,setOperators:[]})}else u=this.buildSelectQuery({table:eM(s,l),fields:{},fieldsFlat:h.map(({field:e})=>({path:[],field:c(e,C)?eK(e,l):e})),joins:g,where:p,limit:d,offset:f,orderBy:m,setOperators:[]});return{tableTsKey:r.tsName,sql:u,selection:h}}}class tn extends tr{static [u]="SQLiteSyncDialect";migrate(e,t,i){let s=void 0===i||"string"==typeof i?"__drizzle_migrations":i.migrationsTable??"__drizzle_migrations",r=ea` CREATE TABLE IF NOT EXISTS ${ea.identifier(s)} ( id SERIAL PRIMARY KEY, hash text NOT NULL, created_at numeric ) `;t.run(r);let n=t.values(ea`SELECT id, hash, created_at FROM ${ea.identifier(s)} ORDER BY created_at DESC LIMIT 1`)[0]??void 0;t.run(ea`BEGIN`);try{for(let i of e)if(!n||Number(n[2])<i.folderMillis){for(let e of i.sql)t.run(ea.raw(e));t.run(ea`INSERT INTO ${ea.identifier(s)} ("hash", "created_at") VALUES(${i.hash}, ${i.folderMillis})`)}t.run(ea`COMMIT`)}catch(e){throw t.run(ea`ROLLBACK`),e}}}class tl extends null{static [u]=null;async migrate(e,t,i){let s=void 0===i||"string"==typeof i?"__drizzle_migrations":i.migrationsTable??"__drizzle_migrations",r=sql` CREATE TABLE IF NOT EXISTS ${sql.identifier(s)} ( id SERIAL PRIMARY KEY, hash text NOT NULL, created_at numeric ) `;await t.run(r);let n=(await t.values(sql`SELECT id, hash, created_at FROM ${sql.identifier(s)} ORDER BY created_at DESC LIMIT 1`))[0]??void 0;await t.transaction(async t=>{for(let i of e)if(!n||Number(n[2])<i.folderMillis){for(let e of i.sql)await t.run(sql.raw(e));await t.run(sql`INSERT INTO ${sql.identifier(s)} ("hash", "created_at") VALUES(${i.hash}, ${i.folderMillis})`)}})}}class ta{static [u]="TypedQueryBuilder";getSelectedFields(){return this._.selectedFields}}class to{static [u]="QueryPromise";[Symbol.toStringTag]="QueryPromise";catch(e){return this.then(void 0,e)}finally(e){return this.then(t=>(e?.(),t),t=>{throw e?.(),t})}then(e,t){return this.execute().then(e,t)}}class tu{static [u]="SQLiteSelectBuilder";fields;session;dialect;withList;distinct;constructor(e){this.fields=e.fields,this.session=e.session,this.dialect=e.dialect,this.withList=e.withList,this.distinct=e.distinct}from(e){let t,i=!!this.fields;return t=this.fields?this.fields:c(e,Y)?Object.fromEntries(Object.keys(e._.selectedFields).map(t=>[t,e[t]])):c(e,ts)?e[H].selectedFields:c(e,ei)?{}:e[N.Symbol.Columns],new th({table:e,fields:t,isPartialSelect:i,session:this.session,dialect:this.dialect,withList:this.withList,distinct:this.distinct})}}class tc extends ta{static [u]="SQLiteSelectQueryBuilder";_;config;joinsNotNullableMap;tableName;isPartialSelect;session;dialect;constructor({table:e,fields:t,isPartialSelect:i,session:s,dialect:r,withList:n,distinct:l}){super(),this.config={withList:n,table:e,fields:{...t},distinct:l,setOperators:[]},this.isPartialSelect=i,this.session=s,this.dialect=r,this._={selectedFields:t},this.tableName=ti(e),this.joinsNotNullableMap="string"==typeof this.tableName?{[this.tableName]:!0}:{}}createJoin(e){return(t,i)=>{let s=this.tableName,r=ti(t);if("string"==typeof r&&this.config.joins?.some(e=>e.alias===r))throw Error(`Alias "${r}" is already used in this query`);if(!this.isPartialSelect&&(1===Object.keys(this.joinsNotNullableMap).length&&"string"==typeof s&&(this.config.fields={[s]:this.config.fields}),"string"==typeof r&&!c(t,ei))){let e=c(t,Y)?t._.selectedFields:c(t,ec)?t[H].selectedFields:t[N.Symbol.Columns];this.config.fields[r]=e}if("function"==typeof i&&(i=i(new Proxy(this.config.fields,new eJ({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.joins||(this.config.joins=[]),this.config.joins.push({on:i,table:t,joinType:e,alias:r}),"string"==typeof r)switch(e){case"left":this.joinsNotNullableMap[r]=!1;break;case"right":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[r]=!0;break;case"inner":this.joinsNotNullableMap[r]=!0;break;case"full":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[r]=!1}return this}}leftJoin=this.createJoin("left");rightJoin=this.createJoin("right");innerJoin=this.createJoin("inner");fullJoin=this.createJoin("full");createSetOperator(e,t){return i=>{let s="function"==typeof i?i(tf()):i;if(!te(this.getSelectedFields(),s.getSelectedFields()))throw Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return this.config.setOperators.push({type:e,isAll:t,rightSelect:s}),this}}union=this.createSetOperator("union",!1);unionAll=this.createSetOperator("union",!0);intersect=this.createSetOperator("intersect",!1);except=this.createSetOperator("except",!1);addSetOperators(e){return this.config.setOperators.push(...e),this}where(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new eJ({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.where=e,this}having(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new eJ({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.having=e,this}groupBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.fields,new eJ({sqlAliasedBehavior:"alias",sqlBehavior:"sql"})));this.config.groupBy=Array.isArray(t)?t:[t]}else this.config.groupBy=e;return this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.fields,new eJ({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=i:this.config.orderBy=i}else this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=e:this.config.orderBy=e;return this}limit(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).limit=e:this.config.limit=e,this}offset(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).offset=e:this.config.offset=e,this}getSQL(){return this.dialect.buildSelectQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}as(e){return new Proxy(new Y(this.getSQL(),this.config.fields,e),new eJ({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}getSelectedFields(){return new Proxy(this.config.fields,new eJ({alias:this.tableName,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}$dynamic(){return this}}class th extends tc{static [u]="SQLiteSelect";_prepare(e=!0){if(!this.session)throw Error("Cannot execute a query on a query builder. Please use a database instance instead.");let t=e8(this.config.fields),i=this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),t,"all",!0);return i.joinsNotNullableMap=this.joinsNotNullableMap,i}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.all()}}for(let e of[to])for(let t of Object.getOwnPropertyNames(e.prototype))"constructor"!==t&&Object.defineProperty(th.prototype,t,Object.getOwnPropertyDescriptor(e.prototype,t)||Object.create(null));function td(e,t){return(i,s,...r)=>{let n=[s,...r].map(i=>({type:e,isAll:t,rightSelect:i}));for(let e of n)if(!te(i.getSelectedFields(),e.rightSelect.getSelectedFields()))throw Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return i.addSetOperators(n)}}let tf=()=>({union:tm,unionAll:tp,intersect:tg,except:ty}),tm=td("union",!1),tp=td("union",!0),tg=td("intersect",!1),ty=td("except",!1);class tb{static [u]="SQLiteQueryBuilder";dialect;dialectConfig;constructor(e){this.dialect=c(e,tr)?e:void 0,this.dialectConfig=c(e,tr)?void 0:e}$with(e){let t=this;return{as:i=>("function"==typeof i&&(i=i(t)),new Proxy(new G(i.getSQL(),i.getSelectedFields(),e,!0),new eJ({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"})))}}with(...e){let t=this;return{select:function(i){return new tu({fields:i??void 0,session:void 0,dialect:t.getDialect(),withList:e})},selectDistinct:function(i){return new tu({fields:i??void 0,session:void 0,dialect:t.getDialect(),withList:e,distinct:!0})}}}select(e){return new tu({fields:e??void 0,session:void 0,dialect:this.getDialect()})}selectDistinct(e){return new tu({fields:e??void 0,session:void 0,dialect:this.getDialect(),distinct:!0})}getDialect(){return this.dialect||(this.dialect=new tn(this.dialectConfig)),this.dialect}}class tw{constructor(e,t,i,s){this.table=e,this.session=t,this.dialect=i,this.withList=s}static [u]="SQLiteUpdateBuilder";set(e){return new tS(this.table,tt(this.table,e),this.session,this.dialect,this.withList)}}class tS extends to{constructor(e,t,i,s,r){super(),this.session=i,this.dialect=s,this.config={set:t,table:e,withList:r,joins:[]}}static [u]="SQLiteUpdate";config;from(e){return this.config.from=e,this}createJoin(e){return(t,i)=>{let s=ti(t);if("string"==typeof s&&this.config.joins.some(e=>e.alias===s))throw Error(`Alias "${s}" is already used in this query`);if("function"==typeof i){let e=this.config.from?c(t,e6)?t[N.Symbol.Columns]:c(t,Y)?t._.selectedFields:c(t,ts)?t[H].selectedFields:void 0:void 0;i=i(new Proxy(this.config.table[N.Symbol.Columns],new eJ({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})),e&&new Proxy(e,new eJ({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))}return this.config.joins.push({on:i,table:t,joinType:e,alias:s}),this}}leftJoin=this.createJoin("left");rightJoin=this.createJoin("right");innerJoin=this.createJoin("inner");fullJoin=this.createJoin("full");where(e){return this.config.where=e,this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.table[N.Symbol.Columns],new eJ({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.orderBy=i}else this.config.orderBy=e;return this}limit(e){return this.config.limit=e,this}returning(e=this.config.table[e6.Symbol.Columns]){return this.config.returning=e8(e),this}getSQL(){return this.dialect.buildUpdateQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0)}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.config.returning?this.all():this.run()}$dynamic(){return this}}class t${constructor(e,t,i,s){this.table=e,this.session=t,this.dialect=i,this.withList=s}static [u]="SQLiteInsertBuilder";values(e){if(0===(e=Array.isArray(e)?e:[e]).length)throw Error("values() must be called with at least one value");let t=e.map(e=>{let t={},i=this.table[N.Symbol.Columns];for(let s of Object.keys(e)){let r=e[s];t[s]=c(r,ei)?r:new el(r,i[s])}return t});return new tv(this.table,t,this.session,this.dialect,this.withList)}select(e){let t="function"==typeof e?e(new tb):e;if(!c(t,ei)&&!te(this.table[g],t._.selectedFields))throw Error("Insert select error: selected fields are not the same or are in a different order compared to the table definition");return new tv(this.table,t,this.session,this.dialect,this.withList,!0)}}class tv extends to{constructor(e,t,i,s,r,n){super(),this.session=i,this.dialect=s,this.config={table:e,values:t,withList:r,select:n}}static [u]="SQLiteInsert";config;returning(e=this.config.table[e6.Symbol.Columns]){return this.config.returning=e8(e),this}onConflictDoNothing(e={}){if(void 0===e.target)this.config.onConflict=ea`do nothing`;else{let t=Array.isArray(e.target)?ea`${e.target}`:ea`${[e.target]}`,i=e.where?ea` where ${e.where}`:ea``;this.config.onConflict=ea`${t} do nothing${i}`}return this}onConflictDoUpdate(e){if(e.where&&(e.targetWhere||e.setWhere))throw Error('You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.');let t=e.where?ea` where ${e.where}`:void 0,i=e.targetWhere?ea` where ${e.targetWhere}`:void 0,s=e.setWhere?ea` where ${e.setWhere}`:void 0,r=Array.isArray(e.target)?ea`${e.target}`:ea`${[e.target]}`,n=this.dialect.buildUpdateSet(this.config.table,tt(this.config.table,e.set));return this.config.onConflict=ea`${r}${i} do update set ${n}${t}${s}`,this}getSQL(){return this.dialect.buildInsertQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0)}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.config.returning?this.all():this.run()}$dynamic(){return this}}class tN extends to{constructor(e,t,i,s){super(),this.table=e,this.session=t,this.dialect=i,this.config={table:e,withList:s}}static [u]="SQLiteDelete";config;where(e){return this.config.where=e,this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.table[N.Symbol.Columns],new eJ({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.orderBy=i}else this.config.orderBy=e;return this}limit(e){return this.config.limit=e,this}returning(e=this.table[e6.Symbol.Columns]){return this.config.returning=e8(e),this}getSQL(){return this.dialect.buildDeleteQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0)}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(e){return this._prepare().execute(e)}$dynamic(){return this}}class tq extends ei{constructor(e){super(tq.buildEmbeddedCount(e.source,e.filters).queryChunks),this.params=e,this.session=e.session,this.sql=tq.buildCount(e.source,e.filters)}sql;static [u]="SQLiteCountBuilderAsync";[Symbol.toStringTag]="SQLiteCountBuilderAsync";session;static buildEmbeddedCount(e,t){return ea`(select count(*) from ${e}${ea.raw(" where ").if(t)}${t})`}static buildCount(e,t){return ea`select count(*) from ${e}${ea.raw(" where ").if(t)}${t}`}then(e,t){return Promise.resolve(this.session.count(this.sql)).then(e,t)}catch(e){return this.then(void 0,e)}finally(e){return this.then(t=>(e?.(),t),t=>{throw e?.(),t})}}class tC{constructor(e,t,i,s,r,n,l,a){this.mode=e,this.fullSchema=t,this.schema=i,this.tableNamesMap=s,this.table=r,this.tableConfig=n,this.dialect=l,this.session=a}static [u]="SQLiteAsyncRelationalQueryBuilder";findMany(e){return"sync"===this.mode?new tT(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e||{},"many"):new tQ(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e||{},"many")}findFirst(e){return"sync"===this.mode?new tT(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e?{...e,limit:1}:{limit:1},"first"):new tQ(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e?{...e,limit:1}:{limit:1},"first")}}class tQ extends to{constructor(e,t,i,s,r,n,l,a,o){super(),this.fullSchema=e,this.schema=t,this.tableNamesMap=i,this.table=s,this.tableConfig=r,this.dialect=n,this.session=l,this.config=a,this.mode=o}static [u]="SQLiteAsyncRelationalQuery";mode;getSQL(){return this.dialect.buildRelationalQuery({fullSchema:this.fullSchema,schema:this.schema,tableNamesMap:this.tableNamesMap,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,tableAlias:this.tableConfig.tsName}).sql}_prepare(e=!1){let{query:t,builtQuery:i}=this._toSQL();return this.session[e?"prepareOneTimeQuery":"prepareQuery"](i,void 0,"first"===this.mode?"get":"all",!0,(e,i)=>{let s=e.map(e=>(function e(t,i,s,r,n=e=>e){let l={};for(let[a,o]of r.entries())if(o.isJson){let r=i.relations[o.tsKey],u=s[a],h="string"==typeof u?JSON.parse(u):u;l[o.tsKey]=c(r,eP)?h&&e(t,t[o.relationTableTsKey],h,o.selection,n):h.map(i=>e(t,t[o.relationTableTsKey],i,o.selection,n))}else{let e,t=n(s[a]),i=o.field;e=c(i,C)?i:c(i,ei)?i.decoder:i.sql.decoder,l[o.tsKey]=null===t?null:e.mapFromDriverValue(t)}return l})(this.schema,this.tableConfig,e,t.selection,i));return"first"===this.mode?s[0]:s})}prepare(){return this._prepare(!1)}_toSQL(){let e=this.dialect.buildRelationalQuery({fullSchema:this.fullSchema,schema:this.schema,tableNamesMap:this.tableNamesMap,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,tableAlias:this.tableConfig.tsName}),t=this.dialect.sqlToQuery(e.sql);return{query:e,builtQuery:t}}toSQL(){return this._toSQL().builtQuery}executeRaw(){return"first"===this.mode?this._prepare(!1).get():this._prepare(!1).all()}async execute(){return this.executeRaw()}}class tT extends tQ{static [u]="SQLiteSyncRelationalQuery";sync(){return this.executeRaw()}}class tx extends to{constructor(e,t,i,s,r){super(),this.execute=e,this.getSQL=t,this.dialect=s,this.mapBatchResult=r,this.config={action:i}}static [u]="SQLiteRaw";config;getQuery(){return{...this.dialect.sqlToQuery(this.getSQL()),method:this.config.action}}mapResult(e,t){return t?this.mapBatchResult(e)