appos 0.3.2-0 → 0.3.4-0
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/dist/bin/auth-schema-CcqAJY9P.mjs +2 -0
- package/dist/bin/better-sqlite3-CuQ3hsWl.mjs +2 -0
- package/dist/bin/bun-sql-DGeo-s_M.mjs +2 -0
- package/dist/bin/cache-3oO07miM.mjs +2 -0
- package/dist/bin/chunk-l9p7A9gZ.mjs +2 -0
- package/dist/bin/cockroach-BaICwY7N.mjs +2 -0
- package/dist/bin/database-CaysWPpa.mjs +2 -0
- package/dist/bin/esm-BvsccvmM.mjs +2 -0
- package/dist/bin/esm-CGKzJ7Am.mjs +3 -0
- package/dist/bin/event-DnSe3eh0.mjs +8 -0
- package/dist/bin/extract-blob-metadata-iqwTl2ft.mjs +170 -0
- package/dist/bin/generate-image-variant-Lyx0vhM6.mjs +2 -0
- package/dist/bin/generate-preview-0MrKxslA.mjs +2 -0
- package/dist/bin/libsql-DQJrZsU9.mjs +2 -0
- package/dist/bin/logger-BAGZLUzj.mjs +2 -0
- package/dist/bin/main.mjs +1201 -190
- package/dist/bin/migrator-B7iNKM8N.mjs +2 -0
- package/dist/bin/migrator-BKE1cSQQ.mjs +2 -0
- package/dist/bin/migrator-BXcbc9zs.mjs +2 -0
- package/dist/bin/migrator-B_XhRWZC.mjs +8 -0
- package/dist/bin/migrator-Bz52Gtr8.mjs +2 -0
- package/dist/bin/migrator-C7W-cZHB.mjs +2 -0
- package/dist/bin/migrator-CEnKyGSW.mjs +2 -0
- package/dist/bin/migrator-CHzIIl5X.mjs +2 -0
- package/dist/bin/migrator-CR-rjZdM.mjs +2 -0
- package/dist/bin/migrator-CjIr1ZCx.mjs +8 -0
- package/dist/bin/migrator-Cuubh2dg.mjs +2 -0
- package/dist/bin/migrator-D8m-ORbr.mjs +8 -0
- package/dist/bin/migrator-DBFwrhZH.mjs +2 -0
- package/dist/bin/migrator-DLmhW9u_.mjs +2 -0
- package/dist/bin/migrator-DLoHx807.mjs +4 -0
- package/dist/bin/migrator-DtN_iS87.mjs +2 -0
- package/dist/bin/migrator-Yc57lb3w.mjs +2 -0
- package/dist/bin/migrator-cEVXH3xC.mjs +2 -0
- package/dist/bin/migrator-hWi-sYIq.mjs +2 -0
- package/dist/bin/mysql2-DufFWkj4.mjs +2 -0
- package/dist/bin/neon-serverless-5a4h2VFz.mjs +2 -0
- package/dist/bin/node-CiOp4xrR.mjs +22 -0
- package/dist/bin/node-mssql-DvZGaUkB.mjs +322 -0
- package/dist/bin/node-postgres-BqbJVBQY.mjs +2 -0
- package/dist/bin/node-postgres-DnhRTTO8.mjs +2 -0
- package/dist/bin/open-0ksnL0S8.mjs +2 -0
- package/dist/bin/pdf-sUYeFPr4.mjs +14 -0
- package/dist/bin/pg-CaH8ptj-.mjs +2 -0
- package/dist/bin/pg-core-BLTZt9AH.mjs +8 -0
- package/dist/bin/pg-core-CGzidKaA.mjs +2 -0
- package/dist/bin/pglite-BJB9z7Ju.mjs +2 -0
- package/dist/bin/planetscale-serverless-H3RfLlMK.mjs +13 -0
- package/dist/bin/postgres-js-DuOf1eWm.mjs +2 -0
- package/dist/bin/purge-attachment-DQXpTtTx.mjs +2 -0
- package/dist/bin/purge-audit-logs-BEt2J2gD.mjs +2 -0
- package/dist/bin/{purge-unattached-blobs-Duvv8Izd.mjs → purge-unattached-blobs-DOmk4ddJ.mjs} +1 -1
- package/dist/bin/query-builder-DSRrR6X_.mjs +8 -0
- package/dist/bin/query-builder-V8-LDhvA.mjs +3 -0
- package/dist/bin/session-CdB1A-LB.mjs +14 -0
- package/dist/bin/session-Cl2e-_i8.mjs +8 -0
- package/dist/bin/singlestore-COft6TlR.mjs +8 -0
- package/dist/bin/sql-D-eKV1Dn.mjs +2 -0
- package/dist/bin/sqlite-cloud-Co9jOn5G.mjs +2 -0
- package/dist/bin/sqlite-proxy-Cpu78gJF.mjs +2 -0
- package/dist/bin/src-C-oXmCzx.mjs +6 -0
- package/dist/bin/table-3zUpWkMg.mjs +2 -0
- package/dist/bin/track-db-changes-DWyY5jXm.mjs +2 -0
- package/dist/bin/utils-CyoeCJlf.mjs +2 -0
- package/dist/bin/utils-EoqYQKy1.mjs +2 -0
- package/dist/bin/utils-bsypyqPl.mjs +2 -0
- package/dist/bin/vercel-postgres-HWL6xtqi.mjs +2 -0
- package/dist/bin/workflow-zxHDyfLq.mjs +2 -0
- package/dist/bin/youch-handler-DrYdbUhe.mjs +2 -0
- package/dist/bin/zod-MJjkEkRY.mjs +24 -0
- package/dist/exports/api/_virtual/rolldown_runtime.mjs +36 -1
- package/dist/exports/api/app-context.mjs +24 -1
- package/dist/exports/api/auth-schema.mjs +373 -1
- package/dist/exports/api/auth.d.mts +4 -0
- package/dist/exports/api/auth.mjs +188 -1
- package/dist/exports/api/cache.d.mts +2 -2
- package/dist/exports/api/cache.mjs +28 -1
- package/dist/exports/api/config.mjs +72 -1
- package/dist/exports/api/constants.mjs +92 -1
- package/dist/exports/api/container.mjs +49 -1
- package/dist/exports/api/database.mjs +218 -1
- package/dist/exports/api/event.mjs +236 -1
- package/dist/exports/api/i18n.mjs +45 -1
- package/dist/exports/api/index.mjs +20 -1
- package/dist/exports/api/instrumentation.mjs +40 -1
- package/dist/exports/api/logger.mjs +26 -1
- package/dist/exports/api/mailer.mjs +37 -1
- package/dist/exports/api/middleware.mjs +73 -1
- package/dist/exports/api/openapi.mjs +507 -1
- package/dist/exports/api/orm.mjs +43 -1
- package/dist/exports/api/otel.mjs +56 -1
- package/dist/exports/api/redis.mjs +41 -1
- package/dist/exports/api/storage-schema.mjs +72 -1
- package/dist/exports/api/storage.mjs +833 -1
- package/dist/exports/api/web/auth.mjs +17 -1
- package/dist/exports/api/workflow.mjs +196 -1
- package/dist/exports/api/workflows/_virtual/rolldown_runtime.mjs +36 -1
- package/dist/exports/api/workflows/api/auth-schema.mjs +373 -1
- package/dist/exports/api/workflows/api/auth.d.mts +4 -0
- package/dist/exports/api/workflows/api/cache.d.mts +2 -2
- package/dist/exports/api/workflows/api/event.mjs +126 -1
- package/dist/exports/api/workflows/api/redis.mjs +3 -1
- package/dist/exports/api/workflows/api/workflow.mjs +135 -1
- package/dist/exports/api/workflows/constants.mjs +23 -1
- package/dist/exports/api/workflows/extract-blob-metadata.mjs +132 -1
- package/dist/exports/api/workflows/generate-image-variant.d.mts +2 -2
- package/dist/exports/api/workflows/generate-image-variant.mjs +118 -1
- package/dist/exports/api/workflows/generate-preview.mjs +160 -1
- package/dist/exports/api/workflows/index.mjs +3 -1
- package/dist/exports/api/workflows/purge-attachment.mjs +34 -1
- package/dist/exports/api/workflows/purge-audit-logs.mjs +47 -1
- package/dist/exports/api/workflows/purge-unattached-blobs.mjs +46 -1
- package/dist/exports/api/workflows/track-db-changes.mjs +110 -1
- package/dist/exports/cli/_virtual/rolldown_runtime.mjs +36 -1
- package/dist/exports/cli/api/auth-schema.mjs +373 -1
- package/dist/exports/cli/api/auth.d.mts +4 -0
- package/dist/exports/cli/api/cache.d.mts +2 -2
- package/dist/exports/cli/api/event.mjs +126 -1
- package/dist/exports/cli/api/redis.mjs +3 -1
- package/dist/exports/cli/api/workflow.mjs +135 -1
- package/dist/exports/cli/api/workflows/extract-blob-metadata.mjs +132 -1
- package/dist/exports/cli/api/workflows/generate-image-variant.mjs +118 -1
- package/dist/exports/cli/api/workflows/generate-preview.mjs +160 -1
- package/dist/exports/cli/api/workflows/purge-attachment.mjs +34 -1
- package/dist/exports/cli/api/workflows/purge-audit-logs.mjs +47 -1
- package/dist/exports/cli/api/workflows/purge-unattached-blobs.mjs +46 -1
- package/dist/exports/cli/api/workflows/track-db-changes.mjs +110 -1
- package/dist/exports/cli/command.d.mts +2 -0
- package/dist/exports/cli/command.mjs +43 -1
- package/dist/exports/cli/constants.mjs +23 -1
- package/dist/exports/cli/index.mjs +3 -1
- package/dist/exports/devtools/index.js +4 -1
- package/dist/exports/tests/api/auth.d.mts +4 -0
- package/dist/exports/tests/api/cache.d.mts +2 -2
- package/dist/exports/tests/api/middleware/i18n.mjs +1 -1
- package/dist/exports/tests/api/middleware/youch-handler.mjs +1 -1
- package/dist/exports/tests/api/openapi.mjs +1 -1
- package/dist/exports/tests/api/server.mjs +1 -1
- package/dist/exports/tests/api/storage.d.mts +4 -4
- package/dist/exports/tests/constants.mjs +1 -1
- package/dist/exports/vendors/date.js +1 -1
- package/dist/exports/vendors/toolkit.js +1 -1
- package/dist/exports/vendors/zod.js +1 -1
- package/dist/exports/vitest/globals.mjs +1 -1
- package/dist/exports/web/auth.js +75 -1
- package/dist/exports/web/i18n.js +45 -1
- package/dist/exports/web/index.js +8 -1
- package/package.json +19 -18
- package/dist/bin/auth-schema-Va0CYicu.mjs +0 -2
- package/dist/bin/event-8JibGFH_.mjs +0 -2
- package/dist/bin/extract-blob-metadata-DjPfHtQ2.mjs +0 -2
- package/dist/bin/generate-image-variant-D5VDFyWj.mjs +0 -2
- package/dist/bin/generate-preview-Dssw7w5U.mjs +0 -2
- package/dist/bin/purge-attachment-BBPzIxwt.mjs +0 -2
- package/dist/bin/purge-audit-logs-BeZy3IFM.mjs +0 -2
- package/dist/bin/track-db-changes-CFykw_YO.mjs +0 -2
- package/dist/bin/workflow-BNUZrj4F.mjs +0 -2
- package/dist/bin/youch-handler-BadUgHb0.mjs +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{G as e,K as t,R as n,T as r,o as i,t as a,u as o}from"./sql-D-eKV1Dn.mjs";import{c as s,dr as c,l}from"./query-builder-V8-LDhvA.mjs";import{t as u}from"./logger-BAGZLUzj.mjs";import{t as d}from"./cache-3oO07miM.mjs";import{L as f,n as p,r as m,t as h,x as g}from"./pg-core-BLTZt9AH.mjs";import{BeginTransactionCommand as _,CommitTransactionCommand as v,ExecuteStatementCommand as y,RDSDataClient as b,RollbackTransactionCommand as x}from"@aws-sdk/client-rds-data";const S={DATE:`DATE`,DECIMAL:`DECIMAL`,JSON:`JSON`,TIME:`TIME`,TIMESTAMP:`TIMESTAMP`,UUID:`UUID`};function C(e){if(e.stringValue!==void 0)return e.stringValue;if(e.booleanValue!==void 0)return e.booleanValue;if(e.doubleValue!==void 0)return e.doubleValue;if(e.isNull!==void 0)return null;if(e.longValue!==void 0)return e.longValue;if(e.blobValue!==void 0)return e.blobValue;if(e.arrayValue!==void 0){if(e.arrayValue.stringValues!==void 0)return e.arrayValue.stringValues;if(e.arrayValue.longValues!==void 0)return e.arrayValue.longValues;if(e.arrayValue.doubleValues!==void 0)return e.arrayValue.doubleValues;if(e.arrayValue.booleanValues!==void 0)return e.arrayValue.booleanValues;if(e.arrayValue.arrayValues!==void 0)return e.arrayValue.arrayValues;throw Error(`Unknown array type`)}else throw Error(`Unknown type`)}function w(e){if(e===`date`)return S.DATE;if(e===`decimal`)return S.DECIMAL;if(e===`json`)return S.JSON;if(e===`time`)return S.TIME;if(e===`timestamp`)return S.TIMESTAMP;if(e===`uuid`)return S.UUID}function T(e,t){let n={value:{},typeHint:w(t)};if(e===null)n.value={isNull:!0};else if(typeof e==`string`)switch(n.typeHint){case S.DATE:n.value={stringValue:e.split(`T`)[0]};break;case S.TIMESTAMP:n.value={stringValue:e.replace(`T`,` `).replace(`Z`,``)};break;default:n.value={stringValue:e};break}else if(typeof e==`number`&&Number.isInteger(e))n.value={longValue:e};else if(typeof e==`number`&&!Number.isInteger(e))n.value={doubleValue:e};else if(typeof e==`boolean`)n.value={booleanValue:e};else if(e instanceof Date)n.value={stringValue:e.toISOString().replace(`T`,` `).replace(`Z`,``)};else throw Error(`Unknown type for ${e}`);return n}var E=class extends h{constructor(e,t,n,r,i,a,o,s,c,l,u,d,f){super({sql:t,params:n},a,o,s),this.client=e,this.queryString=t,this.params=n,this.typings=r,this.options=i,this.fields=c,this.transactionId=l,this._isResponseInArrayMode=u,this.customResultMapper=d,this.isRqbV2Query=f,this.rawQuery=new y({sql:t,parameters:[],secretArn:i.secretArn,resourceArn:i.resourceArn,database:i.database,transactionId:l,includeResultMetadata:f||!c&&!d})}static[e]=`AwsDataApiPreparedQuery`;rawQuery;async execute(e={}){if(this.isRqbV2Query)return this.executeRqbV2(e);let{fields:t,joinsNotNullableMap:n,customResultMapper:r}=this,i=await this.values(e);if(!t&&!r){let{columnMetadata:e,rows:t}=i;if(!e)return i;let n=t.map(t=>{let n={};for(let[r,i]of t.entries()){let t=e[r];if(!t)throw Error(`Unexpected state: no column metadata found for index ${r}. Please report this issue on GitHub: https://github.com/drizzle-team/drizzle-orm/issues/new/choose`);if(!t.name)throw Error(`Unexpected state: no column name for index ${r} found in the column metadata. Please report this issue on GitHub: https://github.com/drizzle-team/drizzle-orm/issues/new/choose`);n[t.name]=i}return n});return Object.assign(i,{rows:n})}return r?r(i.rows):i.rows.map(e=>c(t,e,n))}async executeRqbV2(e={}){let{customResultMapper:t}=this,{columnMetadata:n,rows:r}=await this.values(e);return t(n?r.map(e=>{let t={};for(let[r,i]of e.entries()){let e=n[r];if(!e)throw Error(`Unexpected state: no column metadata found for index ${r}. Please report this issue on GitHub: https://github.com/drizzle-team/drizzle-orm/issues/new/choose`);if(!e.name)throw Error(`Unexpected state: no column name for index ${r} found in the column metadata. Please report this issue on GitHub: https://github.com/drizzle-team/drizzle-orm/issues/new/choose`);t[e.name]=i}return t}):r)}async all(e){let t=await this.execute(e);return!this.fields&&!this.customResultMapper?t.rows:t}async values(e={}){let t=i(this.params,e??{});this.rawQuery.input.parameters=t.map((e,t)=>({name:`${t+1}`,...T(e,this.typings[t])})),this.options.logger?.logQuery(this.rawQuery.input.sql,this.rawQuery.input.parameters);let n=await this.queryWithCache(this.queryString,t,async()=>await this.client.send(this.rawQuery)),r=n.records?.map(e=>e.map(e=>C(e)))??[];return{...n,rows:r}}mapResultRows(e,t){return e.map(e=>{let n={};for(let[r,i]of e.entries()){let{name:e}=t[r];n[e??r]=C(i)}return n})}isResponseInArrayMode(){return this._isResponseInArrayMode}},D=class t extends p{constructor(e,t,n,r,i,a){super(t),this.client=e,this.relations=n,this.schema=r,this.options=i,this.transactionId=a,this.rawQuery={secretArn:i.secretArn,resourceArn:i.resourceArn,database:i.database},this.cache=i.cache??new d}static[e]=`AwsDataApiSession`;rawQuery;cache;prepareQuery(e,t,n,r,i,a,o,s){return new E(this.client,e.sql,e.params,e.typings??[],this.options,this.cache,a,o,t,s??this.transactionId,r,i)}prepareRelationalQuery(e,t,n,r,i){return new E(this.client,e.sql,e.params,e.typings??[],this.options,this.cache,void 0,void 0,t,i??this.transactionId,!1,r,!0)}async count(e){let t=this.dialect.sqlToQuery(e),{rows:n}=await this.prepareQuery(t,void 0,void 0,!0).values(),r=n[0]?.[0]??0;return typeof r==`number`?r:Number(r)}execute(e){return this.prepareQuery(this.dialect.sqlToQuery(e),void 0,void 0,!1,void 0,void 0,void 0,this.transactionId).execute()}async transaction(e,n){let{transactionId:r}=await this.client.send(new _(this.rawQuery)),i=new t(this.client,this.dialect,this.relations,this.schema,this.options,r),a=new O(this.dialect,i,this.relations,this.schema,void 0,!0);n&&await a.setTransaction(n);try{let t=await e(a);return await this.client.send(new v({...this.rawQuery,transactionId:r})),t}catch(e){throw await this.client.send(new x({...this.rawQuery,transactionId:r})),e}}},O=class t extends m{static[e]=`AwsDataApiTransaction`;async transaction(e){let n=`sp${this.nestedIndex+1}`,r=new t(this.dialect,this.session,this.relations,this.schema,this.nestedIndex+1);await this.session.execute(o.raw(`savepoint ${n}`));try{let t=await e(r);return await this.session.execute(o.raw(`release savepoint ${n}`)),t}catch(e){throw await this.session.execute(o.raw(`rollback to savepoint ${n}`)),e}}},k=class extends g{static[e]=`AwsDataApiPgDatabase`;execute(e){return super.execute(e)}},A=class extends f{static[e]=`AwsPgDialect`;escapeParam(e){return`:${e+1}`}buildInsertQuery({table:e,values:i,onConflict:s,returning:c,select:l,withList:u}){let d=e[n.Symbol.Columns];if(!l)for(let e of i)for(let n of Object.keys(d)){let i=e[n];t(i,a)&&i.value!==void 0&&t(i.encoder,r)&&Array.isArray(i.value)&&(e[n]=o`cast(${i} as ${o.raw(i.encoder.getSQLType())})`)}return super.buildInsertQuery({table:e,values:i,onConflict:s,returning:c,withList:u})}buildUpdateSet(e,i){let s=e[n.Symbol.Columns];for(let[e,n]of Object.entries(i))s[e]&&t(n,a)&&n.value!==void 0&&t(n.encoder,r)&&Array.isArray(n.value)&&(i[e]=o`cast(${n} as ${o.raw(n.encoder.getSQLType())})`);return super.buildUpdateSet(e,i)}};function j(e,t){let n=new A({casing:t.casing}),r;t.logger===!0?r=new u:t.logger!==!1&&(r=t.logger);let i;if(t.schema){let e=l(t.schema,s);i={fullSchema:t.schema,schema:e.tables,tableNamesMap:e.tableNamesMap}}let a=t.relations??{},o=new k(n,new D(e,n,a,i,{...t,logger:r,cache:t.cache},void 0),a,i,!0);return o.$client=e,o.$cache=t.cache,o.$cache&&(o.$cache.invalidate=t.cache?.onMutate),o}function M(...e){if(e[0].client){let{client:t,...n}=e[0];return j(t,n)}let{connection:t,...n}=e[0],{resourceArn:r,database:i,secretArn:a,...o}=t;return j(new b(o),{resourceArn:r,database:i,secretArn:a,...n})}(e=>{function t(e){return j({},e)}e.mock=t})(M||={});export{D as AwsDataApiSession,M as drizzle};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{B as e,D as t,G as n,H as r,K as i,P as a,R as o,S as s,T as c,U as l,V as u,W as d,a as f,c as p,d as m,f as h,h as g,m as _,r as v,t as y,u as b,w as x,x as S,z as C}from"./sql-D-eKV1Dn.mjs";import{Dn as ee,G as w,Gt as te,H as ne,K as T,S as re,U as ie,_ as E,_r as ae,_t as oe,a as se,ar as D,cr as O,d as ce,f as le,fn as ue,fr as de,ft as fe,gr as pe,hr as k,i as me,ir as A,kn as he,ln as ge,lr as j,lt as _e,m as ve,mr as M,mt as ye,n as N,o as be,pr as P,q as xe,r as F,rr as I,sr as L,t as Se,u as Ce,vr as we,yr as Te}from"./query-builder-V8-LDhvA.mjs";import{a as Ee,c as De,i as Oe,l as ke,n as Ae,o as je,r as Me,s as Ne,t as Pe}from"./cache-3oO07miM.mjs";var Fe=class{constructor(e,t){this.name=e,this.value=t}static[n]=`PgCheckBuilder`;brand;build(e){return new Ie(e,this)}},Ie=class{constructor(e,t){this.table=e,this.name=t.name,this.value=t.value}static[n]=`PgCheck`;name;value},Le=class{static[n]=`PgIndexBuilder`;config;constructor(e,t,n,r,i=`btree`){this.config={name:r,columns:e,unique:t,only:n,method:i}}concurrently(){return this.config.concurrently=!0,this}with(e){return this.config.with=e,this}where(e){return this.config.where=e,this}build(e){return new Re(this.config,e)}},Re=class{static[n]=`PgIndex`;config;isNameExplicit;constructor(e,t){this.config={...e,table:t},this.isNameExplicit=!!e.name}},ze=class{constructor(e,t){this.name=e,t&&(this.as=t.as,this.for=t.for,this.to=t.to,this.using=t.using,this.withCheck=t.withCheck)}static[n]=`PgPolicy`;as;for;to;using;withCheck;_linkedTable;link(e){return this._linkedTable=e,this}};function Be(e,t){return`${e[l]}_${t.join(`_`)}_unique`}var Ve=class{constructor(e,t){this.name=t,this.columns=e}static[n]=`PgUniqueConstraintBuilder`;columns;nullsNotDistinctConfig=!1;nullsNotDistinct(){return this.nullsNotDistinctConfig=!0,this}build(e){return new He(e,this.columns,this.nullsNotDistinctConfig,this.name)}},He=class{constructor(e,t,n,r){this.table=e,this.columns=t,this.name=r??Be(this.table,this.columns.map(e=>e.name)),this.isNameExplicit=!!r,this.nullsNotDistinct=n}static[n]=`PgUniqueConstraint`;columns;name;isNameExplicit;nullsNotDistinct=!1;getName(){return this.name}};const R=Symbol.for(`drizzle:PgViewConfig`),z=Symbol.for(`drizzle:PgMaterializedViewConfig`);function Ue(e){let t=Object.values(e[o.Symbol.Columns]),n=[],r=[],s=[],c=Object.values(e[w.Symbol.InlineForeignKeys]),l=[],u=e[o.Symbol.Name],d=e[o.Symbol.Schema],f=[],p=e[w.Symbol.EnableRLS],m=e[w.Symbol.ExtraConfigBuilder];if(m!==void 0){let t=m(e[o.Symbol.ExtraConfigColumns]),u=Array.isArray(t)?t.flat(1):Object.values(t);for(let t of u)i(t,Le)?n.push(t.build(e)):i(t,Fe)?r.push(t.build(e)):i(t,Ve)?l.push(t.build(e)):i(t,ne)?s.push(t.build(e)):i(t,a)?c.push(t.build(e)):i(t,ze)&&f.push(t)}return{columns:t,indexes:n,foreignKeys:c,checks:r,primaryKeys:s,uniqueConstraints:l,name:u,schema:d,policies:f,enableRLS:p}}function B(t){return i(t,w)?[t[e]?`${t[e]}.${t[o.Symbol.BaseName]}`:t[o.Symbol.BaseName]]:i(t,_)?t._.usedTables??[]:i(t,v)?t.usedTables??[]:[]}function We(e){return{...e[m],...e[R]}}function Ge(e){return{...e[m],...e[z]}}var V=class extends A{constructor(e,t,n,r){super(),this.session=t,this.dialect=n,this.config={table:e,withList:r}}static[n]=`PgDelete`;config;cacheConfig;where(e){return this.config.where=e,this}returning(e=this.config.table[o.Symbol.Columns]){return this.config.returningFields=e,this.config.returning=P(e),this}getSQL(){return this.dialect.buildDeleteQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e){return h.startActiveSpan(`drizzle.prepareQuery`,()=>this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()),this.config.returning,e,!0,void 0,{type:`delete`,tables:B(this.config.table)},this.cacheConfig))}prepare(e){return this._prepare(e)}authToken;setToken(e){return this.authToken=e,this}execute=e=>h.startActiveSpan(`drizzle.operation`,()=>this._prepare().execute(e,this.authToken));getSelectedFields(){return this.config.returningFields?new Proxy(this.config.returningFields,new I({alias:u(this.config.table),sqlAliasedBehavior:`alias`,sqlBehavior:`error`})):void 0}$dynamic(){return this}},H=class extends f{static[n]=`PgViewBase`},U=class{static[n]=`PgDialect`;casing;constructor(e){this.casing=new Te(e?.casing)}async migrate(e,t,n){let r=typeof n==`string`?`__drizzle_migrations`:n.migrationsTable??`__drizzle_migrations`,i=typeof n==`string`?`drizzle`:n.migrationsSchema??`drizzle`,a=b`
|
|
3
|
+
CREATE TABLE IF NOT EXISTS ${b.identifier(i)}.${b.identifier(r)} (
|
|
4
|
+
id SERIAL PRIMARY KEY,
|
|
5
|
+
hash text NOT NULL,
|
|
6
|
+
created_at bigint
|
|
7
|
+
)
|
|
8
|
+
`;await t.execute(b`CREATE SCHEMA IF NOT EXISTS ${b.identifier(i)}`),await t.execute(a);let o=await t.all(b`select id, hash, created_at from ${b.identifier(i)}.${b.identifier(r)} order by created_at desc limit 1`);if(typeof n==`object`&&n.init){if(o.length)return{exitCode:`databaseMigrations`};if(e.length>1)return{exitCode:`localMigrations`};let[n]=e;if(!n)return;await t.execute(b`insert into ${b.identifier(i)}.${b.identifier(r)} ("hash", "created_at") values(${n.hash}, ${n.folderMillis})`);return}let s=o[0];await t.transaction(async t=>{for await(let n of e)if(!s||Number(s.created_at)<n.folderMillis){for(let e of n.sql)await t.execute(b.raw(e));await t.execute(b`insert into ${b.identifier(i)}.${b.identifier(r)} ("hash", "created_at") values(${n.hash}, ${n.folderMillis})`)}})}escapeName(e){return`"${e}"`}escapeParam(e){return`$${e+1}`}escapeString(e){return`'${e.replace(/'/g,`''`)}'`}buildWithCTE(e){if(!e?.length)return;let t=[b`with `];for(let[n,r]of e.entries())t.push(b`${b.identifier(r._.alias)} as (${r._.sql})`),n<e.length-1&&t.push(b`, `);return t.push(b` `),b.join(t)}buildDeleteQuery({table:e,where:t,returning:n,withList:r}){let i=this.buildWithCTE(r),a=n?b` returning ${this.buildSelection(n,{isSingleTable:!0})}`:void 0;return b`${i}delete from ${e}${t?b` where ${t}`:void 0}${a}`}buildUpdateSet(e,t){let n=e[o.Symbol.Columns],r=Object.keys(n).filter(e=>t[e]!==void 0||n[e]?.onUpdateFn!==void 0),a=r.length;return b.join(r.flatMap((e,r)=>{let o=n[e],s=o.onUpdateFn?.(),c=t[e]??(i(s,v)?s:b.param(s,o)),l=b`${b.identifier(this.casing.getColumnCasing(o))} = ${c}`;return r<a-1?[l,b.raw(`, `)]:[l]}))}buildUpdateQuery({table:e,set:t,where:n,returning:r,withList:i,from:a,joins:o}){let s=this.buildWithCTE(i),c=e[w.Symbol.Name],l=e[w.Symbol.Schema],u=e[w.Symbol.OriginalName],d=c===u?void 0:c,f=b`${l?b`${b.identifier(l)}.`:void 0}${b.identifier(u)}${d&&b` ${b.identifier(d)}`}`,p=this.buildUpdateSet(e,t),m=a&&b.join([b.raw(` from `),this.buildFromTable(a)]),h=this.buildJoins(o),g=r?b` returning ${this.buildSelection(r,{isSingleTable:!a})}`:void 0;return b`${s}update ${f} set ${p}${m}${h}${n?b` where ${n}`:void 0}${g}`}buildSelection(e,{isSingleTable:n=!1}={}){let r=e.length,a=e.flatMap(({field:e},a)=>{let o=[];if(i(e,v.Aliased)&&e.isSelectionField)o.push(b.identifier(e.fieldAlias));else if(i(e,v.Aliased)||i(e,v)){let r=i(e,v.Aliased)?e.sql:e;n?o.push(new v(r.queryChunks.map(e=>i(e,t)?b.identifier(this.casing.getColumnCasing(e)):e))):o.push(r),i(e,v.Aliased)&&o.push(b` as ${b.identifier(e.fieldAlias)}`)}else if(i(e,d))n?o.push(e.isAlias?b`${b.identifier(this.casing.getColumnCasing(pe(e)))} as ${e}`:b.identifier(this.casing.getColumnCasing(e))):o.push(e.isAlias?b`${pe(e)} as ${e}`:e);else if(i(e,_)){let t=Object.entries(e._.selectedFields);if(t.length===1){let n=t[0][1],r=i(n,v)?n.decoder:i(n,d)?{mapFromDriverValue:e=>n.mapFromDriverValue(e)}:n.sql.decoder;r&&(e._.sql.decoder=r)}o.push(e)}return a<r-1&&o.push(b`, `),o});return b.join(a)}buildJoins(e){if(!e||e.length===0)return;let t=[];for(let[n,r]of e.entries()){n===0&&t.push(b` `);let a=r.table,o=r.lateral?b` lateral`:void 0,s=r.on?b` on ${r.on}`:void 0;if(i(a,w)){let e=a[w.Symbol.Name],n=a[w.Symbol.Schema],i=a[w.Symbol.OriginalName],c=e===i?void 0:r.alias;t.push(b`${b.raw(r.joinType)} join${o} ${n?b`${b.identifier(n)}.`:void 0}${b.identifier(i)}${c&&b` ${b.identifier(c)}`}${s}`)}else if(i(a,f)){let e=a[m].name,n=a[m].schema,i=a[m].originalName,c=e===i?void 0:r.alias;t.push(b`${b.raw(r.joinType)} join${o} ${n?b`${b.identifier(n)}.`:void 0}${b.identifier(i)}${c&&b` ${b.identifier(c)}`}${s}`)}else t.push(b`${b.raw(r.joinType)} join${o} ${a}${s}`);n<e.length-1&&t.push(b` `)}return b.join(t)}buildFromTable(e){if(i(e,o)&&e[o.Symbol.IsAlias]){let t=b`${b.identifier(e[o.Symbol.OriginalName])}`;return e[o.Symbol.Schema]&&(t=b`${b.identifier(e[o.Symbol.Schema])}.${t}`),b`${t} ${b.identifier(e[o.Symbol.Name])}`}return e}buildSelectQuery({withList:e,fields:t,fieldsFlat:n,where:r,having:a,table:s,joins:c,orderBy:l,groupBy:f,limit:p,offset:h,lockingClause:g,distinct:y,setOperators:x}){let S=n??P(t);for(let e of S)if(i(e.field,d)&&u(e.field.table)!==(i(s,_)?s._.alias:i(s,H)?s[m].name:i(s,v)?void 0:u(s))&&!(e=>c?.some(({alias:t})=>t===(e[o.Symbol.IsAlias]?u(e):e[o.Symbol.BaseName])))(e.field.table)){let t=u(e.field.table);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 C=!c||c.length===0,ee=this.buildWithCTE(e),w;y&&(w=y===!0?b` distinct`:b` distinct on (${b.join(y.on,b`, `)})`);let te=this.buildSelection(S,{isSingleTable:C}),ne=this.buildFromTable(s),T=this.buildJoins(c),re=r?b` where ${r}`:void 0,ie=a?b` having ${a}`:void 0,E;l&&l.length>0&&(E=b` order by ${b.join(l,b`, `)}`);let ae;f&&f.length>0&&(ae=b` group by ${b.join(f,b`, `)}`);let oe=typeof p==`object`||typeof p==`number`&&p>=0?b` limit ${p}`:void 0,se=h?b` offset ${h}`:void 0,D=b.empty();if(g){let e=b` for ${b.raw(g.strength)}`;g.config.of&&e.append(b` of ${b.join(Array.isArray(g.config.of)?g.config.of:[g.config.of],b`, `)}`),g.config.noWait?e.append(b` nowait`):g.config.skipLocked&&e.append(b` skip locked`),D.append(e)}let O=b`${ee}select${w} ${te} from ${ne}${T}${re}${ae}${ie}${E}${oe}${se}${D}`;return x.length>0?this.buildSetOperations(O,x):O}buildSetOperations(e,t){let[n,...r]=t;if(!n)throw Error(`Cannot pass undefined values to any set operator`);return r.length===0?this.buildSetOperationQuery({leftSelect:e,setOperator:n}):this.buildSetOperations(this.buildSetOperationQuery({leftSelect:e,setOperator:n}),r)}buildSetOperationQuery({leftSelect:e,setOperator:{type:n,isAll:r,rightSelect:a,limit:o,orderBy:s,offset:c}}){let l=b`(${e.getSQL()}) `,u=b`(${a.getSQL()})`,d;if(s&&s.length>0){let e=[];for(let n of s)if(i(n,t))e.push(b.identifier(n.name));else if(i(n,v)){for(let e=0;e<n.queryChunks.length;e++){let r=n.queryChunks[e];i(r,t)&&(n.queryChunks[e]=b.identifier(r.name))}e.push(b`${n}`)}else e.push(b`${n}`);d=b` order by ${b.join(e,b`, `)} `}let f=typeof o==`object`||typeof o==`number`&&o>=0?b` limit ${o}`:void 0,p=b.raw(`${n} ${r?`all `:``}`),m=c?b` offset ${c}`:void 0;return b`${l}${p}${u}${d}${f}${m}`}buildInsertQuery({table:e,values:t,onConflict:n,returning:r,withList:a,select:s,overridingSystemValue_:c}){let l=[],u=e[o.Symbol.Columns],d=Object.entries(u).filter(([e,t])=>!t.shouldDisableInsert()),f=d.map(([,e])=>b.identifier(this.casing.getColumnCasing(e)));if(s){let e=t;i(e,v)?l.push(e):l.push(e.getSQL())}else{let e=t;l.push(b.raw(`values `));for(let[t,n]of e.entries()){let r=[];for(let[e,t]of d){let a=n[e];if(a===void 0||i(a,y)&&a.value===void 0)if(t.defaultFn!==void 0){let e=t.defaultFn(),n=i(e,v)?e:b.param(e,t);r.push(n)}else if(!t.default&&t.onUpdateFn!==void 0){let e=t.onUpdateFn(),n=i(e,v)?e:b.param(e,t);r.push(n)}else r.push(b`default`);else r.push(a)}l.push(r),t<e.length-1&&l.push(b`, `)}}let p=this.buildWithCTE(a),m=b.join(l),h=r?b` returning ${this.buildSelection(r,{isSingleTable:!0})}`:void 0,g=n?b` on conflict ${n}`:void 0;return b`${p}insert into ${e} ${f} ${c===!0?b`overriding system value `:void 0}${m}${g}${h}`}buildRefreshMaterializedViewQuery({view:e,concurrently:t,withNoData:n}){return b`refresh materialized view${t?b` concurrently`:void 0} ${e}${n?b` with no data`:void 0}`}prepareTyping(e){return i(e,ge)||i(e,ue)?`json`:i(e,te)?`decimal`:i(e,oe)?`time`:i(e,fe)||i(e,ye)?`timestamp`:i(e,ee)||i(e,he)?`date`:i(e,_e)?`uuid`:`none`}sqlToQuery(e,t){return e.toQuery({casing:this.casing,escapeName:this.escapeName,escapeParam:this.escapeParam,escapeString:this.escapeString,prepareTyping:this.prepareTyping,invokeSource:t})}_buildRelationalQuery({fullSchema:e,schema:t,tableNamesMap:n,table:a,tableConfig:o,queryConfig:s,tableAlias:c,nestedQueryRelation:l,joinOn:u}){let f=[],p,m,h=[],g,y=[];if(s===!0)f=Object.entries(o.columns).map(([e,t])=>({dbKey:t.name,tsKey:e,field:k(t,c),relationTableTsKey:void 0,isJson:!1,selection:[]}));else{let a=Object.fromEntries(Object.entries(o.columns).map(([e,t])=>[e,k(t,c)]));if(s.where){let e=typeof s.where==`function`?s.where(a,Ce()):s.where;g=e&&we(e,c)}let l=[],u=[];if(s.columns){let e=!1;for(let[t,n]of Object.entries(s.columns))n!==void 0&&t in o.columns&&(!e&&n===!0&&(e=!0),u.push(t));u.length>0&&(u=e?u.filter(e=>s.columns?.[e]===!0):Object.keys(o.columns).filter(e=>!u.includes(e)))}else u=Object.keys(o.columns);for(let e of u){let t=o.columns[e];l.push({tsKey:e,value:t})}let x=[];s.with&&(x=Object.entries(s.with).filter(e=>!!e[1]).map(([e,t])=>({tsKey:e,queryConfig:t,relation:o.relations[e]})));let S;if(s.extras){S=typeof s.extras==`function`?s.extras(a,{sql:b}):s.extras;for(let[e,t]of Object.entries(S))l.push({tsKey:e,value:ae(t,c)})}for(let{tsKey:e,value:t}of l)f.push({dbKey:i(t,v.Aliased)?t.fieldAlias:o.columns[e].name,tsKey:e,field:i(t,d)?k(t,c):t,relationTableTsKey:void 0,isJson:!1,selection:[]});let C=typeof s.orderBy==`function`?s.orderBy(a,ce()):s.orderBy??[];Array.isArray(C)||(C=[C]),h=C.map(e=>i(e,d)?k(e,c):we(e,c)),p=s.limit,m=s.offset;for(let{tsKey:a,queryConfig:o,relation:s}of x){let l=ve(t,n,s),u=n[r(s.referencedTable)],d=`${c}_${a}`,p=E(...l.fields.map((e,t)=>re(k(l.references[t],d),k(e,c)))),m=this._buildRelationalQuery({fullSchema:e,schema:t,tableNamesMap:n,table:e[u],tableConfig:t[u],queryConfig:i(s,be)?o===!0?{limit:1}:{...o,limit:1}:o,tableAlias:d,joinOn:p,nestedQueryRelation:s}),h=b`${b.identifier(d)}.${b.identifier(`data`)}`.as(a);y.push({on:b`true`,table:new _(m.sql,{},d),alias:d,joinType:`left`,lateral:!0}),f.push({dbKey:a,tsKey:a,field:h,relationTableTsKey:u,isJson:!0,selection:m.selection})}}if(f.length===0)throw new N({message:`No fields selected for table "${o.tsName}" ("${c}")`});let x;if(g=E(u,g),l){let e=b`json_build_array(${b.join(f.map(({field:e,tsKey:t,isJson:n})=>n?b`${b.identifier(`${c}_${t}`)}.${b.identifier(`data`)}`:i(e,v.Aliased)?e.sql:e),b`, `)})`;i(l,se)&&(e=b`coalesce(json_agg(${e}${h.length>0?b` order by ${b.join(h,b`, `)}`:void 0}), '[]'::json)`);let t=[{dbKey:`data`,tsKey:`data`,field:e.as(`data`),isJson:!0,relationTableTsKey:o.tsName,selection:f}];p!==void 0||m!==void 0||h.length>0?(x=this.buildSelectQuery({table:M(a,c),fields:{},fieldsFlat:[{path:[],field:b.raw(`*`)}],where:g,limit:p,offset:m,orderBy:h,setOperators:[]}),g=void 0,p=void 0,m=void 0,h=[]):x=M(a,c),x=this.buildSelectQuery({table:i(x,w)?x:new _(x,{},c),fields:{},fieldsFlat:t.map(({field:e})=>({path:[],field:i(e,d)?k(e,c):e})),joins:y,where:g,limit:p,offset:m,orderBy:h,setOperators:[]})}else x=this.buildSelectQuery({table:M(a,c),fields:{},fieldsFlat:f.map(({field:e})=>({path:[],field:i(e,d)?k(e,c):e})),joins:y,where:g,limit:p,offset:m,orderBy:h,setOperators:[]});return{tableTsKey:o.tsName,sql:x,selection:f}}nestedSelectionerror(){throw new N({message:`Views with nested selections are not supported by the relational query builder`})}buildRqbColumn(e,t,n){if(i(t,d)){let r=b`${e}.${b.identifier(this.casing.getColumnCasing(t))}`,a=t.columnType,o=t,s=0;for(;i(o,c);)o=o.baseColumn,a=o.columnType,++s;switch(a){case`PgNumeric`:case`PgNumericNumber`:case`PgNumericBigInt`:case`PgBigInt64`:case`PgBigIntString`:case`PgBigSerial64`:case`PgTimestampString`:case`PgGeometry`:case`PgGeometryObject`:case`PgBytea`:{let e=`[]`.repeat(s);return b`${r}::text${b.raw(e).if(e)} as ${b.identifier(n)}`}case`PgCustomColumn`:return b`${o.jsonSelectIdentifier(r,b,s>0?s:void 0)} as ${b.identifier(n)}`;default:return b`${r} as ${b.identifier(n)}`}}return b`${e}.${i(t,v.Aliased)?b.identifier(t.fieldAlias):p(t)?b.identifier(n):this.nestedSelectionerror()} as ${b.identifier(n)}`}unwrapAllColumns=(e,t)=>b.join(Object.entries(e[C]).map(([n,r])=>(t.push({key:n,field:r}),this.buildRqbColumn(e,r,n))),b`, `);buildColumns=(e,t,n)=>n?.columns?(()=>{let r=Object.entries(n.columns),i=e[C],a=[],o;for(let[n,s]of r)if(s!==void 0&&(o||=s,s)){let r=i[n];a.push(this.buildRqbColumn(e,r,n)),t.push({key:n,field:r})}if(o===!1)for(let[r,o]of Object.entries(i))n.columns[r]!==!1&&(a.push(this.buildRqbColumn(e,o,r)),t.push({key:r,field:o}));return a.length?b.join(a,b`, `):void 0})():this.unwrapAllColumns(e,t);buildRelationalQuery({schema:e,table:t,tableConfig:n,queryConfig:r,relationWhere:a,mode:o,errorPath:s,depth:c,throughJoin:l}){let u=[],d=o===`first`,f=r===!0?void 0:r,p=s??``,m=c??0;m||(t=M(t,`d${m}`));let h=d?1:f?.limit,g=f?.offset,_=f?.where&&a?E(De(t,f.where,n.relations,e,this.casing),a):f?.where?De(t,f.where,n.relations,e,this.casing):a,v=f?.orderBy?ke(t,f.orderBy):void 0,y=this.buildColumns(t,u,f),x=f?.extras?je(t,f.extras):void 0;x&&u.push(...x.selection);let S=y?[y]:[],C=f?(()=>{let{with:r}=f;if(!r)return;let a=Object.entries(r).filter(([e,t])=>t);if(a.length)return b.join(a.map(([r,a])=>{let o=n.relations[r],s=i(o,Me),c=M(o.targetTable,`d${m+1}`),l=o.throughTable?M(o.throughTable,`tr${m}`):void 0,{filter:d,joinCondition:f}=Ne(this.casing,o,t,c,l);S.push(b`${b.identifier(r)}.${b.identifier(`r`)} as ${b.identifier(r)}`);let h=l?b` inner join ${Oe(l)} on ${f}`:void 0,g=this.buildRelationalQuery({table:c,mode:s?`first`:`many`,schema:e,queryConfig:a,tableConfig:e[o.targetTableName],relationWhere:d,errorPath:`${p.length?`${p}.`:``}${r}`,depth:m+1,throughJoin:h});return u.push({field:c,key:r,selection:g.selection,isArray:!s,isOptional:(o.optional??!1)||a!==!0&&!!a.where}),b`left join lateral(select ${s?b`row_to_json(${b.identifier(`t`)}.*) ${b.identifier(`r`)}`:b`coalesce(json_agg(row_to_json(${b.identifier(`t`)}.*)), '[]') as ${b.identifier(`r`)}`} from (${g.sql}) as ${b.identifier(`t`)}) as ${b.identifier(r)} on true`}),b` `)})():void 0;if(x?.sql&&S.push(x.sql),!S.length)throw new N({message:`No fields selected for table "${n.name}"${p?` ("${p}")`:``}`});return{sql:b`select ${b.join(S.filter(e=>e!==void 0),b`, `)} from ${Oe(t)}${l}${b` ${C}`.if(C)}${b` where ${_}`.if(_)}${b` order by ${v}`.if(v)}${b` limit ${h}`.if(h!==void 0)}${b` offset ${g}`.if(g!==void 0)}`,selection:u}}},W=class{static[n]=`PgSelectBuilder`;fields;session;dialect;withList=[];distinct;constructor(e){this.fields=e.fields,this.session=e.session,this.dialect=e.dialect,e.withList&&(this.withList=e.withList),this.distinct=e.distinct}authToken;setToken(e){return this.authToken=e,this}from(e){let t=!!this.fields,n=e,r;return r=this.fields?this.fields:i(n,_)?Object.fromEntries(Object.keys(n._.selectedFields).map(e=>[e,n[e]])):i(n,H)?n[m].selectedFields:i(n,v)?{}:L(n),new G({table:n,fields:r,isPartialSelect:t,session:this.session,dialect:this.dialect,withList:this.withList,distinct:this.distinct}).setToken(this.authToken)}},Ke=class extends Se{static[n]=`PgSelectQueryBuilder`;_;config;joinsNotNullableMap;tableName;isPartialSelect;session;dialect;cacheConfig=void 0;usedTables=new Set;constructor({table:e,fields:t,isPartialSelect:n,session:r,dialect:i,withList:a,distinct:o}){super(),this.config={withList:a,table:e,fields:{...t},distinct:o,setOperators:[]},this.isPartialSelect=n,this.session=r,this.dialect=i,this._={selectedFields:t,config:this.config},this.tableName=O(e),this.joinsNotNullableMap=typeof this.tableName==`string`?{[this.tableName]:!0}:{};for(let t of B(e))this.usedTables.add(t)}getUsedTables(){return[...this.usedTables]}createJoin(e,t){return((n,r)=>{let a=this.tableName,s=O(n);for(let e of B(n))this.usedTables.add(e);if(typeof s==`string`&&this.config.joins?.some(e=>e.alias===s))throw Error(`Alias "${s}" is already used in this query`);if(!this.isPartialSelect&&(Object.keys(this.joinsNotNullableMap).length===1&&typeof a==`string`&&(this.config.fields={[a]:this.config.fields}),typeof s==`string`&&!i(n,v))){let e=i(n,_)?n._.selectedFields:i(n,f)?n[m].selectedFields:n[o.Symbol.Columns];this.config.fields[s]=e}if(typeof r==`function`&&(r=r(new Proxy(this.config.fields,new I({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})))),this.config.joins||(this.config.joins=[]),this.config.joins.push({on:r,table:n,joinType:e,alias:s,lateral:t}),typeof s==`string`)switch(e){case`left`:this.joinsNotNullableMap[s]=!1;break;case`right`:this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[s]=!0;break;case`cross`:case`inner`:this.joinsNotNullableMap[s]=!0;break;case`full`:this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[s]=!1;break}return this})}leftJoin=this.createJoin(`left`,!1);leftJoinLateral=this.createJoin(`left`,!0);rightJoin=this.createJoin(`right`,!1);innerJoin=this.createJoin(`inner`,!1);innerJoinLateral=this.createJoin(`inner`,!0);fullJoin=this.createJoin(`full`,!1);crossJoin=this.createJoin(`cross`,!1);crossJoinLateral=this.createJoin(`cross`,!0);createSetOperator(e,t){return n=>{let r=typeof n==`function`?n(qe()):n;if(!j(this.getSelectedFields(),r.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:r}),this}}union=this.createSetOperator(`union`,!1);unionAll=this.createSetOperator(`union`,!0);intersect=this.createSetOperator(`intersect`,!1);intersectAll=this.createSetOperator(`intersect`,!0);except=this.createSetOperator(`except`,!1);exceptAll=this.createSetOperator(`except`,!0);addSetOperators(e){return this.config.setOperators.push(...e),this}where(e){return typeof e==`function`&&(e=e(new Proxy(this.config.fields,new I({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})))),this.config.where=e,this}having(e){return typeof e==`function`&&(e=e(new Proxy(this.config.fields,new I({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})))),this.config.having=e,this}groupBy(...e){if(typeof e[0]==`function`){let t=e[0](new Proxy(this.config.fields,new I({sqlAliasedBehavior:`alias`,sqlBehavior:`sql`})));this.config.groupBy=Array.isArray(t)?t:[t]}else this.config.groupBy=e;return this}orderBy(...e){if(typeof e[0]==`function`){let t=e[0](new Proxy(this.config.fields,new I({sqlAliasedBehavior:`alias`,sqlBehavior:`sql`}))),n=Array.isArray(t)?t:[t];this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=n:this.config.orderBy=n}else{let t=e;this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=t:this.config.orderBy=t}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}for(e,t={}){return this.config.lockingClause={strength:e,config:t},this}getSQL(){return this.dialect.buildSelectQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}as(e){let t=[];if(t.push(...B(this.config.table)),this.config.joins)for(let e of this.config.joins)t.push(...B(e.table));return new Proxy(new _(this.getSQL(),this.config.fields,e,!1,[...new Set(t)]),new I({alias:e,sqlAliasedBehavior:`alias`,sqlBehavior:`error`}))}getSelectedFields(){return new Proxy(this.config.fields,new I({alias:this.tableName,sqlAliasedBehavior:`alias`,sqlBehavior:`error`}))}$dynamic(){return this}$withCache(e){return this.cacheConfig=e===void 0?{config:{},enable:!0,autoInvalidate:!0}:e===!1?{enable:!1}:{enable:!0,autoInvalidate:!0,...e},this}},G=class extends Ke{static[n]=`PgSelect`;_prepare(e){let{session:t,config:n,dialect:r,joinsNotNullableMap:i,authToken:a,cacheConfig:o,usedTables:s}=this;if(!t)throw Error(`Cannot execute a query on a query builder. Please use a database instance instead.`);let{fields:c}=n;return h.startActiveSpan(`drizzle.prepareQuery`,()=>{let n=P(c),l=t.prepareQuery(r.sqlToQuery(this.getSQL()),n,e,!0,void 0,{type:`select`,tables:[...s]},o);return l.joinsNotNullableMap=i,l.setToken(a)})}prepare(e){return this._prepare(e)}authToken;setToken(e){return this.authToken=e,this}execute=e=>h.startActiveSpan(`drizzle.operation`,()=>this._prepare().execute(e,this.authToken))};D(G,[A]);function K(e,t){return(n,r,...i)=>{let a=[r,...i].map(n=>({type:e,isAll:t,rightSelect:n}));for(let e of a)if(!j(n.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 n.addSetOperators(a)}}const qe=()=>({union:Je,unionAll:Ye,intersect:Xe,intersectAll:Ze,except:Qe,exceptAll:$e}),Je=K(`union`,!1),Ye=K(`union`,!0),Xe=K(`intersect`,!1),Ze=K(`intersect`,!0),Qe=K(`except`,!1),$e=K(`except`,!0);var q=class{static[n]=`PgQueryBuilder`;dialect;dialectConfig;constructor(e){this.dialect=i(e,U)?e:void 0,this.dialectConfig=i(e,U)?void 0:e}$with=(e,t)=>{let n=this;return{as:r=>(typeof r==`function`&&(r=r(n)),new Proxy(new g(r.getSQL(),t??(`getSelectedFields`in r?r.getSelectedFields()??{}:{}),e,!0),new I({alias:e,sqlAliasedBehavior:`alias`,sqlBehavior:`error`})))}};with(...e){let t=this;function n(n){return new W({fields:n??void 0,session:void 0,dialect:t.getDialect(),withList:e})}function r(e){return new W({fields:e??void 0,session:void 0,dialect:t.getDialect(),distinct:!0})}function i(e,n){return new W({fields:n??void 0,session:void 0,dialect:t.getDialect(),distinct:{on:e}})}return{select:n,selectDistinct:r,selectDistinctOn:i}}select(e){return new W({fields:e??void 0,session:void 0,dialect:this.getDialect()})}selectDistinct(e){return new W({fields:e??void 0,session:void 0,dialect:this.getDialect(),distinct:!0})}selectDistinctOn(e,t){return new W({fields:t??void 0,session:void 0,dialect:this.getDialect(),distinct:{on:e}})}getDialect(){return this.dialect||=new U(this.dialectConfig),this.dialect}},J=class{constructor(e,t,n,r,i){this.table=e,this.session=t,this.dialect=n,this.withList=r,this.overridingSystemValue_=i}static[n]=`PgInsertBuilder`;authToken;setToken(e){return this.authToken=e,this}overridingSystemValue(){return this.overridingSystemValue_=!0,this}values(e){if(e=Array.isArray(e)?e:[e],e.length===0)throw Error(`values() must be called with at least one value`);let t=e.map(e=>{let t={},n=this.table[o.Symbol.Columns];for(let r of Object.keys(e)){let a=e[r];t[r]=i(a,v)?a:new y(a,n[r])}return t});return new Y(this.table,t,this.session,this.dialect,this.withList,!1,this.overridingSystemValue_).setToken(this.authToken)}select(e){let t=typeof e==`function`?e(new q):e;if(!i(t,v)&&!j(this.table[C],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 Y(this.table,t,this.session,this.dialect,this.withList,!0)}},Y=class extends A{constructor(e,t,n,r,i,a,o){super(),this.session=n,this.dialect=r,this.config={table:e,values:t,withList:i,select:a,overridingSystemValue_:o}}static[n]=`PgInsert`;config;cacheConfig;returning(e=this.config.table[o.Symbol.Columns]){return this.config.returningFields=e,this.config.returning=P(e),this}onConflictDoNothing(e={}){if(e.target===void 0)this.config.onConflict=b`do nothing`;else{let t=``;t=Array.isArray(e.target)?e.target.map(e=>this.dialect.escapeName(this.dialect.casing.getColumnCasing(e))).join(`,`):this.dialect.escapeName(this.dialect.casing.getColumnCasing(e.target));let n=e.where?b` where ${e.where}`:void 0;this.config.onConflict=b`(${b.raw(t)})${n} do nothing`}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?b` where ${e.where}`:void 0,n=e.targetWhere?b` where ${e.targetWhere}`:void 0,r=e.setWhere?b` where ${e.setWhere}`:void 0,i=this.dialect.buildUpdateSet(this.config.table,de(this.config.table,e.set)),a=``;return a=Array.isArray(e.target)?e.target.map(e=>this.dialect.escapeName(this.dialect.casing.getColumnCasing(e))).join(`,`):this.dialect.escapeName(this.dialect.casing.getColumnCasing(e.target)),this.config.onConflict=b`(${b.raw(a)})${n} do update set ${i}${t}${r}`,this}getSQL(){return this.dialect.buildInsertQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e){return h.startActiveSpan(`drizzle.prepareQuery`,()=>this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()),this.config.returning,e,!0,void 0,{type:`insert`,tables:B(this.config.table)},this.cacheConfig))}prepare(e){return this._prepare(e)}authToken;setToken(e){return this.authToken=e,this}execute=e=>h.startActiveSpan(`drizzle.operation`,()=>this._prepare().execute(e,this.authToken));getSelectedFields(){return this.config.returningFields?new Proxy(this.config.returningFields,new I({alias:u(this.config.table),sqlAliasedBehavior:`alias`,sqlBehavior:`error`})):void 0}$dynamic(){return this}},et=class extends A{constructor(e,t,n){super(),this.session=t,this.dialect=n,this.config={view:e}}static[n]=`PgRefreshMaterializedView`;config;concurrently(){if(this.config.withNoData!==void 0)throw Error(`Cannot use concurrently and withNoData together`);return this.config.concurrently=!0,this}withNoData(){if(this.config.concurrently!==void 0)throw Error(`Cannot use concurrently and withNoData together`);return this.config.withNoData=!0,this}getSQL(){return this.dialect.buildRefreshMaterializedViewQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e){return h.startActiveSpan(`drizzle.prepareQuery`,()=>this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()),void 0,e,!0))}prepare(e){return this._prepare(e)}authToken;setToken(e){return this.authToken=e,this}execute=e=>h.startActiveSpan(`drizzle.operation`,()=>this._prepare().execute(e,this.authToken))},X=class{constructor(e,t,n,r){this.table=e,this.session=t,this.dialect=n,this.withList=r}static[n]=`PgUpdateBuilder`;authToken;setToken(e){return this.authToken=e,this}set(e){return new tt(this.table,de(this.table,e),this.session,this.dialect,this.withList).setToken(this.authToken)}},tt=class extends A{constructor(e,t,n,r,i){super(),this.session=n,this.dialect=r,this.config={set:t,table:e,withList:i,joins:[]},this.tableName=O(e),this.joinsNotNullableMap=typeof this.tableName==`string`?{[this.tableName]:!0}:{}}static[n]=`PgUpdate`;config;tableName;joinsNotNullableMap;cacheConfig;from(e){let t=e,n=O(t);return typeof n==`string`&&(this.joinsNotNullableMap[n]=!0),this.config.from=t,this}getTableLikeFields(e){return i(e,w)?e[o.Symbol.Columns]:i(e,_)?e._.selectedFields:e[m].selectedFields}createJoin(e){return((t,n)=>{let r=O(t);if(typeof r==`string`&&this.config.joins.some(e=>e.alias===r))throw Error(`Alias "${r}" is already used in this query`);if(typeof n==`function`){let e=this.config.from&&!i(this.config.from,v)?this.getTableLikeFields(this.config.from):void 0;n=n(new Proxy(this.config.table[o.Symbol.Columns],new I({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})),e&&new Proxy(e,new I({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})))}if(this.config.joins.push({on:n,table:t,joinType:e,alias:r}),typeof r==`string`)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;break}return 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}returning(e){if(!e&&(e=Object.assign({},this.config.table[o.Symbol.Columns]),this.config.from)){let t=O(this.config.from);if(typeof t==`string`&&this.config.from&&!i(this.config.from,v)){let n=this.getTableLikeFields(this.config.from);e[t]=n}for(let t of this.config.joins){let n=O(t.table);if(typeof n==`string`&&!i(t.table,v)){let r=this.getTableLikeFields(t.table);e[n]=r}}}return this.config.returningFields=e,this.config.returning=P(e),this}getSQL(){return this.dialect.buildUpdateQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e){let t=this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()),this.config.returning,e,!0,void 0,{type:`insert`,tables:B(this.config.table)},this.cacheConfig);return t.joinsNotNullableMap=this.joinsNotNullableMap,t}prepare(e){return this._prepare(e)}authToken;setToken(e){return this.authToken=e,this}execute=e=>this._prepare().execute(e,this.authToken);getSelectedFields(){return this.config.returningFields?new Proxy(this.config.returningFields,new I({alias:u(this.config.table),sqlAliasedBehavior:`alias`,sqlBehavior:`error`})):void 0}$dynamic(){return this}},nt=class{constructor(e,t,n,r,i,a,o){this.fullSchema=e,this.schema=t,this.tableNamesMap=n,this.table=r,this.tableConfig=i,this.dialect=a,this.session=o}static[n]=`PgRelationalQueryBuilder`;findMany(e){return new rt(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e||{},`many`)}findFirst(e){return new rt(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e?{...e,limit:1}:{limit:1},`first`)}},rt=class extends A{constructor(e,t,n,r,i,a,o,s,c){super(),this.fullSchema=e,this.schema=t,this.tableNamesMap=n,this.table=r,this.tableConfig=i,this.dialect=a,this.session=o,this.config=s,this.mode=c}static[n]=`PgRelationalQuery`;_prepare(e){return h.startActiveSpan(`drizzle.prepareQuery`,()=>{let{query:t,builtQuery:n}=this._toSQL();return this.session.prepareQuery(n,void 0,e,!0,(e,n)=>{let r=e.map(e=>le(this.schema,this.tableConfig,e,t.selection,n));return this.mode===`first`?r[0]:r})})}prepare(e){return this._prepare(e)}_getQuery(){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})}getSQL(){return this._getQuery().sql}_toSQL(){let e=this._getQuery();return{query:e,builtQuery:this.dialect.sqlToQuery(e.sql)}}toSQL(){return this._toSQL().builtQuery}authToken;setToken(e){return this.authToken=e,this}execute(){return h.startActiveSpan(`drizzle.operation`,()=>this._prepare().execute(void 0,this.authToken))}},it=class e extends v{constructor(t){super(e.buildEmbeddedCount(t.source,t.filters).queryChunks),this.params=t,this.mapWith(Number),this.session=t.session,this.sql=e.buildCount(t.source,t.filters)}sql;token;static[n]=`PgCountBuilder`;[Symbol.toStringTag]=`PgCountBuilder`;session;static buildEmbeddedCount(e,t){return b`(select count(*) from ${e}${b.raw(` where `).if(t)}${t})`}static buildCount(e,t){return b`select count(*) as count from ${e}${b.raw(` where `).if(t)}${t};`}setToken(e){return this.token=e,this}then(e,t){return Promise.resolve(this.session.count(this.sql,this.token)).then(e,t)}catch(e){return this.then(void 0,e)}finally(e){return this.then(t=>(e?.(),t),t=>{throw e?.(),t})}},at=class{constructor(e,t,n,r,i,a){this.schema=e,this.table=t,this.tableConfig=n,this.dialect=r,this.session=i,this.parseJson=a}static[n]=`PgRelationalQueryBuilderV2`;findMany(e){return new ot(this.schema,this.table,this.tableConfig,this.dialect,this.session,e??!0,`many`,this.parseJson)}findFirst(e){return new ot(this.schema,this.table,this.tableConfig,this.dialect,this.session,e??!0,`first`,this.parseJson)}},ot=class extends A{constructor(e,t,n,r,i,a,o,s){super(),this.schema=e,this.table=t,this.tableConfig=n,this.dialect=r,this.session=i,this.config=a,this.mode=o,this.parseJson=s}static[n]=`PgRelationalQueryV2`;_prepare(e){return h.startActiveSpan(`drizzle.prepareQuery`,()=>{let{query:t,builtQuery:n}=this._toSQL();return this.session.prepareRelationalQuery(n,void 0,e,(e,n)=>{for(let r of e)Ee(r,t.selection,n,this.parseJson);return this.mode===`first`?e[0]:e})})}prepare(e){return this._prepare(e)}_getQuery(){return this.dialect.buildRelationalQuery({schema:this.schema,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,mode:this.mode})}getSQL(){return this._getQuery().sql}_toSQL(){let e=this._getQuery();return{query:e,builtQuery:this.dialect.sqlToQuery(e.sql)}}toSQL(){return this._toSQL().builtQuery}authToken;setToken(e){return this.authToken=e,this}execute(){return h.startActiveSpan(`drizzle.operation`,()=>this._prepare().execute(void 0,this.authToken))}},st=class extends A{constructor(e,t,n,r){super(),this.execute=e,this.sql=t,this.query=n,this.mapBatchResult=r}static[n]=`PgRaw`;getSQL(){return this.sql}getQuery(){return this.query}mapResult(e,t){return t?this.mapBatchResult(e):e}_prepare(){return this}isResponseInArrayMode(){return!1}},ct=class{constructor(e,t,n,r,i=!1){if(this.dialect=e,this.session=t,this._=r?{schema:r.schema,fullSchema:r.fullSchema,tableNamesMap:r.tableNamesMap,relations:n,session:t}:{schema:void 0,fullSchema:{},tableNamesMap:{},relations:n,session:t},this._query={},this._.schema)for(let[n,i]of Object.entries(this._.schema))this._query[n]=new nt(r.fullSchema,this._.schema,this._.tableNamesMap,r.fullSchema[n],i,e,t);this.query={};for(let[r,a]of Object.entries(n))this.query[r]=new at(n,n[a.name].table,a,e,t,i);this.$cache={invalidate:async e=>{}}}static[n]=`PgDatabase`;_query;query;$with=(e,t)=>{let n=this;return{as:r=>(typeof r==`function`&&(r=r(new q(n.dialect))),new Proxy(new g(r.getSQL(),t??(`getSelectedFields`in r?r.getSelectedFields()??{}:{}),e,!0),new I({alias:e,sqlAliasedBehavior:`alias`,sqlBehavior:`error`})))}};$count(e,t){return new it({source:e,filters:t,session:this.session})}$cache;with(...e){let t=this;function n(n){return new W({fields:n??void 0,session:t.session,dialect:t.dialect,withList:e})}function r(n){return new W({fields:n??void 0,session:t.session,dialect:t.dialect,withList:e,distinct:!0})}function i(n,r){return new W({fields:r??void 0,session:t.session,dialect:t.dialect,withList:e,distinct:{on:n}})}function a(n){return new X(n,t.session,t.dialect,e)}function o(n){return new J(n,t.session,t.dialect,e)}function s(n){return new V(n,t.session,t.dialect,e)}return{select:n,selectDistinct:r,selectDistinctOn:i,update:a,insert:o,delete:s}}select(e){return new W({fields:e??void 0,session:this.session,dialect:this.dialect})}selectDistinct(e){return new W({fields:e??void 0,session:this.session,dialect:this.dialect,distinct:!0})}selectDistinctOn(e,t){return new W({fields:t??void 0,session:this.session,dialect:this.dialect,distinct:{on:e}})}update(e){return new X(e,this.session,this.dialect)}insert(e){return new J(e,this.session,this.dialect)}delete(e){return new V(e,this.session,this.dialect)}refreshMaterializedView(e){return new et(e,this.session,this.dialect)}authToken;execute(e){let t=typeof e==`string`?b.raw(e):e.getSQL(),n=this.dialect.sqlToQuery(t),r=this.session.prepareQuery(n,void 0,void 0,!1);return new st(()=>r.execute(void 0,this.authToken),t,n,e=>r.mapResult(e,!0))}transaction(e,t){return this.session.transaction(e,t)}},lt=class{constructor(e,t){this.name=e,t&&(this.createDb=t.createDb,this.createRole=t.createRole,this.inherit=t.inherit)}static[n]=`PgRole`;_existing;createDb;createRole;inherit;existing(){return this._existing=!0,this}},Z=class{constructor(e,t,n){this.seqName=e,this.seqOptions=t,this.schema=n}static[n]=`PgSequence`};function ut(e,t,n){return new Z(e,t,n)}function dt(e){return i(e,Z)}var ft=class{constructor(e,t){this.name=e,this.schema=t}static[n]=`PgDefaultViewBuilderCore`;config={};with(e){return this.config.with=e,this}},pt=class extends ft{static[n]=`PgViewBuilder`;as(e){typeof e==`function`&&(e=e(new q));let t=new I({alias:this.name,sqlBehavior:`error`,sqlAliasedBehavior:`alias`,replaceOriginalName:!0}),n=new Proxy(e.getSelectedFields(),t);return new Proxy(new Q({pgConfig:this.config,config:{name:this.name,schema:this.schema,selectedFields:n,query:e.getSQL().inlineParams()}}),t)}},mt=class extends ft{static[n]=`PgManualViewBuilder`;columns;constructor(e,t,n){super(e,n),this.columns=L(T(e,t))}existing(){return new Proxy(new Q({pgConfig:void 0,config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:void 0}}),new I({alias:this.name,sqlBehavior:`error`,sqlAliasedBehavior:`alias`,replaceOriginalName:!0}))}as(e){return new Proxy(new Q({pgConfig:this.config,config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:e.inlineParams()}}),new I({alias:this.name,sqlBehavior:`error`,sqlAliasedBehavior:`alias`,replaceOriginalName:!0}))}},ht=class{constructor(e,t){this.name=e,this.schema=t}static[n]=`PgMaterializedViewBuilderCore`;config={};using(e){return this.config.using=e,this}with(e){return this.config.with=e,this}tablespace(e){return this.config.tablespace=e,this}withNoData(){return this.config.withNoData=!0,this}},gt=class extends ht{static[n]=`PgMaterializedViewBuilder`;as(e){typeof e==`function`&&(e=e(new q));let t=new I({alias:this.name,sqlBehavior:`error`,sqlAliasedBehavior:`alias`,replaceOriginalName:!0}),n=new Proxy(e.getSelectedFields(),t);return new Proxy(new $({pgConfig:{with:this.config.with,using:this.config.using,tablespace:this.config.tablespace,withNoData:this.config.withNoData},config:{name:this.name,schema:this.schema,selectedFields:n,query:e.getSQL().inlineParams()}}),t)}},_t=class extends ht{static[n]=`PgManualMaterializedViewBuilder`;columns;constructor(e,t,n){super(e,n),this.columns=L(T(e,t))}existing(){return new Proxy(new $({pgConfig:{tablespace:this.config.tablespace,using:this.config.using,with:this.config.with,withNoData:this.config.withNoData},config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:void 0}}),new I({alias:this.name,sqlBehavior:`error`,sqlAliasedBehavior:`alias`,replaceOriginalName:!0}))}as(e){return new Proxy(new $({pgConfig:{tablespace:this.config.tablespace,using:this.config.using,with:this.config.with,withNoData:this.config.withNoData},config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:e.inlineParams()}}),new I({alias:this.name,sqlBehavior:`error`,sqlAliasedBehavior:`alias`,replaceOriginalName:!0}))}},Q=class extends H{static[n]=`PgView`;[R];constructor({pgConfig:e,config:t}){super(t),e&&(this[R]={with:e.with})}},$=class extends H{static[n]=`PgMaterializedView`;[z];constructor({pgConfig:e,config:t}){super(t),this[z]={with:e?.with,using:e?.using,tablespace:e?.tablespace,withNoData:e?.withNoData}}};function vt(e,t,n){return t?new mt(e,t,n):new pt(e,n)}function yt(e,t,n){return t?new _t(e,t,n):new gt(e,n)}function bt(e){return i(e,Q)}function xt(e){return i(e,$)}var St=class{constructor(e){this.schemaName=e,this.table=Object.assign(this.table,{withRLS:((e,t,n)=>{let r=xe(e,t,n,this.schemaName);return r[ie]=!0,r})})}static[n]=`PgSchema`;isExisting=!1;table=((e,t,n)=>xe(e,t,n,this.schemaName));view=((e,t)=>vt(e,t,this.schemaName));materializedView=((e,t)=>yt(e,t,this.schemaName));enum(e,t){return Array.isArray(t)?s(e,[...t],this.schemaName):S(e,t,this.schemaName)}sequence=((e,t)=>ut(e,t,this.schemaName));getSQL(){return new v([b.identifier(this.schemaName)])}shouldOmitSQLParens(){return!0}existing(){return this.isExisting=!0,this}},Ct=class{constructor(e,t,n,r){this.query=e,this.cache=t,this.queryMetadata=n,this.cacheConfig=r,t&&t.strategy()===`all`&&r===void 0&&(this.cacheConfig={enable:!0,autoInvalidate:!0}),this.cacheConfig?.enable||(this.cacheConfig=void 0)}authToken;getQuery(){return this.query}mapResult(e,t){return e}setToken(e){return this.authToken=e,this}static[n]=`PgPreparedQuery`;joinsNotNullableMap;async queryWithCache(e,t,n){if(this.cache===void 0||i(this.cache,Pe)||this.queryMetadata===void 0)try{return await n()}catch(n){throw new F(e,t,n)}if(this.cacheConfig&&!this.cacheConfig.enable)try{return await n()}catch(n){throw new F(e,t,n)}if((this.queryMetadata.type===`insert`||this.queryMetadata.type===`update`||this.queryMetadata.type===`delete`)&&this.queryMetadata.tables.length>0)try{let[e]=await Promise.all([n(),this.cache.onMutate({tables:this.queryMetadata.tables})]);return e}catch(n){throw new F(e,t,n)}if(!this.cacheConfig)try{return await n()}catch(n){throw new F(e,t,n)}if(this.queryMetadata.type===`select`){let r=await this.cache.get(this.cacheConfig.tag??await Ae(e,t),this.queryMetadata.tables,this.cacheConfig.tag!==void 0,this.cacheConfig.autoInvalidate);if(r===void 0){let r;try{r=await n()}catch(n){throw new F(e,t,n)}return await this.cache.put(this.cacheConfig.tag??await Ae(e,t),r,this.cacheConfig.autoInvalidate?this.queryMetadata.tables:[],this.cacheConfig.tag!==void 0,this.cacheConfig.config),r}return r}try{return await n()}catch(n){throw new F(e,t,n)}}},wt=class{constructor(e){this.dialect=e}static[n]=`PgSession`;execute(e,t){return h.startActiveSpan(`drizzle.operation`,()=>h.startActiveSpan(`drizzle.prepareQuery`,()=>this.prepareQuery(this.dialect.sqlToQuery(e),void 0,void 0,!1)).setToken(t).execute(void 0,t))}all(e){return this.prepareQuery(this.dialect.sqlToQuery(e),void 0,void 0,!1).all()}async count(e,t){let n=await this.execute(e,t);return Number(n[0].count)}},Tt=class extends ct{constructor(e,t,n,r,i=0,a){super(e,t,n,r,a),this.relations=n,this.schema=r,this.nestedIndex=i}static[n]=`PgTransaction`;rollback(){throw new me}getTransactionConfigSQL(e){let t=[];return e.isolationLevel&&t.push(`isolation level ${e.isolationLevel}`),e.accessMode&&t.push(e.accessMode),typeof e.deferrable==`boolean`&&t.push(e.deferrable?`deferrable`:`not deferrable`),b.raw(t.join(` `))}setTransaction(e){return this.session.execute(b`set transaction ${this.getTransactionConfigSQL(e)}`)}};export{Ke as A,Ge as B,X as C,q as D,J as E,Je as F,He as G,We as H,Ye as I,ze as J,Ve as K,U as L,$e as M,Xe as N,G as O,Ze as P,Fe as Q,V as R,tt as S,Y as T,z as U,Ue as V,R as W,Le as X,Re as Y,Ie as Z,Z as _,ft as a,lt as b,gt as c,Q as d,pt as f,vt as g,yt as h,St as i,Qe as j,W as k,ht as l,bt as m,wt as n,_t as o,xt as p,Be as q,Tt as r,mt as s,Ct as t,$ as u,dt as v,et as w,ct as x,ut as y,B as z};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{A as ee,C as te,D as e,E as ne,N as re,O as t,P as n,S as r,T as i,_ as a,b as o,g as s,j as c,k as l,v as u,w as d,x as f,y as p}from"./sql-D-eKV1Dn.mjs";import{$ as m,$n as h,$t as g,An as _,At as v,Bn as y,Bt as b,Cn as x,Ct as S,Dn as C,Dt as w,En as T,Et as E,Fn as D,Ft as O,G as k,Gn as A,Gt as j,H as M,Hn as N,Ht as P,In as F,It as I,J as L,Jn as R,Jt as z,K as B,Kn as V,Kt as H,Ln as U,Lt as W,Mn as G,Mt as K,Nn as q,Nt as J,On as Y,Ot as X,Pn as ie,Pt as ae,Q as oe,Qn as se,Qt as ce,Rn as le,Rt as ue,Sn as de,St as fe,Tn as pe,Tt as me,U as he,Un as ge,Ut as _e,V as ve,Vn as ye,Vt as be,W as xe,Wn as Se,Wt as Ce,X as we,Xn as Te,Xt as Ee,Y as De,Yn as Oe,Yt as ke,Z as Ae,Zn as je,Zt as Me,_n as Ne,_t as Pe,an as Fe,at as Ie,bn as Le,bt as Re,cn as ze,ct as Be,dn as Ve,dt as He,en as Ue,er as We,et as Ge,fn as Ke,ft as qe,gn as Je,gt as Ye,hn as Xe,ht as Ze,in as Qe,it as $e,jn as et,jt as tt,kn as nt,kt as Z,ln as rt,lt as it,mn as at,mt as ot,nn as st,nr as ct,nt as lt,on as ut,ot as dt,pn as ft,pt,q as mt,qn as ht,qt as gt,rn as _t,rt as vt,sn as yt,st as bt,tn as xt,tr as St,tt as Ct,un as wt,ut as Tt,vn as Et,vt as Dt,wn as Ot,wt as kt,xn as At,xt as jt,yn as Mt,yt as Nt,zn as Pt,zt as Ft}from"./query-builder-V8-LDhvA.mjs";import{A as It,B as Lt,C as Rt,D as zt,E as Bt,F as Vt,G as Ht,H as Ut,I as Wt,J as Gt,K as Kt,L as Q,M as qt,N as Jt,O as Yt,P as Xt,Q as Zt,R as Qt,S as $t,T as en,U as tn,V as $,W as nn,X as rn,Y as an,Z as on,_ as sn,a as cn,b as ln,c as un,d as dn,f as fn,g as pn,h as mn,i as hn,j as gn,k as _n,l as vn,m as yn,n as bn,o as xn,p as Sn,q as Cn,r as wn,s as Tn,t as En,u as Dn,v as On,w as kn,x as An,y as jn,z as Mn}from"./pg-core-BLTZt9AH.mjs";export{Q as PgDialect,k as PgTable,$ as getTableConfig};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{G as e,o as t,u as n}from"./sql-D-eKV1Dn.mjs";import{c as r,dr as i,l as a}from"./query-builder-V8-LDhvA.mjs";import{n as o,t as s}from"./logger-BAGZLUzj.mjs";import{t as c}from"./cache-3oO07miM.mjs";import{L as l,n as u,r as d,t as f,x as p}from"./pg-core-BLTZt9AH.mjs";import{PGlite as m,types as h}from"@electric-sql/pglite";var g=class extends f{constructor(e,t,n,r,i,a,o,s,c,l,u,d){super({sql:t,params:n},i,a,o),this.client=e,this.queryString=t,this.params=n,this.logger=r,this.fields=s,this._isResponseInArrayMode=l,this.customResultMapper=u,this.isRqbV2Query=d,this.rawQueryConfig={rowMode:`object`,parsers:{[h.TIMESTAMP]:e=>e,[h.TIMESTAMPTZ]:e=>e,[h.INTERVAL]:e=>e,[h.DATE]:e=>e,1231:e=>e,1115:e=>e,1185:e=>e,1187:e=>e,1182:e=>e}},this.queryConfig={rowMode:`array`,parsers:{[h.TIMESTAMP]:e=>e,[h.TIMESTAMPTZ]:e=>e,[h.INTERVAL]:e=>e,[h.DATE]:e=>e,1231:e=>e,1115:e=>e,1185:e=>e,1187:e=>e,1182:e=>e}}}static[e]=`PglitePreparedQuery`;rawQueryConfig;queryConfig;async execute(e={}){if(this.isRqbV2Query)return this.executeRqbV2(e);let n=t(this.params,e);this.logger.logQuery(this.queryString,n);let{fields:r,client:a,queryConfig:o,joinsNotNullableMap:s,customResultMapper:c,queryString:l,rawQueryConfig:u}=this;if(!r&&!c)return this.queryWithCache(l,n,async()=>await a.query(l,n,u));let d=await this.queryWithCache(l,n,async()=>await a.query(l,n,o));return c?c(d.rows):d.rows.map(e=>i(r,e,s))}async executeRqbV2(e={}){let n=t(this.params,e);this.logger.logQuery(this.queryString,n);let{rawQueryConfig:r,client:i,customResultMapper:a,queryString:o}=this;return a((await i.query(o,n,r)).rows)}all(e={}){let n=t(this.params,e);return this.logger.logQuery(this.queryString,n),this.queryWithCache(this.queryString,n,async()=>await this.client.query(this.queryString,n,this.rawQueryConfig)).then(e=>e.rows)}isResponseInArrayMode(){return this._isResponseInArrayMode}},_=class t extends u{constructor(e,t,n,r,i={}){super(t),this.client=e,this.relations=n,this.schema=r,this.options=i,this.logger=i.logger??new o,this.cache=i.cache??new c}static[e]=`PgliteSession`;logger;cache;prepareQuery(e,t,n,r,i,a,o){return new g(this.client,e.sql,e.params,this.logger,this.cache,a,o,t,n,r,i)}prepareRelationalQuery(e,t,n,r){return new g(this.client,e.sql,e.params,this.logger,this.cache,void 0,void 0,t,n,!1,r,!0)}async transaction(e,n){return this.client.transaction(async r=>{let i=new t(r,this.dialect,this.relations,this.schema,this.options),a=new v(this.dialect,i,this.relations,this.schema);return n&&await a.setTransaction(n),e(a)})}async count(e){let t=await this.execute(e);return Number(t.rows[0].count)}},v=class t extends d{static[e]=`PgliteTransaction`;async transaction(e){let r=`sp${this.nestedIndex+1}`,i=new t(this.dialect,this.session,this.relations,this.schema,this.nestedIndex+1);await i.execute(n.raw(`savepoint ${r}`));try{let t=await e(i);return await i.execute(n.raw(`release savepoint ${r}`)),t}catch(e){throw await i.execute(n.raw(`rollback to savepoint ${r}`)),e}}},y=class{constructor(e,t,n={}){this.client=e,this.dialect=t,this.options=n}static[e]=`PgliteDriver`;createSession(e,t){return new _(this.client,this.dialect,e,t,{logger:this.options.logger,cache:this.options.cache})}},b=class extends p{static[e]=`PgliteDatabase`};function x(e,t={}){let n=new l({casing:t.casing}),i;t.logger===!0?i=new s:t.logger!==!1&&(i=t.logger);let o;if(t.schema){let e=a(t.schema,r);o={fullSchema:t.schema,schema:e.tables,tableNamesMap:e.tableNamesMap}}let c=t.relations??{},u=new b(n,new y(e,n,{logger:i,cache:t.cache}).createSession(c,o),c,o);return u.$client=e,u.$cache=t.cache,u.$cache&&(u.$cache.invalidate=t.cache?.onMutate),u}function S(...e){if(e[0]===void 0||typeof e[0]==`string`)return x(new m(e[0]),e[1]);let{connection:t,client:n,...r}=e[0];if(n)return x(n,r);if(typeof t==`object`){let{dataDir:e,...n}=t;return x(new m(e,n),r)}return x(new m(t),r)}(e=>{function t(e){return x({},e)}e.mock=t})(S||={});export{S as drizzle};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{G as e,K as t,W as n,o as r,u as i}from"./sql-D-eKV1Dn.mjs";import{c as a,dr as o,l as s}from"./query-builder-V8-LDhvA.mjs";import{n as c,t as l}from"./logger-BAGZLUzj.mjs";import{t as u}from"./cache-3oO07miM.mjs";import{a as d,i as f,n as p,r as m,t as h}from"./session-Cl2e-_i8.mjs";import{Client as g}from"@planetscale/database";var _=class extends h{constructor(e,t,n,r,i,a,o,s,c,l,u,d){super(i,a,o),this.client=e,this.queryString=t,this.params=n,this.logger=r,this.fields=s,this.customResultMapper=c,this.generatedIds=l,this.returningIds=u,this.isRqbV2Query=d}static[e]=`PlanetScalePreparedQuery`;rawQuery={as:`object`};query={as:`array`};async execute(e={}){if(this.isRqbV2Query)return this.executeRqbV2(e);let i=r(this.params,e);this.logger.logQuery(this.queryString,i);let{fields:a,client:s,queryString:c,rawQuery:l,query:u,joinsNotNullableMap:d,customResultMapper:f,returningIds:p,generatedIds:m}=this;if(!a&&!f){let e=await this.queryWithCache(c,i,async()=>await s.execute(c,i,l)),r=Number.parseFloat(e.insertId),a=e.rowsAffected;if(p){let e=[],i=0;for(let o=r;o<r+a;o++){for(let r of p){let a=p[0].path[0];t(r.field,n)&&(r.field.primary&&r.field.autoIncrement&&e.push({[a]:o}),r.field.defaultFn&&m&&e.push({[a]:m[i][a]}))}i++}return e}return e}let{rows:h}=await this.queryWithCache(c,i,async()=>await s.execute(c,i,u));return f?f(h):h.map(e=>o(a,e,d))}async executeRqbV2(e={}){let t=r(this.params,e);this.logger.logQuery(this.queryString,t);let{client:n,queryString:i,rawQuery:a,customResultMapper:o}=this;return o((await n.execute(i,t,a)).rows)}iterator(e){throw Error(`Streaming is not supported by the PlanetScale Serverless driver`)}},v=class t extends p{constructor(e,t,n,r,i,a={}){super(t),this.baseClient=e,this.relations=r,this.schema=i,this.options=a,this.client=n??e,this.logger=a.logger??new c,this.cache=a.cache??new u}static[e]=`PlanetscaleSession`;logger;client;cache;prepareQuery(e,t,n,r,i,a,o){return new _(this.client,e.sql,e.params,this.logger,this.cache,a,o,t,n,r,i)}prepareRelationalQuery(e,t,n,r,i){return new _(this.client,e.sql,e.params,this.logger,this.cache,void 0,void 0,t,n,r,i,!0)}async query(e,t){return this.logger.logQuery(e,t),await this.client.execute(e,t,{as:`array`})}async queryObjects(e,t){return this.client.execute(e,t,{as:`object`})}all(e){let t=this.dialect.sqlToQuery(e);return this.logger.logQuery(t.sql,t.params),this.client.execute(t.sql,t.params,{as:`object`}).then(e=>e.rows)}async count(e){let t=await this.execute(e);return Number(t.rows[0].count)}transaction(e){return this.baseClient.transaction(n=>{let r=new t(this.baseClient,this.dialect,n,this.relations,this.schema,this.options);return e(new y(this.dialect,r,this.relations,this.schema))})}},y=class t extends m{static[e]=`PlanetScaleTransaction`;constructor(e,t,n,r,i=0){super(e,t,n,r,i,`planetscale`)}async transaction(e){let n=`sp${this.nestedIndex+1}`,r=new t(this.dialect,this.session,this.relations,this.schema,this.nestedIndex+1);await r.execute(i.raw(`savepoint ${n}`));try{let t=await e(r);return await r.execute(i.raw(`release savepoint ${n}`)),t}catch(e){throw await r.execute(i.raw(`rollback to savepoint ${n}`)),e}}},b=class extends f{static[e]=`PlanetScaleDatabase`};function x(e,t={}){if(!(e instanceof g))throw Error(`Warning: You need to pass an instance of Client:
|
|
3
|
+
|
|
4
|
+
import { Client } from "@planetscale/database";
|
|
5
|
+
|
|
6
|
+
const client = new Client({
|
|
7
|
+
host: process.env["DATABASE_HOST"],
|
|
8
|
+
username: process.env["DATABASE_USERNAME"],
|
|
9
|
+
password: process.env["DATABASE_PASSWORD"],
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const db = drizzle({ client });
|
|
13
|
+
`);let n=new d({casing:t.casing}),r;t.logger===!0?r=new l:t.logger!==!1&&(r=t.logger);let i;if(t.schema){let e=s(t.schema,a);i={fullSchema:t.schema,schema:e.tables,tableNamesMap:e.tableNamesMap}}let o=t.relations??{},c=new b(n,new v(e,n,void 0,o,i,{logger:r,cache:t.cache}),o,i,`planetscale`);return c.$client=e,c.$cache=t.cache,c.$cache&&(c.$cache.invalidate=t.cache?.onMutate),c}function S(...e){if(typeof e[0]==`string`)return x(new g({url:e[0]}),e[1]);let{connection:t,client:n,...r}=e[0];return x(n||(typeof t==`string`?new g({url:t}):new g(t)),r)}(e=>{function t(e){return x({},e)}e.mock=t})(S||={});export{S as drizzle};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{G as e,f as t,o as n}from"./sql-D-eKV1Dn.mjs";import{c as r,dr as i,l as a}from"./query-builder-V8-LDhvA.mjs";import{n as o,t as s}from"./logger-BAGZLUzj.mjs";import{t as c}from"./cache-3oO07miM.mjs";import{L as l,n as u,r as d,t as f,x as p}from"./pg-core-BLTZt9AH.mjs";import m from"postgres";var h=class extends f{constructor(e,t,n,r,i,a,o,s,c,l,u){super({sql:t,params:n},i,a,o),this.client=e,this.queryString=t,this.params=n,this.logger=r,this.fields=s,this._isResponseInArrayMode=c,this.customResultMapper=l,this.isRqbV2Query=u}static[e]=`PostgresJsPreparedQuery`;async execute(e={}){return this.isRqbV2Query?this.executeRqbV2(e):t.startActiveSpan(`drizzle.execute`,async r=>{let a=n(this.params,e);r?.setAttributes({"drizzle.query.text":this.queryString,"drizzle.query.params":JSON.stringify(a)}),this.logger.logQuery(this.queryString,a);let{fields:o,queryString:s,client:c,joinsNotNullableMap:l,customResultMapper:u}=this;if(!o&&!u)return t.startActiveSpan(`drizzle.driver.execute`,()=>this.queryWithCache(s,a,async()=>await c.unsafe(s,a)));let d=await t.startActiveSpan(`drizzle.driver.execute`,()=>(r?.setAttributes({"drizzle.query.text":s,"drizzle.query.params":JSON.stringify(a)}),this.queryWithCache(s,a,async()=>await c.unsafe(s,a).values())));return t.startActiveSpan(`drizzle.mapResponse`,()=>u?u(d):d.map(e=>i(o,e,l)))})}async executeRqbV2(e={}){return t.startActiveSpan(`drizzle.execute`,async r=>{let i=n(this.params,e);r?.setAttributes({"drizzle.query.text":this.queryString,"drizzle.query.params":JSON.stringify(i)}),this.logger.logQuery(this.queryString,i);let{queryString:a,client:o,customResultMapper:s}=this,c=await t.startActiveSpan(`drizzle.driver.execute`,()=>(r?.setAttributes({"drizzle.query.text":a,"drizzle.query.params":JSON.stringify(i)}),o.unsafe(a,i)));return t.startActiveSpan(`drizzle.mapResponse`,()=>s(Object.values(c)))})}all(e={}){return t.startActiveSpan(`drizzle.execute`,async r=>{let i=n(this.params,e);return r?.setAttributes({"drizzle.query.text":this.queryString,"drizzle.query.params":JSON.stringify(i)}),this.logger.logQuery(this.queryString,i),t.startActiveSpan(`drizzle.driver.execute`,()=>(r?.setAttributes({"drizzle.query.text":this.queryString,"drizzle.query.params":JSON.stringify(i)}),this.queryWithCache(this.queryString,i,async()=>this.client.unsafe(this.queryString,i))))})}isResponseInArrayMode(){return this._isResponseInArrayMode}},g=class t extends u{constructor(e,t,n,r,i={}){super(t),this.client=e,this.relations=n,this.schema=r,this.options=i,this.logger=i.logger??new o,this.cache=i.cache??new c}static[e]=`PostgresJsSession`;logger;cache;prepareQuery(e,t,n,r,i,a,o){return new h(this.client,e.sql,e.params,this.logger,this.cache,a,o,t,r,i)}prepareRelationalQuery(e,t,n,r){return new h(this.client,e.sql,e.params,this.logger,this.cache,void 0,void 0,t,!1,r,!0)}query(e,t){return this.logger.logQuery(e,t),this.client.unsafe(e,t).values()}queryObjects(e,t){return this.client.unsafe(e,t)}transaction(e,n){return this.client.begin(async r=>{let i=new t(r,this.dialect,this.relations,this.schema,this.options),a=new _(this.dialect,i,this.schema,this.relations);return n&&await a.setTransaction(n),e(a)})}},_=class t extends d{constructor(e,t,n,r,i=0){super(e,t,r,n,i),this.session=t}static[e]=`PostgresJsTransaction`;transaction(e){return this.session.client.savepoint(n=>{let r=new g(n,this.dialect,this.relations,this.schema,this.session.options);return e(new t(this.dialect,r,this.schema,this.relations))})}},v=class extends p{static[e]=`PostgresJsDatabase`};function y(e,t={}){let n=e=>e;for(let t of[`1184`,`1082`,`1083`,`1114`,`1182`,`1185`,`1115`,`1231`])e.options.parsers[t]=n,e.options.serializers[t]=n;e.options.serializers[114]=n,e.options.serializers[3802]=n;let i=new l({casing:t.casing}),o;t.logger===!0?o=new s:t.logger!==!1&&(o=t.logger);let c;if(t.schema){let e=a(t.schema,r);c={fullSchema:t.schema,schema:e.tables,tableNamesMap:e.tableNamesMap}}let u=t.relations??{},d=new v(i,new g(e,i,u,c,{logger:o,cache:t.cache}),u,c);return d.$client=e,d.$cache=t.cache,d.$cache&&(d.$cache.invalidate=t.cache?.onMutate),d}function b(...e){if(typeof e[0]==`string`)return y(m(e[0]),e[1]);let{connection:t,client:n,...r}=e[0];if(n)return y(n,r);if(typeof t==`object`&&t.url!==void 0){let{url:e,...n}=t;return y(m(e,n),r)}return y(m(t),r)}(e=>{function t(e){return y({options:{parsers:{},serializers:{}}},e)}e.mock=t})(b||={});export{b as drizzle};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{n as e}from"./workflow-zxHDyfLq.mjs";import{t}from"./zod-MJjkEkRY.mjs";const n=e({input:t.object({attachmentIds:t.array(t.string()).min(1)}),async run({container:e,input:{attachmentIds:t},step:n}){let r=await n(`fetch-attachments`,async()=>(await e.storage.primary.getAttachmentsByIds(t)).filter(e=>e.blob!==null).map(e=>({attachmentId:e.id,blobId:e.blob.id})));return await n(`delete-attachments`,async()=>{for(let{attachmentId:t}of r)await e.storage.primary.deleteAttachment(t)}),await n(`delete-blobs`,async()=>{for(let{blobId:t}of r)await e.storage.primary.deleteBlob(t)}),e.logger.info({attachmentIds:t,blobCount:r.length},`Attachments and blobs purged`),{purgedCount:r.length}}});export{n as purgeAttachment};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{t as e}from"./workflow-zxHDyfLq.mjs";import{j as t}from"./query-builder-V8-LDhvA.mjs";import{t as n}from"./auth-schema-CcqAJY9P.mjs";const r=n();function i(n=`0 0 * * *`){return e({crontab:n,async run({container:e,step:n,scheduledTime:i}){let a=e.auth.auditLog?.retentionDays??90,o=new Date(i);o.setDate(o.getDate()-a);let s=o.toISOString(),c=await n(`delete-old-logs`,async()=>{let{auditLogs:n}=r.tables;return(await e.db.primary.delete(n).where(t(n.createdAt,s)).returning({id:n.id})).length});e.logger.info({deletedCount:c,retentionDays:a,cutoffDate:s},`Audit log purge completed`)}})}export{i as definePurgeAuditLogs};
|
package/dist/bin/{purge-unattached-blobs-Duvv8Izd.mjs → purge-unattached-blobs-DOmk4ddJ.mjs}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{t as e}from"./workflow-
|
|
2
|
+
import{t as e}from"./workflow-zxHDyfLq.mjs";function t(t=`0 0 * * *`){return e({crontab:t,async run({container:e,step:t}){let n=new Date(Date.now()-2880*60*1e3).toISOString(),r=await t(`fetch-unattached-blobs`,async()=>e.storage.primary.getUnattachedBlobs({olderThan:n})),i=await t(`fetch-pending-blobs`,async()=>e.storage.primary.getPendingBlobs(n)),a=[...r,...i],o=0;for(let n of a)await t(`delete-blob`,async()=>{await e.storage.primary.deleteBlob(n.id),o++});e.logger.info({purgedCount:o,unattachedCount:r.length,pendingCount:i.length},`Orphaned blobs purged`)}})}export{t as definePurgeUnattachedBlobs};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{F as e,G as t,H as n,K as r,M as i,R as a,V as o,W as s,a as c,d as l,f as u,h as d,m as f,r as p,t as m,u as h}from"./sql-D-eKV1Dn.mjs";import{S as g,_,_r as v,a as y,ar as b,cr as x,d as S,gr as C,hr as w,ir as T,lr as E,m as D,mr as O,n as k,o as ee,or as A,pr as j,rr as M,sr as N,t as te,u as P,vr as F,yr as ne}from"./query-builder-V8-LDhvA.mjs";var re=class{static[t]=`CockroachForeignKeyBuilder`;reference;_onUpdate=`no action`;_onDelete=`no action`;constructor(e,t){this.reference=()=>{let{name:t,columns:n,foreignColumns:r}=e();return{name:t,columns:n,foreignTable:r[0].table,foreignColumns:r}},t&&(this._onUpdate=t.onUpdate,this._onDelete=t.onDelete)}onUpdate(e){return this._onUpdate=e===void 0?`no action`:e,this}onDelete(e){return this._onDelete=e===void 0?`no action`:e,this}build(e){return new ie(e,this)}},ie=class{constructor(e,t){this.table=e,this.reference=t.reference,this.onUpdate=t._onUpdate,this.onDelete=t._onDelete}static[t]=`CockroachForeignKey`;reference;onUpdate;onDelete;name;getName(){let{name:e}=this.reference();return e}isNameExplicit(){return!!this.reference().name}};function ae(e,t,n){for(let r=t;r<e.length;r++){let i=e[r];if(i===`\\`){r++;continue}if(i===`"`)return[e.slice(t,r).replace(/\\/g,``),r+1];if(!n&&(i===`,`||i===`}`))return[e.slice(t,r).replace(/\\/g,``),r]}return[e.slice(t).replace(/\\/g,``),e.length]}function oe(e,t=0){let n=[],r=t,i=!1;for(;r<e.length;){let a=e[r];if(a===`,`){(i||r===t)&&n.push(``),i=!0,r++;continue}if(i=!1,a===`\\`){r+=2;continue}if(a===`"`){let[t,i]=ae(e,r+1,!0);n.push(t),r=i;continue}if(a===`}`)return[n,r+1];if(a===`{`){let[t,i]=oe(e,r+1);n.push(t),r=i;continue}let[o,s]=ae(e,r,!1);n.push(o),r=s}return[n,r]}function se(e){let[t]=oe(e,1);return t}function I(e){return`{${e.map(e=>Array.isArray(e)?I(e):typeof e==`string`?`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`:`${e}`).join(`,`)}}`}var L=class extends e{foreignKeyConfigs=[];static[t]=`CockroachColumnBuilder`;references(e,t={}){return this.foreignKeyConfigs.push({ref:e,config:t}),this}unique(e){return this.config.isUnique=!0,this.config.uniqueName=e,this}generatedAlwaysAs(e){return this.config.generated={as:e,type:`always`,mode:`stored`},this}buildForeignKeys(e,t){return this.foreignKeyConfigs.map(({ref:n,config:r})=>i((n,r)=>{let i=new re(()=>{let t=n();return{name:r.name,columns:[e],foreignColumns:[t]}});return r.onUpdate&&i.onUpdate(r.onUpdate),r.onDelete&&i.onDelete(r.onDelete),i.build(t)},n,r))}buildExtraConfigColumn(e){return new ce(e,this.config)}},R=class extends L{static[t]=`CockroachColumnWithArrayBuilder`;array(e){return new le(this.config.name,this,e)}},z=class extends s{static[t]=`CockroachColumn`;table;constructor(e,t){super(e,t),this.table=e}shouldDisableInsert(){return this.config.generatedIdentity!==void 0&&this.config.generatedIdentity.type===`always`||this.config.generated!==void 0&&this.config.generated.type!==`byDefault`}},ce=class extends z{static[t]=`ExtraConfigColumn`;getSQLType(){return this.getSQLType()}indexConfig={order:this.config.order??`asc`};defaultConfig={order:`asc`};asc(){return this.indexConfig.order=`asc`,this}desc(){return this.indexConfig.order=`desc`,this}},le=class extends R{static[t]=`CockroachArrayBuilder`;constructor(e,t,n){super(e,`array basecolumn`,`CockroachArray`),this.config.baseBuilder=t,this.config.length=n}build(e){let t=this.config.baseBuilder.build(e);return new ue(e,this.config,t)}},ue=class e extends z{constructor(e,t,n,r){super(e,t),this.baseColumn=n,this.range=r}static[t]=`CockroachArray`;getSQLType(){return`${this.baseColumn.getSQLType()}[${typeof this.length==`number`?this.length:``}]`}mapFromDriverValue(e){return typeof e==`string`&&(e=se(e)),e.map(e=>this.baseColumn.mapFromDriverValue(e))}mapFromJsonValue(e){typeof e==`string`&&(e=se(e));let t=this.baseColumn;return`mapFromJsonValue`in t?e.map(e=>t.mapFromJsonValue(e)):e.map(e=>t.mapFromDriverValue(e))}mapToDriverValue(t,n=!1){let i=t.map(t=>t===null?null:r(this.baseColumn,e)?this.baseColumn.mapToDriverValue(t,!0):this.baseColumn.mapToDriverValue(t));return n?i:I(i)}},B=class extends R{static[t]=`CockroachIntColumnBaseBuilder`;generatedAlwaysAsIdentity(e){return this.config.generatedIdentity=e?{type:`always`,sequenceOptions:e}:{type:`always`},this.config.hasDefault=!0,this.config.notNull=!0,this}generatedByDefaultAsIdentity(e){return this.config.generatedIdentity=e?{type:`byDefault`,sequenceOptions:e}:{type:`byDefault`},this.config.hasDefault=!0,this.config.notNull=!0,this}},V=class extends B{static[t]=`CockroachBigInt53Builder`;constructor(e){super(e,`number int53`,`CockroachBigInt53`)}build(e){return new de(e,this.config)}},de=class extends z{static[t]=`CockroachBigInt53`;getSQLType(){return`int8`}mapFromDriverValue(e){return typeof e==`number`?e:Number(e)}},H=class extends B{static[t]=`CockroachBigInt64Builder`;constructor(e){super(e,`bigint int64`,`CockroachBigInt64`)}build(e){return new fe(e,this.config)}},fe=class extends z{static[t]=`CockroachBigInt64`;getSQLType(){return`int8`}mapFromDriverValue(e){return BigInt(e)}};function pe(e,t){let{name:n,config:r}=A(e,t);return r.mode===`number`?new V(n):new H(n)}function me(e,t){let{name:n,config:r}=A(e,t);return r.mode===`number`?new V(n):new H(n)}var he=class extends R{static[t]=`CockroachBitBuilder`;constructor(e,t){super(e,`string binary`,`CockroachBit`),this.config.length=t.length??1,this.config.setLength=t.length!==void 0,this.config.isLengthExact=!0}build(e){return new ge(e,this.config)}},ge=class extends z{static[t]=`CockroachBit`;getSQLType(){return this.config.setLength?`bit(${this.length})`:`bit`}};function _e(e,t={}){let{name:n,config:r}=A(e,t);return new he(n,r)}var ve=class extends R{static[t]=`CockroachBooleanBuilder`;constructor(e){super(e,`boolean`,`CockroachBoolean`)}build(e){return new ye(e,this.config)}},ye=class extends z{static[t]=`CockroachBoolean`;getSQLType(){return`bool`}};function be(e){return new ve(e??``)}var xe=class extends R{static[t]=`CockroachCharBuilder`;constructor(e,t){super(e,t.enum?.length?`string enum`:`string`,`CockroachChar`),this.config.enumValues=t.enum,this.config.length=t.length??1,this.config.setLength=t.length!==void 0}build(e){return new Se(e,this.config)}},Se=class extends z{static[t]=`CockroachChar`;enumValues=this.config.enumValues;getSQLType(){return this.config.setLength?`char(${this.length})`:`char`}};function Ce(e,t={}){let{name:n,config:r}=A(e,t);return new xe(n,r)}var we=class extends R{static[t]=`CockroachCustomColumnBuilder`;constructor(e,t,n){super(e,`custom`,`CockroachCustomColumn`),this.config.fieldConfig=t,this.config.customTypeParams=n}build(e){return new Te(e,this.config)}},Te=class extends z{static[t]=`CockroachCustomColumn`;sqlName;mapTo;mapFrom;mapJson;forJsonSelect;constructor(e,t){super(e,t),this.sqlName=t.customTypeParams.dataType(t.fieldConfig),this.mapTo=t.customTypeParams.toDriver,this.mapFrom=t.customTypeParams.fromDriver,this.mapJson=t.customTypeParams.fromJson,this.forJsonSelect=t.customTypeParams.forJsonSelect}getSQLType(){return this.sqlName}mapFromDriverValue(e){return typeof this.mapFrom==`function`?this.mapFrom(e):e}mapFromJsonValue(e){return typeof this.mapJson==`function`?this.mapJson(e):this.mapFromDriverValue(e)}jsonSelectIdentifier(e,t,n){if(typeof this.forJsonSelect==`function`)return this.forJsonSelect(e,t,n);let r=this.getSQLType().toLowerCase(),i=r.indexOf(`(`);switch(i+1?r.slice(0,i):r){case`geometry`:case`timestamp`:case`decimal`:case`int8`:{let r=`[]`.repeat(n??0);return t`${e}::text${t.raw(r).if(n)}`}default:return e}}mapToDriverValue(e){return typeof this.mapTo==`function`?this.mapTo(e):e}};function Ee(e){return(t,n)=>{let{name:r,config:i}=A(t,n);return new we(r,i,e)}}var U=class extends R{static[t]=`CockroachDateColumnBaseBuilder`;defaultNow(){return this.default(h`now()`)}},De=class extends U{static[t]=`CockroachDateBuilder`;constructor(e){super(e,`object date`,`CockroachDate`)}build(e){return new Oe(e,this.config)}},Oe=class extends z{static[t]=`CockroachDate`;getSQLType(){return`date`}mapFromDriverValue(e){return new Date(e)}mapToDriverValue(e){return typeof e==`string`?e:e.toISOString()}},ke=class extends U{static[t]=`CockroachDateStringBuilder`;constructor(e){super(e,`string date`,`CockroachDateString`)}build(e){return new Ae(e,this.config)}},Ae=class extends z{static[t]=`CockroachDateString`;getSQLType(){return`date`}mapToDriverValue(e){return typeof e==`string`?e:e.toISOString()}};function je(e,t){let{name:n,config:r}=A(e,t);return r?.mode===`date`?new De(n):new ke(n)}var Me=class extends R{static[t]=`CockroachDecimalBuilder`;constructor(e,t,n){super(e,`string numeric`,`CockroachDecimal`),this.config.precision=t,this.config.scale=n}build(e){return new Ne(e,this.config)}},Ne=class extends z{static[t]=`CockroachDecimal`;precision;scale;constructor(e,t){super(e,t),this.precision=t.precision,this.scale=t.scale}mapFromDriverValue(e){return typeof e==`string`?e:String(e)}getSQLType(){return this.precision!==void 0&&this.scale!==void 0?`decimal(${this.precision},${this.scale})`:this.precision===void 0?`decimal`:`decimal(${this.precision})`}},Pe=class extends R{static[t]=`CockroachDecimalNumberBuilder`;constructor(e,t,n){super(e,`number`,`CockroachDecimalNumber`),this.config.precision=t,this.config.scale=n}build(e){return new Fe(e,this.config)}},Fe=class extends z{static[t]=`CockroachDecimalNumber`;precision;scale;constructor(e,t){super(e,t),this.precision=t.precision,this.scale=t.scale}mapFromDriverValue(e){return typeof e==`number`?e:Number(e)}mapToDriverValue=String;getSQLType(){return this.precision!==void 0&&this.scale!==void 0?`decimal(${this.precision},${this.scale})`:this.precision===void 0?`decimal`:`decimal(${this.precision})`}},Ie=class extends R{static[t]=`CockroachDecimalBigIntBuilder`;constructor(e,t,n){super(e,`bigint int64`,`CockroachDecimalBigInt`),this.config.precision=t,this.config.scale=n}build(e){return new Le(e,this.config)}},Le=class extends z{static[t]=`CockroachDecimalBigInt`;precision;scale;constructor(e,t){super(e,t),this.precision=t.precision,this.scale=t.scale}mapFromDriverValue=BigInt;mapToDriverValue=String;getSQLType(){return this.precision!==void 0&&this.scale!==void 0?`decimal(${this.precision},${this.scale})`:this.precision===void 0?`decimal`:`decimal(${this.precision})`}};function W(e,t){let{name:n,config:r}=A(e,t),i=r?.mode;return i===`number`?new Pe(n,r?.precision,r?.scale):i===`bigint`?new Ie(n,r?.precision,r?.scale):new Me(n,r?.precision,r?.scale)}const Re=W;var ze=class extends R{static[t]=`CockroachFloatBuilder`;constructor(e){super(e,`number double`,`CockroachFloat`)}build(e){return new Be(e,this.config)}},Be=class extends z{static[t]=`CockroachFloat`;getSQLType(){return`float`}mapFromDriverValue(e){return typeof e==`string`?Number.parseFloat(e):e}};function G(e){return new ze(e??``)}const Ve=G;function He(e){let t=[];for(let n=0;n<e.length;n+=2)t.push(Number.parseInt(e.slice(n,n+2),16));return new Uint8Array(t)}function K(e,t){let n=new ArrayBuffer(8),r=new DataView(n);for(let n=0;n<8;n++)r.setUint8(n,e[t+n]);return r.getFloat64(0,!0)}function Ue(e){let t=He(e),n=0,r=t[n];n+=1;let i=new DataView(t.buffer),a=i.getUint32(n,r===1);n+=4;let o;if(a&536870912&&(o=i.getUint32(n,r===1),n+=4),(a&65535)==1){let e=K(t,n);n+=8;let r=K(t,n);return n+=8,{srid:o,point:[e,r]}}throw Error(`Unsupported geometry type`)}var We=class extends R{static[t]=`CockroachGeometryBuilder`;constructor(e,t){super(e,`array geometry`,`CockroachGeometry`),this.config.srid=t}build(e){return new Ge(e,this.config)}},Ge=class extends z{static[t]=`CockroachGeometry`;srid=this.config.srid;mode=`tuple`;getSQLType(){return`geometry(point${this.srid===void 0?``:`,${this.srid}`})`}mapFromDriverValue(e){return typeof e==`string`?Ue(e).point:e}mapToDriverValue(e){return`point(${e[0]} ${e[1]})`}},Ke=class extends R{static[t]=`CockroachGeometryObjectBuilder`;constructor(e,t){super(e,`object geometry`,`CockroachGeometryObject`),this.config.srid=t}build(e){return new qe(e,this.config)}},qe=class extends z{static[t]=`CockroachGeometryObject`;srid=this.config.srid;mode=`object`;getSQLType(){return`geometry(point${this.srid===void 0?``:`,${this.srid}`})`}mapFromDriverValue(e){let t=Ue(e);return{x:t.point[0],y:t.point[1]}}mapToDriverValue(e){return`point(${e.x} ${e.y})`}};function Je(e,t){let{name:n,config:r}=A(e,t);return!r?.mode||r.mode===`tuple`?new We(n,r?.srid):new Ke(n,r?.srid)}var Ye=class extends R{static[t]=`CockroachInetBuilder`;constructor(e){super(e,`string inet`,`CockroachInet`)}build(e){return new Xe(e,this.config)}},Xe=class extends z{static[t]=`CockroachInet`;getSQLType(){return`inet`}};function Ze(e){return new Ye(e??``)}var Qe=class extends B{static[t]=`CockroachIntegerBuilder`;constructor(e){super(e,`number int32`,`CockroachInteger`)}build(e){return new $e(e,this.config)}},$e=class extends z{static[t]=`CockroachInteger`;getSQLType(){return`int4`}mapFromDriverValue(e){return typeof e==`string`?Number.parseInt(e):e}};function et(e){return new Qe(e??``)}var tt=class extends R{static[t]=`CockroachIntervalBuilder`;constructor(e,t){super(e,`string interval`,`CockroachInterval`),this.config.intervalConfig=t}build(e){return new nt(e,this.config)}},nt=class extends z{static[t]=`CockroachInterval`;fields=this.config.intervalConfig.fields;precision=this.config.intervalConfig.precision;getSQLType(){return`interval${this.fields?` ${this.fields}`:``}${this.precision?`(${this.precision})`:``}`}};function rt(e,t={}){let{name:n,config:r}=A(e,t);return new tt(n,r)}var it=class extends L{static[t]=`CockroachJsonbBuilder`;constructor(e){super(e,`object json`,`CockroachJsonb`)}build(e){return new at(e,this.config)}},at=class extends z{static[t]=`CockroachJsonb`;constructor(e,t){super(e,t)}getSQLType(){return`jsonb`}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){if(typeof e==`string`)try{return JSON.parse(e)}catch{return e}return e}};function ot(e){return new it(e??``)}var st=class extends R{static[t]=`CockroachRealBuilder`;constructor(e,t){super(e,`number float`,`CockroachReal`),this.config.length=t}build(e){return new ct(e,this.config)}},ct=class extends z{static[t]=`CockroachReal`;constructor(e,t){super(e,t)}getSQLType(){return`real`}mapFromDriverValue=e=>typeof e==`string`?Number.parseFloat(e):e};function lt(e){return new st(e??``)}var ut=class extends B{static[t]=`CockroachSmallIntBuilder`;constructor(e){super(e,`number int16`,`CockroachSmallInt`)}build(e){return new dt(e,this.config)}},dt=class extends z{static[t]=`CockroachSmallInt`;getSQLType(){return`int2`}mapFromDriverValue=e=>typeof e==`string`?Number(e):e};function ft(e){return new ut(e??``)}function pt(e){return new ut(e??``)}var mt=class extends R{static[t]=`CockroachStringBuilder`;constructor(e,t){super(e,t.enum?.length?`string enum`:`string`,`CockroachString`),this.config.enumValues=t.enum,this.config.length=t.length}build(e){return new ht(e,this.config)}},ht=class extends z{static[t]=`CockroachString`;enumValues=this.config.enumValues;getSQLType(){return this.length===void 0?`string`:`string(${this.length})`}};function gt(e,t={}){let{name:n,config:r}=A(e,t);return new mt(n,r)}function _t(e,t={}){let{name:n,config:r}=A(e,t);return new mt(n,r)}var vt=class extends R{constructor(e,t,n){super(e,`string time`,`CockroachTime`),this.withTimezone=t,this.precision=n,this.config.withTimezone=t,this.config.precision=n}static[t]=`CockroachTimeBuilder`;build(e){return new yt(e,this.config)}},yt=class extends z{static[t]=`CockroachTime`;withTimezone;precision;constructor(e,t){super(e,t),this.withTimezone=t.withTimezone,this.precision=t.precision}getSQLType(){let e=this.precision===void 0?``:`(${this.precision})`;return`time${this.withTimezone?`tz`:``}${e}`}};function bt(e,t={}){let{name:n,config:r}=A(e,t);return new vt(n,r.withTimezone??!1,r.precision)}var xt=class extends U{static[t]=`CockroachTimestampBuilder`;constructor(e,t,n){super(e,`object date`,`CockroachTimestamp`),this.config.withTimezone=t,this.config.precision=n}build(e){return new St(e,this.config)}},St=class extends z{static[t]=`CockroachTimestamp`;withTimezone;precision;constructor(e,t){super(e,t),this.withTimezone=t.withTimezone,this.precision=t.precision}getSQLType(){let e=this.precision===void 0?``:`(${this.precision})`;return`timestamp${this.withTimezone?`tz`:``}${e}`}mapFromDriverValue=e=>new Date(this.withTimezone?e:e+`+0000`);mapToDriverValue=e=>typeof e==`string`?e:e.toISOString()},Ct=class extends U{static[t]=`CockroachTimestampStringBuilder`;constructor(e,t,n){super(e,`string timestamp`,`CockroachTimestampString`),this.config.withTimezone=t,this.config.precision=n}build(e){return new wt(e,this.config)}},wt=class extends z{static[t]=`CockroachTimestampString`;withTimezone;precision;constructor(e,t){super(e,t),this.withTimezone=t.withTimezone,this.precision=t.precision}getSQLType(){let e=this.precision===void 0?``:`(${this.precision})`;return`timestamp${this.withTimezone?`tz`:``}${e}`}mapToDriverValue=e=>typeof e==`string`?e:e.toISOString()};function Tt(e,t={}){let{name:n,config:r}=A(e,t);return r?.mode===`string`?new Ct(n,r.withTimezone??!1,r.precision):new xt(n,r?.withTimezone??!1,r?.precision)}var Et=class extends R{static[t]=`CockroachUUIDBuilder`;constructor(e){super(e,`string uuid`,`CockroachUUID`)}defaultRandom(){return this.default(h`gen_random_uuid()`)}build(e){return new Dt(e,this.config)}},Dt=class extends z{static[t]=`CockroachUUID`;getSQLType(){return`uuid`}};function Ot(e){return new Et(e??``)}var kt=class extends R{static[t]=`CockroachVarbitBuilder`;constructor(e,t){super(e,`string binary`,`CockroachVarbit`),this.config.length=t.length}build(e){return new At(e,this.config)}},At=class extends z{static[t]=`CockroachVarbit`;getSQLType(){return this.length?`varbit(${this.length})`:`varbit`}};function jt(e,t={}){let{name:n,config:r}=A(e,t);return new kt(n,r)}var Mt=class extends R{static[t]=`CockroachVarcharBuilder`;constructor(e,t){super(e,t.enum?.length?`string enum`:`string`,`CockroachVarchar`),this.config.length=t.length,this.config.enumValues=t.enum}build(e){return new Nt(e,this.config)}},Nt=class extends z{static[t]=`CockroachVarchar`;enumValues=this.config.enumValues;getSQLType(){return this.length===void 0?`varchar`:`varchar(${this.length})`}};function Pt(e,t={}){let{name:n,config:r}=A(e,t);return new Mt(n,r)}var Ft=class extends L{static[t]=`CockroachVectorBuilder`;constructor(e,t){super(e,`array vector`,`CockroachVector`),this.config.length=t.dimensions}build(e){return new It(e,this.config)}},It=class extends z{static[t]=`CockroachVector`;getSQLType(){return`vector(${this.config.length})`}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){return e.slice(1,-1).split(`,`).map(e=>Number.parseFloat(e))}};function Lt(e,t){let{name:n,config:r}=A(e,t);return new Ft(n,r)}function Rt(){return{bigint:pe,bool:be,char:Ce,customType:Ee,date:je,doublePrecision:Ve,inet:Ze,int4:et,int2:pt,int8:me,interval:rt,jsonb:ot,numeric:Re,decimal:W,geometry:Je,real:lt,smallint:ft,text:_t,time:bt,timestamp:Tt,uuid:Ot,varchar:Pt,bit:_e,vector:Lt,float:G,string:gt,varbit:jt}}const q=Symbol.for(`drizzle:CockroachInlineForeignKeys`),J=Symbol.for(`drizzle:EnableRLS`);var Y=class extends a{static[t]=`CockroachTable`;static Symbol=Object.assign({},a.Symbol,{InlineForeignKeys:q,EnableRLS:J});[q]=[];[J]=!1;[a.Symbol.ExtraConfigBuilder]=void 0;[a.Symbol.ExtraConfigColumns]={}};function zt(e,t,n,r,i=e){let o=new Y(e,r,i),s=typeof t==`function`?t(Rt()):t,c=Object.fromEntries(Object.entries(s).map(([e,t])=>{let n=t;n.setName(e);let r=n.build(o);return o[q].push(...n.buildForeignKeys(r,o)),[e,r]})),l=Object.fromEntries(Object.entries(s).map(([e,t])=>{let n=t;return n.setName(e),[e,n.buildExtraConfigColumn(o)]})),u=Object.assign(o,c);return u[a.Symbol.Columns]=c,u[a.Symbol.ExtraConfigColumns]=l,n&&(u[Y.Symbol.ExtraConfigBuilder]=n),Object.assign(u,{enableRLS:()=>(u[Y.Symbol.EnableRLS]=!0,u)})}const Bt=Object.assign((e,t,n)=>zt(e,t,n,void 0),{withRLS:(e,t,n)=>{let r=zt(e,t,n,void 0);return r[J]=!0,r}});var X=class extends c{static[t]=`CockroachViewBase`},Z=class{static[t]=`CockroachDialect`;casing;constructor(e){this.casing=new ne(e?.casing)}async migrate(e,t,n){let r=typeof n==`string`?`__drizzle_migrations`:n.migrationsTable??`__drizzle_migrations`,i=typeof n==`string`?`drizzle`:n.migrationsSchema??`drizzle`,a=h`
|
|
3
|
+
CREATE TABLE IF NOT EXISTS ${h.identifier(i)}.${h.identifier(r)} (
|
|
4
|
+
id INT GENERATED ALWAYS AS IDENTITY,
|
|
5
|
+
hash text NOT NULL,
|
|
6
|
+
created_at bigint
|
|
7
|
+
)
|
|
8
|
+
`;await t.execute(h`CREATE SCHEMA IF NOT EXISTS ${h.identifier(i)}`),await t.execute(a);let o=await t.all(h`select id, hash, created_at from ${h.identifier(i)}.${h.identifier(r)} order by created_at desc limit 1`);if(typeof n==`object`&&n.init){if(o.length)return{exitCode:`databaseMigrations`};if(e.length>1)return{exitCode:`localMigrations`};let[n]=e;if(!n)return;await t.execute(h`insert into ${h.identifier(i)}.${h.identifier(r)} ("hash", "created_at") values(${n.hash}, ${n.folderMillis})`);return}let s=o[0];await t.transaction(async t=>{for await(let n of e)if(!s||Number(s.created_at)<n.folderMillis){for(let e of n.sql)await t.execute(h.raw(e));await t.execute(h`insert into ${h.identifier(i)}.${h.identifier(r)} ("hash", "created_at") values(${n.hash}, ${n.folderMillis})`)}})}escapeName(e){return`"${e}"`}escapeParam(e){return`$${e+1}`}escapeString(e){return`'${e.replace(/'/g,`''`)}'`}buildWithCTE(e){if(!e?.length)return;let t=[h`with `];for(let[n,r]of e.entries())t.push(h`${h.identifier(r._.alias)} as (${r._.sql})`),n<e.length-1&&t.push(h`, `);return t.push(h` `),h.join(t)}buildDeleteQuery({table:e,where:t,returning:n,withList:r}){let i=this.buildWithCTE(r),a=n?h` returning ${this.buildSelection(n,{isSingleTable:!0})}`:void 0;return h`${i}delete from ${e}${t?h` where ${t}`:void 0}${a}`}buildUpdateSet(e,t){let n=e[a.Symbol.Columns],i=Object.keys(n).filter(e=>t[e]!==void 0||n[e]?.onUpdateFn!==void 0),o=i.length;return h.join(i.flatMap((e,i)=>{let a=n[e],s=a.onUpdateFn?.(),c=t[e]??(r(s,p)?s:h.param(s,a)),l=h`${h.identifier(this.casing.getColumnCasing(a))} = ${c}`;return i<o-1?[l,h.raw(`, `)]:[l]}))}buildUpdateQuery({table:e,set:t,where:n,returning:r,withList:i,from:a,joins:o}){let s=this.buildWithCTE(i),c=e[Y.Symbol.Name],l=e[Y.Symbol.Schema],u=e[Y.Symbol.OriginalName],d=c===u?void 0:c,f=h`${l?h`${h.identifier(l)}.`:void 0}${h.identifier(u)}${d&&h` ${h.identifier(d)}`}`,p=this.buildUpdateSet(e,t),m=a&&h.join([h.raw(` from `),this.buildFromTable(a)]),g=this.buildJoins(o),_=r?h` returning ${this.buildSelection(r,{isSingleTable:!a})}`:void 0;return h`${s}update ${f} set ${p}${m}${g}${n?h` where ${n}`:void 0}${_}`}buildSelection(e,{isSingleTable:t=!1}={}){let n=e.length,i=e.flatMap(({field:e},i)=>{let a=[];if(r(e,p.Aliased)&&e.isSelectionField)a.push(h.identifier(e.fieldAlias));else if(r(e,p.Aliased)||r(e,p)){let n=r(e,p.Aliased)?e.sql:e;t?a.push(new p(n.queryChunks.map(e=>r(e,z)?h.identifier(this.casing.getColumnCasing(e)):e))):a.push(n),r(e,p.Aliased)&&a.push(h` as ${h.identifier(e.fieldAlias)}`)}else if(r(e,s))t?a.push(e.isAlias?h`${h.identifier(this.casing.getColumnCasing(C(e)))} as ${e}`:h.identifier(this.casing.getColumnCasing(e))):a.push(e.isAlias?h`${C(e)} as ${e}`:e);else if(r(e,f)){let t=Object.entries(e._.selectedFields);if(t.length===1){let n=t[0][1],i=r(n,p)?n.decoder:r(n,s)?{mapFromDriverValue:e=>n.mapFromDriverValue(e)}:n.sql.decoder;i&&(e._.sql.decoder=i)}a.push(e)}return i<n-1&&a.push(h`, `),a});return h.join(i)}buildJoins(e){if(!e||e.length===0)return;let t=[];for(let[n,i]of e.entries()){n===0&&t.push(h` `);let a=i.table,o=i.lateral?h` lateral`:void 0,s=i.on?h` on ${i.on}`:void 0;if(r(a,Y)){let e=a[Y.Symbol.Name],n=a[Y.Symbol.Schema],r=a[Y.Symbol.OriginalName],c=e===r?void 0:i.alias;t.push(h`${h.raw(i.joinType)} join${o} ${n?h`${h.identifier(n)}.`:void 0}${h.identifier(r)}${c&&h` ${h.identifier(c)}`}${s}`)}else if(r(a,c)){let e=a[l].name,n=a[l].schema,r=a[l].originalName,c=e===r?void 0:i.alias;t.push(h`${h.raw(i.joinType)} join${o} ${n?h`${h.identifier(n)}.`:void 0}${h.identifier(r)}${c&&h` ${h.identifier(c)}`}${s}`)}else t.push(h`${h.raw(i.joinType)} join${o} ${a}${s}`);n<e.length-1&&t.push(h` `)}return h.join(t)}buildFromTable(e){if(r(e,a)&&e[a.Symbol.IsAlias]){let t=h`${h.identifier(e[a.Symbol.OriginalName])}`;return e[a.Symbol.Schema]&&(t=h`${h.identifier(e[a.Symbol.Schema])}.${t}`),h`${t} ${h.identifier(e[a.Symbol.Name])}`}return e}buildSelectQuery({withList:e,fields:t,fieldsFlat:n,where:i,having:c,table:u,joins:d,orderBy:m,groupBy:g,limit:_,offset:v,lockingClause:y,distinct:b,setOperators:x}){let S=n??j(t);for(let e of S)if(r(e.field,s)&&o(e.field.table)!==(r(u,f)?u._.alias:r(u,X)?u[l].name:r(u,p)?void 0:o(u))&&!(e=>d?.some(({alias:t})=>t===(e[a.Symbol.IsAlias]?o(e):e[a.Symbol.BaseName])))(e.field.table)){let t=o(e.field.table);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 C=!d||d.length===0,w=this.buildWithCTE(e),T;b&&(T=b===!0?h` distinct`:h` distinct on (${h.join(b.on,h`, `)})`);let E=this.buildSelection(S,{isSingleTable:C}),D=this.buildFromTable(u),O=this.buildJoins(d),k=i?h` where ${i}`:void 0,ee=c?h` having ${c}`:void 0,A;m&&m.length>0&&(A=h` order by ${h.join(m,h`, `)}`);let M;g&&g.length>0&&(M=h` group by ${h.join(g,h`, `)}`);let N=typeof _==`object`||typeof _==`number`&&_>=0?h` limit ${_}`:void 0,te=v?h` offset ${v}`:void 0,P=h.empty();if(y){let e=h` for ${h.raw(y.strength)}`;y.config.of&&e.append(h` of ${h.join(Array.isArray(y.config.of)?y.config.of:[y.config.of],h`, `)}`),y.config.noWait?e.append(h` nowait`):y.config.skipLocked&&e.append(h` skip locked`),P.append(e)}let F=h`${w}select${T} ${E} from ${D}${O}${k}${M}${ee}${A}${N}${te}${P}`;return x.length>0?this.buildSetOperations(F,x):F}buildSetOperations(e,t){let[n,...r]=t;if(!n)throw Error(`Cannot pass undefined values to any set operator`);return r.length===0?this.buildSetOperationQuery({leftSelect:e,setOperator:n}):this.buildSetOperations(this.buildSetOperationQuery({leftSelect:e,setOperator:n}),r)}buildSetOperationQuery({leftSelect:e,setOperator:{type:t,isAll:n,rightSelect:i,limit:a,orderBy:o,offset:s}}){let c=h`(${e.getSQL()}) `,l=h`(${i.getSQL()})`,u;if(o&&o.length>0){let e=[];for(let t of o)if(r(t,z))e.push(h.identifier(t.name));else if(r(t,p)){for(let e=0;e<t.queryChunks.length;e++){let n=t.queryChunks[e];r(n,z)&&(t.queryChunks[e]=h.identifier(n.name))}e.push(h`${t}`)}else e.push(h`${t}`);u=h` order by ${h.join(e,h`, `)} `}let d=typeof a==`object`||typeof a==`number`&&a>=0?h` limit ${a}`:void 0,f=h.raw(`${t} ${n?`all `:``}`),m=s?h` offset ${s}`:void 0;return h`${c}${f}${l}${u}${d}${m}`}buildInsertQuery({table:e,values:t,onConflict:n,returning:i,withList:o,select:s}){let c=[],l=e[a.Symbol.Columns],u=Object.entries(l).filter(([e,t])=>!t.shouldDisableInsert()),d=u.map(([,e])=>h.identifier(this.casing.getColumnCasing(e)));if(s){let e=t;r(e,p)?c.push(e):c.push(e.getSQL())}else{let e=t;c.push(h.raw(`values `));for(let[t,n]of e.entries()){let i=[];for(let[e,t]of u){let a=n[e];if(a===void 0||r(a,m)&&a.value===void 0)if(t.defaultFn!==void 0){let e=t.defaultFn(),n=r(e,p)?e:h.param(e,t);i.push(n)}else if(!t.default&&t.onUpdateFn!==void 0){let e=t.onUpdateFn(),n=r(e,p)?e:h.param(e,t);i.push(n)}else i.push(h`default`);else i.push(a)}c.push(i),t<e.length-1&&c.push(h`, `)}}let f=this.buildWithCTE(o),g=h.join(c),_=i?h` returning ${this.buildSelection(i,{isSingleTable:!0})}`:void 0;return h`${f}insert into ${e} ${d} ${g}${n?h` on conflict ${n}`:void 0}${_}`}buildRefreshMaterializedViewQuery({view:e,concurrently:t,withNoData:n}){return h`refresh materialized view${t?h` concurrently`:void 0} ${e}${n?h` with no data`:void 0}`}sqlToQuery(e,t){return e.toQuery({casing:this.casing,escapeName:this.escapeName,escapeParam:this.escapeParam,escapeString:this.escapeString,invokeSource:t})}buildRelationalQueryWithoutPK({fullSchema:e,schema:t,tableNamesMap:i,table:a,tableConfig:o,queryConfig:c,tableAlias:l,nestedQueryRelation:u,joinOn:d}){let m=[],b,x,C=[],T,E=[];if(c===!0)m=Object.entries(o.columns).map(([e,t])=>({dbKey:t.name,tsKey:e,field:w(t,l),relationTableTsKey:void 0,isJson:!1,selection:[]}));else{let a=Object.fromEntries(Object.entries(o.columns).map(([e,t])=>[e,w(t,l)]));if(c.where){let e=typeof c.where==`function`?c.where(a,P()):c.where;T=e&&F(e,l)}let u=[],d=[];if(c.columns){let e=!1;for(let[t,n]of Object.entries(c.columns))n!==void 0&&t in o.columns&&(!e&&n===!0&&(e=!0),d.push(t));d.length>0&&(d=e?d.filter(e=>c.columns?.[e]===!0):Object.keys(o.columns).filter(e=>!d.includes(e)))}else d=Object.keys(o.columns);for(let e of d){let t=o.columns[e];u.push({tsKey:e,value:t})}let y=[];c.with&&(y=Object.entries(c.with).filter(e=>!!e[1]).map(([e,t])=>({tsKey:e,queryConfig:t,relation:o.relations[e]})));let O;if(c.extras){O=typeof c.extras==`function`?c.extras(a,{sql:h}):c.extras;for(let[e,t]of Object.entries(O))u.push({tsKey:e,value:v(t,l)})}for(let{tsKey:e,value:t}of u)m.push({dbKey:r(t,p.Aliased)?t.fieldAlias:o.columns[e].name,tsKey:e,field:r(t,s)?w(t,l):t,relationTableTsKey:void 0,isJson:!1,selection:[]});let k=typeof c.orderBy==`function`?c.orderBy(a,S()):c.orderBy??[];Array.isArray(k)||(k=[k]),C=k.map(e=>r(e,s)?w(e,l):F(e,l)),b=c.limit,x=c.offset;for(let{tsKey:a,queryConfig:o,relation:s}of y){let c=D(t,i,s),u=i[n(s.referencedTable)],d=`${l}_${a}`,p=_(...c.fields.map((e,t)=>g(w(c.references[t],d),w(e,l)))),v=this.buildRelationalQueryWithoutPK({fullSchema:e,schema:t,tableNamesMap:i,table:e[u],tableConfig:t[u],queryConfig:r(s,ee)?o===!0?{limit:1}:{...o,limit:1}:o,tableAlias:d,joinOn:p,nestedQueryRelation:s}),y=h`${h.identifier(d)}.${h.identifier(`data`)}`.as(a);E.push({on:h`true`,table:new f(v.sql,{},d),alias:d,joinType:`left`,lateral:!0}),m.push({dbKey:a,tsKey:a,field:y,relationTableTsKey:u,isJson:!0,selection:v.selection})}}if(m.length===0)throw new k({message:`No fields selected for table "${o.tsName}" ("${l}")`});let A;if(T=_(d,T),u){let e=h`json_build_array(${h.join(m.map(({field:e,tsKey:t,isJson:n})=>n?h`${h.identifier(`${l}_${t}`)}.${h.identifier(`data`)}`:r(e,p.Aliased)?e.sql:e),h`, `)})`;r(u,y)&&(e=h`coalesce(json_agg(${e}${C.length>0?h` order by ${h.join(C,h`, `)}`:void 0}), '[]'::json)`);let t=[{dbKey:`data`,tsKey:`data`,field:e.as(`data`),isJson:!0,relationTableTsKey:o.tsName,selection:m}];b!==void 0||x!==void 0||C.length>0?(A=this.buildSelectQuery({table:O(a,l),fields:{},fieldsFlat:[{path:[],field:h.raw(`*`)}],where:T,limit:b,offset:x,orderBy:C,setOperators:[]}),T=void 0,b=void 0,x=void 0,C=[]):A=O(a,l),A=this.buildSelectQuery({table:r(A,Y)?A:new f(A,{},l),fields:{},fieldsFlat:t.map(({field:e})=>({path:[],field:r(e,s)?w(e,l):e})),joins:E,where:T,limit:b,offset:x,orderBy:C,setOperators:[]})}else A=this.buildSelectQuery({table:O(a,l),fields:{},fieldsFlat:m.map(({field:e})=>({path:[],field:r(e,s)?w(e,l):e})),joins:E,where:T,limit:b,offset:x,orderBy:C,setOperators:[]});return{tableTsKey:o.tsName,sql:A,selection:m}}},Q=class{static[t]=`CockroachSelectBuilder`;fields;session;dialect;withList=[];distinct;constructor(e){this.fields=e.fields,this.session=e.session,this.dialect=e.dialect,e.withList&&(this.withList=e.withList),this.distinct=e.distinct}authToken;setToken(e){return this.authToken=e,this}from(e){let t=!!this.fields,n=e,i;return i=this.fields?this.fields:r(n,f)?Object.fromEntries(Object.keys(n._.selectedFields).map(e=>[e,n[e]])):r(n,X)?n[l].selectedFields:r(n,p)?{}:N(n),new Ht({table:n,fields:i,isPartialSelect:t,session:this.session,dialect:this.dialect,withList:this.withList,distinct:this.distinct}).setToken(this.authToken)}},Vt=class extends te{static[t]=`CockroachSelectQueryBuilder`;_;config;joinsNotNullableMap;tableName;isPartialSelect;session;dialect;constructor({table:e,fields:t,isPartialSelect:n,session:r,dialect:i,withList:a,distinct:o}){super(),this.config={withList:a,table:e,fields:{...t},distinct:o,setOperators:[]},this.isPartialSelect=n,this.session=r,this.dialect=i,this._={selectedFields:t},this.tableName=x(e),this.joinsNotNullableMap=typeof this.tableName==`string`?{[this.tableName]:!0}:{}}createJoin(e,t){return((n,i)=>{let o=this.tableName,s=x(n);if(typeof s==`string`&&this.config.joins?.some(e=>e.alias===s))throw Error(`Alias "${s}" is already used in this query`);if(!this.isPartialSelect&&(Object.keys(this.joinsNotNullableMap).length===1&&typeof o==`string`&&(this.config.fields={[o]:this.config.fields}),typeof s==`string`&&!r(n,p))){let e=r(n,f)?n._.selectedFields:r(n,c)?n[l].selectedFields:n[a.Symbol.Columns];this.config.fields[s]=e}if(typeof i==`function`&&(i=i(new Proxy(this.config.fields,new M({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})))),this.config.joins||(this.config.joins=[]),this.config.joins.push({on:i,table:n,joinType:e,alias:s,lateral:t}),typeof s==`string`)switch(e){case`left`:this.joinsNotNullableMap[s]=!1;break;case`right`:this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[s]=!0;break;case`cross`:case`inner`:this.joinsNotNullableMap[s]=!0;break;case`full`:this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[s]=!1;break}return this})}leftJoin=this.createJoin(`left`,!1);leftJoinLateral=this.createJoin(`left`,!0);rightJoin=this.createJoin(`right`,!1);innerJoin=this.createJoin(`inner`,!1);innerJoinLateral=this.createJoin(`inner`,!0);fullJoin=this.createJoin(`full`,!1);crossJoin=this.createJoin(`cross`,!1);crossJoinLateral=this.createJoin(`cross`,!0);createSetOperator(e,t){return n=>{let r=typeof n==`function`?n(Ut()):n;if(!E(this.getSelectedFields(),r.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:r}),this}}union=this.createSetOperator(`union`,!1);unionAll=this.createSetOperator(`union`,!0);intersect=this.createSetOperator(`intersect`,!1);intersectAll=this.createSetOperator(`intersect`,!0);except=this.createSetOperator(`except`,!1);exceptAll=this.createSetOperator(`except`,!0);addSetOperators(e){return this.config.setOperators.push(...e),this}where(e){return typeof e==`function`&&(e=e(new Proxy(this.config.fields,new M({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})))),this.config.where=e,this}having(e){return typeof e==`function`&&(e=e(new Proxy(this.config.fields,new M({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})))),this.config.having=e,this}groupBy(...e){if(typeof e[0]==`function`){let t=e[0](new Proxy(this.config.fields,new M({sqlAliasedBehavior:`alias`,sqlBehavior:`sql`})));this.config.groupBy=Array.isArray(t)?t:[t]}else this.config.groupBy=e;return this}orderBy(...e){if(typeof e[0]==`function`){let t=e[0](new Proxy(this.config.fields,new M({sqlAliasedBehavior:`alias`,sqlBehavior:`sql`}))),n=Array.isArray(t)?t:[t];this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=n:this.config.orderBy=n}else{let t=e;this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=t:this.config.orderBy=t}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}for(e,t={}){return this.config.lockingClause={strength:e,config:t},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 f(this.getSQL(),this.config.fields,e),new M({alias:e,sqlAliasedBehavior:`alias`,sqlBehavior:`error`}))}getSelectedFields(){return new Proxy(this.config.fields,new M({alias:this.tableName,sqlAliasedBehavior:`alias`,sqlBehavior:`error`}))}$dynamic(){return this}},Ht=class extends Vt{static[t]=`CockroachSelect`;_prepare(e){let{session:t,config:n,dialect:r,joinsNotNullableMap:i,authToken:a}=this;if(!t)throw Error(`Cannot execute a query on a query builder. Please use a database instance instead.`);return u.startActiveSpan(`drizzle.prepareQuery`,()=>{let o=j(n.fields),s=t.prepareQuery(r.sqlToQuery(this.getSQL()),o,e,!0);return s.joinsNotNullableMap=i,s.setToken(a)})}prepare(e){return this._prepare(e)}authToken;setToken(e){return this.authToken=e,this}execute=e=>u.startActiveSpan(`drizzle.operation`,()=>this._prepare().execute(e,this.authToken))};b(Ht,[T]);function $(e,t){return(n,r,...i)=>{let a=[r,...i].map(n=>({type:e,isAll:t,rightSelect:n}));for(let e of a)if(!E(n.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 n.addSetOperators(a)}}const Ut=()=>({union:Wt,unionAll:Gt,intersect:Kt,intersectAll:qt,except:Jt,exceptAll:Yt}),Wt=$(`union`,!1),Gt=$(`union`,!0),Kt=$(`intersect`,!1),qt=$(`intersect`,!0),Jt=$(`except`,!1),Yt=$(`except`,!0);var Xt=class{static[t]=`CockroachQueryBuilder`;dialect;dialectConfig;constructor(e){this.dialect=r(e,Z)?e:void 0,this.dialectConfig=r(e,Z)?void 0:e}$with=(e,t)=>{let n=this;return{as:r=>(typeof r==`function`&&(r=r(n)),new Proxy(new d(r.getSQL(),t??(`getSelectedFields`in r?r.getSelectedFields()??{}:{}),e,!0),new M({alias:e,sqlAliasedBehavior:`alias`,sqlBehavior:`error`})))}};with(...e){let t=this;function n(n){return new Q({fields:n??void 0,session:void 0,dialect:t.getDialect(),withList:e})}function r(e){return new Q({fields:e??void 0,session:void 0,dialect:t.getDialect(),distinct:!0})}function i(e,n){return new Q({fields:n??void 0,session:void 0,dialect:t.getDialect(),distinct:{on:e}})}return{select:n,selectDistinct:r,selectDistinctOn:i}}select(e){return new Q({fields:e??void 0,session:void 0,dialect:this.getDialect()})}selectDistinct(e){return new Q({fields:e??void 0,session:void 0,dialect:this.getDialect(),distinct:!0})}selectDistinctOn(e,t){return new Q({fields:t??void 0,session:void 0,dialect:this.getDialect(),distinct:{on:e}})}getDialect(){return this.dialect||=new Z(this.dialectConfig),this.dialect}};export{Y as a,X as i,Q as n,Bt as o,Z as r,Xt as t};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{D as e,G as t,H as n,K as r,O as i,R as a,V as o,W as s,a as c,c as l,d as u,i as d,m as f,n as ee,q as te,r as p,s as ne,t as m,u as h}from"./sql-D-eKV1Dn.mjs";function re(e){return(e.replace(/['\u2019]/g,``).match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).map(e=>e.toLowerCase()).join(`_`)}function ie(e){return(e.replace(/['\u2019]/g,``).match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).reduce((e,t,n)=>e+(n===0?t.toLowerCase():`${t[0].toUpperCase()}${t.slice(1)}`),``)}function ae(e){return e}var oe=class{static[t]=`CasingCache`;cache={};cachedTables={};convert;constructor(e){this.convert=e===`snake_case`?re:e===`camelCase`?ie:ae}getColumnCasing(e){if(!e.keyAsName)return e.name;let t=`${e.table[a.Symbol.Schema]??`public`}.${e.table[a.Symbol.OriginalName]}.${e.name}`;return this.cache[t]||this.cacheTable(e.table),this.cache[t]}cacheTable(e){let t=`${e[a.Symbol.Schema]??`public`}.${e[a.Symbol.OriginalName]}`;if(!this.cachedTables[t]){for(let n of Object.values(e[a.Symbol.Columns])){if(!r(n,s))continue;let e=`${t}.${n.name}`;this.cache[e]=this.convert(n.name)}this.cachedTables[t]=!0}}clearCache(){this.cache={},this.cachedTables={}}},g=class{constructor(e,t){this.table=e,this.ignoreColumnAlias=t}static[t]=`ColumnTableAliasProxyHandler`;get(e,t){return t===`table`?this.table:t===`isAlias`&&this.ignoreColumnAlias?!1:e[t]}},_=class{constructor(e,t,n){this.alias=e,this.replaceOriginalName=t,this.ignoreColumnAlias=n}static[t]=`TableAliasProxyHandler`;get(e,t){if(t===a.Symbol.IsAlias)return!0;if(t===a.Symbol.Name||this.replaceOriginalName&&t===a.Symbol.OriginalName)return this.alias;if(t===u)return{...e[u],name:this.alias,isAlias:!0};if(t===a.Symbol.Columns){let t=e[a.Symbol.Columns];if(!t)return t;let n={};return Object.keys(t).map(r=>{n[r]=new Proxy(t[r],new g(new Proxy(e,this),this.ignoreColumnAlias))}),n}let n=e[t];return r(n,s)?new Proxy(n,new g(new Proxy(e,this),this.ignoreColumnAlias)):n}},se=class{constructor(e){this.alias=e}static[t]=`ColumnAliasProxyHandler`;get(e,t){return t===`isAlias`?!0:t===`name`?this.alias:t===`keyAsName`?!1:t===te?()=>e:e[t]}};function ce(e,t){return new Proxy(e,new _(t,!1,!1))}function le(e,t){return new Proxy(e,new se(t))}function v(e,t){return new Proxy(e,new g(new Proxy(e.table,new _(t,!1,!1)),!1))}function y(e,t){return new p.Aliased(b(e.sql,t),e.fieldAlias)}function b(e,t){return h.join(e.queryChunks.map(e=>r(e,s)?v(e,t):r(e,p)?b(e,t):r(e,p.Aliased)?y(e,t):e))}s.prototype.as=function(e){return le(this,e)};function ue(e){return e[te]()}function de(e,t,n){let i={},a=e.reduce((e,{path:a,field:c},l)=>{let u;u=r(c,s)?c:r(c,p)?c.decoder:r(c,f)?c._.sql.decoder:c.sql.decoder;let d=e;for(let[e,f]of a.entries())if(e<a.length-1)f in d||(d[f]={}),d=d[f];else{let e=t[l],ee=d[f]=e===null?null:u.mapFromDriverValue(e);if(n&&r(c,s)&&a.length===2){let e=a[0];e in i?typeof i[e]==`string`&&i[e]!==o(c.table)&&(i[e]=!1):i[e]=ee===null?o(c.table):!1}}return e},{});if(n&&Object.keys(i).length>0)for(let[e,t]of Object.entries(i))typeof t==`string`&&!n[t]&&(a[e]=null);return a}function x(e,t){return Object.entries(e).reduce((e,[n,i])=>{if(typeof n!=`string`)return e;let o=t?[...t,n]:[n];return r(i,s)||r(i,p)||r(i,p.Aliased)||r(i,f)?e.push({path:o,field:i}):r(i,a)?e.push(...x(i[a.Symbol.Columns],o)):e.push(...x(i,o)),e},[])}function fe(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let[e,t]of n.entries())if(t!==r[e])return!1;return!0}function pe(e,t){let n=Object.entries(t).filter(([,e])=>e!==void 0).map(([t,n])=>r(n,p)||r(n,s)?[t,n]:[t,new m(n,e[a.Symbol.Columns][t])]);if(n.length===0)throw Error(`No values to set`);return Object.fromEntries(n)}function me(e,t){for(let n of t)for(let t of Object.getOwnPropertyNames(n.prototype))t!==`constructor`&&Object.defineProperty(e.prototype,t,Object.getOwnPropertyDescriptor(n.prototype,t)||Object.create(null))}function he(e){return e[a.Symbol.Columns]}function ge(e){return r(e,f)?e._.alias:r(e,c)?e[u].name:r(e,p)?void 0:e[a.Symbol.IsAlias]?e[a.Symbol.Name]:e[a.Symbol.BaseName]}function S(e,t){return{name:typeof e==`string`&&e.length>0?e:``,config:typeof e==`object`?e:t}}function _e(e){if(typeof e!=`object`||!e||e.constructor.name!==`Object`)return!1;if(`logger`in e){let t=typeof e.logger;return!(t!==`boolean`&&(t!==`object`||typeof e.logger.logQuery!=`function`)&&t!==`undefined`)}if(`schema`in e){let t=typeof e.schema;return!(t!==`object`&&t!==`undefined`)}if(`relations`in e){let t=typeof e.relations;return!(t!==`object`&&t!==`undefined`)}if(`casing`in e){let t=typeof e.casing;return!(t!==`string`&&t!==`undefined`)}if(`mode`in e)return!(e.mode!==`default`||e.mode!==`planetscale`||e.mode!==void 0);if(`connection`in e){let t=typeof e.connection;return!(t!==`string`&&t!==`object`&&t!==`undefined`)}if(`client`in e){let t=typeof e.client;return!(t!==`object`&&t!==`function`&&t!==`undefined`)}return Object.keys(e).length===0}typeof TextDecoder>`u`||new TextDecoder;var ve=class{static[t]=`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)}},ye=class e{static[t]=`SelectionProxyHandler`;config;constructor(e){this.config={...e}}get(t,n){if(n===`_`)return{...t._,selectedFields:new Proxy(t._.selectedFields,this)};if(n===u)return{...t[u],selectedFields:new Proxy(t[u].selectedFields,this)};if(typeof n==`symbol`)return t[n];let i=(r(t,f)?t._.selectedFields:r(t,c)?t[u].selectedFields:t)[n];if(r(i,p.Aliased)){if(this.config.sqlAliasedBehavior===`sql`&&!i.isSelectionField)return i.sql;let e=i.clone();return e.isSelectionField=!0,e}if(r(i,p)){if(this.config.sqlBehavior===`sql`)return i;throw Error(`You tried to reference "${n}" 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 r(i,s)?this.config.alias?new Proxy(i,new g(new Proxy(i.table,new _(this.config.alias,this.config.replaceOriginalName??!1,!0)),!0)):i:typeof i!=`object`||!i?i:new Proxy(i,new e(this.config))}},C=class extends i{static[t]=`PgIntColumnBaseBuilder`;generatedAlwaysAsIdentity(e){if(e){let{name:t,...n}=e;this.config.generatedIdentity={type:`always`,sequenceName:t,sequenceOptions:n}}else this.config.generatedIdentity={type:`always`};return this.config.hasDefault=!0,this.config.notNull=!0,this}generatedByDefaultAsIdentity(e){if(e){let{name:t,...n}=e;this.config.generatedIdentity={type:`byDefault`,sequenceName:t,sequenceOptions:n}}else this.config.generatedIdentity={type:`byDefault`};return this.config.hasDefault=!0,this.config.notNull=!0,this}},w=class extends C{static[t]=`PgBigInt53Builder`;constructor(e){super(e,`number int53`,`PgBigInt53`)}build(e){return new T(e,this.config)}},T=class extends e{static[t]=`PgBigInt53`;getSQLType(){return`bigint`}mapFromDriverValue(e){return typeof e==`number`?e:Number(e)}},E=class extends C{static[t]=`PgBigInt64Builder`;constructor(e){super(e,`bigint int64`,`PgBigInt64`)}build(e){return new D(e,this.config)}},D=class extends e{static[t]=`PgBigInt64`;getSQLType(){return`bigint`}mapFromDriverValue(e){return BigInt(e)}},O=class extends C{static[t]=`PgBigIntStringBuilder`;constructor(e){super(e,`string int64`,`PgBigIntString`)}build(e){return new k(e,this.config)}},k=class extends e{static[t]=`PgBigIntString`;getSQLType(){return`bigint`}mapFromDriverValue(e){return typeof e==`string`?e:String(e)}};function A(e,t){let{name:n,config:r}=S(e,t);return r.mode===`number`?new w(n):r.mode===`string`?new O(n):new E(n)}var j=class extends i{static[t]=`PgBigSerial53Builder`;constructor(e){super(e,`number int53`,`PgBigSerial53`),this.config.hasDefault=!0,this.config.notNull=!0}build(e){return new M(e,this.config)}},M=class extends e{static[t]=`PgBigSerial53`;getSQLType(){return`bigserial`}mapFromDriverValue(e){return typeof e==`number`?e:Number(e)}},N=class extends i{static[t]=`PgBigSerial64Builder`;constructor(e){super(e,`bigint int64`,`PgBigSerial64`),this.config.hasDefault=!0,this.config.notNull=!0}build(e){return new P(e,this.config)}},P=class extends e{static[t]=`PgBigSerial64`;getSQLType(){return`bigserial`}mapFromDriverValue(e){return BigInt(e)}};function F(e,t){let{name:n,config:r}=S(e,t);return r.mode===`number`?new j(n):new N(n)}var I=class extends i{static[t]=`PgBooleanBuilder`;constructor(e){super(e,`boolean`,`PgBoolean`)}build(e){return new L(e,this.config)}},L=class extends e{static[t]=`PgBoolean`;getSQLType(){return`boolean`}};function R(e){return new I(e??``)}var z=class extends i{static[t]=`PgCharBuilder`;constructor(e,t){super(e,t.enum?.length?`string enum`:`string`,`PgChar`),this.config.length=t.length??1,this.config.setLength=t.length!==void 0,this.config.enumValues=t.enum}build(e){return new B(e,this.config)}},B=class extends e{static[t]=`PgChar`;enumValues=this.config.enumValues;getSQLType(){return this.config.setLength?`char(${this.length})`:`char`}};function V(e,t={}){let{name:n,config:r}=S(e,t);return new z(n,r)}var H=class extends i{static[t]=`PgCidrBuilder`;constructor(e){super(e,`string cidr`,`PgCidr`)}build(e){return new U(e,this.config)}},U=class extends e{static[t]=`PgCidr`;getSQLType(){return`cidr`}};function be(e){return new H(e??``)}var xe=class extends i{static[t]=`PgCustomColumnBuilder`;constructor(e,t,n){super(e,`custom`,`PgCustomColumn`),this.config.fieldConfig=t,this.config.customTypeParams=n}build(e){return new Se(e,this.config)}},Se=class extends e{static[t]=`PgCustomColumn`;sqlName;mapTo;mapFrom;mapJson;forJsonSelect;constructor(e,t){super(e,t),this.sqlName=t.customTypeParams.dataType(t.fieldConfig),this.mapTo=t.customTypeParams.toDriver,this.mapFrom=t.customTypeParams.fromDriver,this.mapJson=t.customTypeParams.fromJson,this.forJsonSelect=t.customTypeParams.forJsonSelect}getSQLType(){return this.sqlName}mapFromDriverValue(e){return typeof this.mapFrom==`function`?this.mapFrom(e):e}mapFromJsonValue(e){return typeof this.mapJson==`function`?this.mapJson(e):this.mapFromDriverValue(e)}jsonSelectIdentifier(e,t,n){if(typeof this.forJsonSelect==`function`)return this.forJsonSelect(e,t,n);let r=this.getSQLType().toLowerCase(),i=r.indexOf(`(`);switch(i+1?r.slice(0,i):r){case`bytea`:case`geometry`:case`timestamp`:case`numeric`:case`bigint`:{let r=`[]`.repeat(n??0);return t`${e}::text${t.raw(r).if(n)}`}default:return e}}mapToDriverValue(e){return typeof this.mapTo==`function`?this.mapTo(e):e}};function Ce(e){return(t,n)=>{let{name:r,config:i}=S(t,n);return new xe(r,i,e)}}var W=class extends i{static[t]=`PgDateColumnBaseBuilder`;defaultNow(){return this.default(h`now()`)}},we=class extends W{static[t]=`PgDateBuilder`;constructor(e){super(e,`object date`,`PgDate`)}build(e){return new Te(e,this.config)}},Te=class extends e{static[t]=`PgDate`;getSQLType(){return`date`}mapFromDriverValue(e){return typeof e==`string`?new Date(e):e}mapToDriverValue(e){return typeof e==`string`?e:e.toISOString()}},Ee=class extends W{static[t]=`PgDateStringBuilder`;constructor(e){super(e,`string date`,`PgDateString`)}build(e){return new De(e,this.config)}},De=class extends e{static[t]=`PgDateString`;getSQLType(){return`date`}mapFromDriverValue(e){return typeof e==`string`?e:e.toISOString().slice(0,-14)}mapToDriverValue(e){return typeof e==`string`?e:e.toISOString()}};function Oe(e,t){let{name:n,config:r}=S(e,t);return r?.mode===`date`?new we(n):new Ee(n)}var ke=class extends i{static[t]=`PgDoublePrecisionBuilder`;constructor(e){super(e,`number double`,`PgDoublePrecision`)}build(e){return new Ae(e,this.config)}},Ae=class extends e{static[t]=`PgDoublePrecision`;getSQLType(){return`double precision`}mapFromDriverValue(e){return typeof e==`string`?Number.parseFloat(e):e}};function je(e){return new ke(e??``)}var Me=class extends i{static[t]=`PgInetBuilder`;constructor(e){super(e,`string inet`,`PgInet`)}build(e){return new Ne(e,this.config)}},Ne=class extends e{static[t]=`PgInet`;getSQLType(){return`inet`}};function Pe(e){return new Me(e??``)}var Fe=class extends C{static[t]=`PgIntegerBuilder`;constructor(e){super(e,`number int32`,`PgInteger`)}build(e){return new Ie(e,this.config)}},Ie=class extends e{static[t]=`PgInteger`;getSQLType(){return`integer`}mapFromDriverValue(e){return typeof e==`string`?Number.parseInt(e):e}};function Le(e){return new Fe(e??``)}var Re=class extends i{static[t]=`PgIntervalBuilder`;constructor(e,t){super(e,`string interval`,`PgInterval`),this.config.intervalConfig=t}build(e){return new ze(e,this.config)}},ze=class extends e{static[t]=`PgInterval`;fields=this.config.intervalConfig.fields;precision=this.config.intervalConfig.precision;getSQLType(){return`interval${this.fields?` ${this.fields}`:``}${this.precision?`(${this.precision})`:``}`}};function Be(e,t={}){let{name:n,config:r}=S(e,t);return new Re(n,r)}var Ve=class extends i{static[t]=`PgJsonBuilder`;constructor(e){super(e,`object json`,`PgJson`)}build(e){return new He(e,this.config)}},He=class extends e{static[t]=`PgJson`;constructor(e,t){super(e,t)}getSQLType(){return`json`}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){if(typeof e==`string`)try{return JSON.parse(e)}catch{return e}return e}};function Ue(e){return new Ve(e??``)}var We=class extends i{static[t]=`PgJsonbBuilder`;constructor(e){super(e,`object json`,`PgJsonb`)}build(e){return new Ge(e,this.config)}},Ge=class extends e{static[t]=`PgJsonb`;constructor(e,t){super(e,t)}getSQLType(){return`jsonb`}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){if(typeof e==`string`)try{return JSON.parse(e)}catch{return e}return e}};function Ke(e){return new We(e??``)}var qe=class extends i{static[t]=`PgLineBuilder`;constructor(e){super(e,`array line`,`PgLine`)}build(e){return new Je(e,this.config)}},Je=class extends e{static[t]=`PgLine`;mode=`tuple`;getSQLType(){return`line`}mapFromDriverValue(e){let[t,n,r]=e.slice(1,-1).split(`,`);return[Number.parseFloat(t),Number.parseFloat(n),Number.parseFloat(r)]}mapToDriverValue(e){return`{${e[0]},${e[1]},${e[2]}}`}},Ye=class extends i{static[t]=`PgLineABCBuilder`;constructor(e){super(e,`object line`,`PgLineABC`)}build(e){return new Xe(e,this.config)}},Xe=class extends e{static[t]=`PgLineABC`;mode=`abc`;getSQLType(){return`line`}mapFromDriverValue(e){let[t,n,r]=e.slice(1,-1).split(`,`);return{a:Number.parseFloat(t),b:Number.parseFloat(n),c:Number.parseFloat(r)}}mapToDriverValue(e){return`{${e.a},${e.b},${e.c}}`}};function Ze(e,t){let{name:n,config:r}=S(e,t);return!r?.mode||r.mode===`tuple`?new qe(n):new Ye(n)}var Qe=class extends i{static[t]=`PgMacaddrBuilder`;constructor(e){super(e,`string macaddr`,`PgMacaddr`)}build(e){return new $e(e,this.config)}},$e=class extends e{static[t]=`PgMacaddr`;getSQLType(){return`macaddr`}};function et(e){return new Qe(e??``)}var tt=class extends i{static[t]=`PgMacaddr8Builder`;constructor(e){super(e,`string macaddr8`,`PgMacaddr8`)}build(e){return new nt(e,this.config)}},nt=class extends e{static[t]=`PgMacaddr8`;getSQLType(){return`macaddr8`}};function rt(e){return new tt(e??``)}var it=class extends i{static[t]=`PgNumericBuilder`;constructor(e,t,n){super(e,`string numeric`,`PgNumeric`),this.config.precision=t,this.config.scale=n}build(e){return new at(e,this.config)}},at=class extends e{static[t]=`PgNumeric`;precision;scale;constructor(e,t){super(e,t),this.precision=t.precision,this.scale=t.scale}mapFromDriverValue(e){return typeof e==`string`?e:String(e)}getSQLType(){return this.precision!==void 0&&this.scale!==void 0?`numeric(${this.precision}, ${this.scale})`:this.precision===void 0?`numeric`:`numeric(${this.precision})`}},ot=class extends i{static[t]=`PgNumericNumberBuilder`;constructor(e,t,n){super(e,`number`,`PgNumericNumber`),this.config.precision=t,this.config.scale=n}build(e){return new st(e,this.config)}},st=class extends e{static[t]=`PgNumericNumber`;precision;scale;constructor(e,t){super(e,t),this.precision=t.precision,this.scale=t.scale}mapFromDriverValue(e){return typeof e==`number`?e:Number(e)}mapToDriverValue=String;getSQLType(){return this.precision!==void 0&&this.scale!==void 0?`numeric(${this.precision}, ${this.scale})`:this.precision===void 0?`numeric`:`numeric(${this.precision})`}},ct=class extends i{static[t]=`PgNumericBigIntBuilder`;constructor(e,t,n){super(e,`bigint int64`,`PgNumericBigInt`),this.config.precision=t,this.config.scale=n}build(e){return new lt(e,this.config)}},lt=class extends e{static[t]=`PgNumericBigInt`;precision;scale;constructor(e,t){super(e,t),this.precision=t.precision,this.scale=t.scale}mapFromDriverValue=BigInt;mapToDriverValue=String;getSQLType(){return this.precision!==void 0&&this.scale!==void 0?`numeric(${this.precision}, ${this.scale})`:this.precision===void 0?`numeric`:`numeric(${this.precision})`}};function ut(e,t){let{name:n,config:r}=S(e,t),i=r?.mode;return i===`number`?new ot(n,r?.precision,r?.scale):i===`bigint`?new ct(n,r?.precision,r?.scale):new it(n,r?.precision,r?.scale)}var dt=class extends i{static[t]=`PgPointTupleBuilder`;constructor(e){super(e,`array point`,`PgPointTuple`)}build(e){return new ft(e,this.config)}},ft=class extends e{static[t]=`PgPointTuple`;mode=`tuple`;getSQLType(){return`point`}mapFromDriverValue(e){if(typeof e==`string`){let[t,n]=e.slice(1,-1).split(`,`);return[Number.parseFloat(t),Number.parseFloat(n)]}return[e.x,e.y]}mapToDriverValue(e){return`(${e[0]},${e[1]})`}},pt=class extends i{static[t]=`PgPointObjectBuilder`;constructor(e){super(e,`object point`,`PgPointObject`)}build(e){return new mt(e,this.config)}},mt=class extends e{static[t]=`PgPointObject`;mode=`xy`;getSQLType(){return`point`}mapFromDriverValue(e){if(typeof e==`string`){let[t,n]=e.slice(1,-1).split(`,`);return{x:Number.parseFloat(t),y:Number.parseFloat(n)}}return e}mapToDriverValue(e){return`(${e.x},${e.y})`}};function ht(e,t){let{name:n,config:r}=S(e,t);return!r?.mode||r.mode===`tuple`?new dt(n):new pt(n)}function gt(e){let t=[];for(let n=0;n<e.length;n+=2)t.push(Number.parseInt(e.slice(n,n+2),16));return new Uint8Array(t)}function _t(e,t){let n=new ArrayBuffer(8),r=new DataView(n);for(let n=0;n<8;n++)r.setUint8(n,e[t+n]);return r.getFloat64(0,!0)}function vt(e){let t=gt(e),n=0,r=t[n];n+=1;let i=new DataView(t.buffer),a=i.getUint32(n,r===1);n+=4;let o;if(a&536870912&&(o=i.getUint32(n,r===1),n+=4),(a&65535)==1){let e=_t(t,n);n+=8;let r=_t(t,n);return n+=8,{srid:o,point:[e,r]}}throw Error(`Unsupported geometry type`)}var yt=class extends i{static[t]=`PgGeometryBuilder`;constructor(e,t){super(e,`array geometry`,`PgGeometry`),this.config.srid=t}build(e){return new bt(e,this.config)}},bt=class extends e{static[t]=`PgGeometry`;srid=this.config.srid;mode=`tuple`;getSQLType(){return`geometry(point${this.srid===void 0?``:`,${this.srid}`})`}mapFromDriverValue(e){return typeof e==`string`?vt(e).point:e}mapToDriverValue(e){return`point(${e[0]} ${e[1]})`}},xt=class extends i{static[t]=`PgGeometryObjectBuilder`;constructor(e,t){super(e,`object geometry`,`PgGeometryObject`),this.config.srid=t}build(e){return new St(e,this.config)}},St=class extends e{static[t]=`PgGeometryObject`;srid=this.config.srid;mode=`object`;getSQLType(){return`geometry(point${this.srid===void 0?``:`,${this.srid}`})`}mapFromDriverValue(e){let t=vt(e);return{x:t.point[0],y:t.point[1]}}mapToDriverValue(e){return`point(${e.x} ${e.y})`}};function Ct(e,t){let{name:n,config:r}=S(e,t);return!r?.mode||r.mode===`tuple`?new yt(n,r?.srid):new xt(n,r?.srid)}var wt=class extends i{static[t]=`PgRealBuilder`;constructor(e,t){super(e,`number float`,`PgReal`),this.config.length=t}build(e){return new Tt(e,this.config)}},Tt=class extends e{static[t]=`PgReal`;constructor(e,t){super(e,t)}getSQLType(){return`real`}mapFromDriverValue=e=>typeof e==`string`?Number.parseFloat(e):e};function G(e){return new wt(e??``)}var Et=class extends i{static[t]=`PgSerialBuilder`;constructor(e){super(e,`number int32`,`PgSerial`),this.config.hasDefault=!0,this.config.notNull=!0}build(e){return new Dt(e,this.config)}},Dt=class extends e{static[t]=`PgSerial`;getSQLType(){return`serial`}};function Ot(e){return new Et(e??``)}var kt=class extends C{static[t]=`PgSmallIntBuilder`;constructor(e){super(e,`number int16`,`PgSmallInt`)}build(e){return new At(e,this.config)}},At=class extends e{static[t]=`PgSmallInt`;getSQLType(){return`smallint`}mapFromDriverValue=e=>typeof e==`string`?Number(e):e};function jt(e){return new kt(e??``)}var Mt=class extends i{static[t]=`PgSmallSerialBuilder`;constructor(e){super(e,`number int16`,`PgSmallSerial`),this.config.hasDefault=!0,this.config.notNull=!0}build(e){return new Nt(e,this.config)}},Nt=class extends e{static[t]=`PgSmallSerial`;getSQLType(){return`smallserial`}};function Pt(e){return new Mt(e??``)}var Ft=class extends i{static[t]=`PgTextBuilder`;constructor(e,t){super(e,t.enum?.length?`string enum`:`string`,`PgText`),this.config.enumValues=t.enum}build(e){return new It(e,this.config,this.config.enumValues)}},It=class extends e{static[t]=`PgText`;enumValues;constructor(e,t,n){super(e,t),this.enumValues=n}getSQLType(){return`text`}};function Lt(e,t={}){let{name:n,config:r}=S(e,t);return new Ft(n,r)}var Rt=class extends W{constructor(e,t,n){super(e,`string time`,`PgTime`),this.withTimezone=t,this.precision=n,this.config.withTimezone=t,this.config.precision=n}static[t]=`PgTimeBuilder`;build(e){return new zt(e,this.config)}},zt=class extends e{static[t]=`PgTime`;withTimezone;precision;constructor(e,t){super(e,t),this.withTimezone=t.withTimezone,this.precision=t.precision}getSQLType(){return`time${this.precision===void 0?``:`(${this.precision})`}${this.withTimezone?` with time zone`:``}`}};function Bt(e,t={}){let{name:n,config:r}=S(e,t);return new Rt(n,r.withTimezone??!1,r.precision)}var Vt=class extends W{static[t]=`PgTimestampBuilder`;constructor(e,t,n){super(e,`object date`,`PgTimestamp`),this.config.withTimezone=t,this.config.precision=n}build(e){return new Ht(e,this.config)}},Ht=class extends e{static[t]=`PgTimestamp`;withTimezone;precision;constructor(e,t){super(e,t),this.withTimezone=t.withTimezone,this.precision=t.precision}getSQLType(){return`timestamp${this.precision===void 0?``:` (${this.precision})`}${this.withTimezone?` with time zone`:``}`}mapFromDriverValue(e){return typeof e==`string`?new Date(this.withTimezone?e:e+`+0000`):e}mapToDriverValue(e){return typeof e==`string`?e:e.toISOString()}},Ut=class extends W{static[t]=`PgTimestampStringBuilder`;constructor(e,t,n){super(e,`string timestamp`,`PgTimestampString`),this.config.withTimezone=t,this.config.precision=n}build(e){return new Wt(e,this.config)}},Wt=class extends e{static[t]=`PgTimestampString`;withTimezone;precision;constructor(e,t){super(e,t),this.withTimezone=t.withTimezone,this.precision=t.precision}getSQLType(){return`timestamp${this.precision===void 0?``:`(${this.precision})`}${this.withTimezone?` with time zone`:``}`}mapFromDriverValue(e){if(typeof e==`string`)return e;let t=e.toISOString().slice(0,-1).replace(`T`,` `);if(this.withTimezone){let n=e.getTimezoneOffset();return`${t}${n<=0?`+`:`-`}${Math.floor(Math.abs(n)/60).toString().padStart(2,`0`)}`}return t}mapToDriverValue(e){return typeof e==`string`?e:e.toISOString()}};function Gt(e,t={}){let{name:n,config:r}=S(e,t);return r?.mode===`string`?new Ut(n,r.withTimezone??!1,r.precision):new Vt(n,r?.withTimezone??!1,r?.precision)}var Kt=class extends i{static[t]=`PgUUIDBuilder`;constructor(e){super(e,`string uuid`,`PgUUID`)}defaultRandom(){return this.default(h`gen_random_uuid()`)}build(e){return new qt(e,this.config)}},qt=class extends e{static[t]=`PgUUID`;getSQLType(){return`uuid`}};function Jt(e){return new Kt(e??``)}var Yt=class extends i{static[t]=`PgVarcharBuilder`;constructor(e,t){super(e,t.enum?.length?`string enum`:`string`,`PgVarchar`),this.config.length=t.length,this.config.enumValues=t.enum}build(e){return new Xt(e,this.config)}},Xt=class extends e{static[t]=`PgVarchar`;enumValues=this.config.enumValues;getSQLType(){return this.length===void 0?`varchar`:`varchar(${this.length})`}};function Zt(e,t={}){let{name:n,config:r}=S(e,t);return new Yt(n,r)}var Qt=class extends i{static[t]=`PgBinaryVectorBuilder`;constructor(e,t){super(e,`string binary`,`PgBinaryVector`),this.config.length=t.dimensions,this.config.isLengthExact=!0}build(e){return new $t(e,this.config)}},$t=class extends e{static[t]=`PgBinaryVector`;getSQLType(){return`bit(${this.length})`}};function en(e,t){let{name:n,config:r}=S(e,t);return new Qt(n,r)}var tn=class extends i{static[t]=`PgHalfVectorBuilder`;constructor(e,t){super(e,`array halfvector`,`PgHalfVector`),this.config.length=t.dimensions,this.config.isLengthExact=!0}build(e){return new nn(e,this.config)}},nn=class extends e{static[t]=`PgHalfVector`;getSQLType(){return`halfvec(${this.length})`}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){return e.slice(1,-1).split(`,`).map(e=>Number.parseFloat(e))}};function rn(e,t){let{name:n,config:r}=S(e,t);return new tn(n,r)}var an=class extends i{static[t]=`PgSparseVectorBuilder`;constructor(e,t){super(e,`string sparsevec`,`PgSparseVector`),this.config.dimensions=t.dimensions}build(e){return new on(e,this.config)}},on=class extends e{static[t]=`PgSparseVector`;dimensions=this.config.dimensions;getSQLType(){return`sparsevec(${this.dimensions})`}};function sn(e,t){let{name:n,config:r}=S(e,t);return new an(n,r)}var cn=class extends i{static[t]=`PgVectorBuilder`;constructor(e,t){super(e,`array vector`,`PgVector`),this.config.length=t.dimensions,this.config.isLengthExact=!0}build(e){return new ln(e,this.config)}},ln=class extends e{static[t]=`PgVector`;getSQLType(){return`vector(${this.length})`}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){return e.slice(1,-1).split(`,`).map(e=>Number.parseFloat(e))}};function un(e,t){let{name:n,config:r}=S(e,t);return new cn(n,r)}function dn(){return{bigint:A,bigserial:F,boolean:R,char:V,cidr:be,customType:Ce,date:Oe,doublePrecision:je,inet:Pe,integer:Le,interval:Be,json:Ue,jsonb:Ke,line:Ze,macaddr:et,macaddr8:rt,numeric:ut,point:ht,geometry:Ct,real:G,serial:Ot,smallint:jt,smallserial:Pt,text:Lt,time:Bt,timestamp:Gt,uuid:Jt,varchar:Zt,bit:en,halfvec:rn,sparsevec:sn,vector:un}}const K=Symbol.for(`drizzle:PgInlineForeignKeys`),q=Symbol.for(`drizzle:EnableRLS`);var J=class extends a{static[t]=`PgTable`;static Symbol=Object.assign({},a.Symbol,{InlineForeignKeys:K,EnableRLS:q});[K]=[];[q]=!1;[a.Symbol.ExtraConfigBuilder]=void 0;[a.Symbol.ExtraConfigColumns]={}};function Y(e,t,n,r,i=e){let o=new J(e,r,i),s=typeof t==`function`?t(dn()):t,c=Object.fromEntries(Object.entries(s).map(([e,t])=>{let n=t;n.setName(e);let r=n.build(o);return o[K].push(...n.buildForeignKeys(r,o)),[e,r]})),l=Object.fromEntries(Object.entries(s).map(([e,t])=>{let n=t;return n.setName(e),[e,n.buildExtraConfigColumn(o)]})),u=Object.assign(o,c);return u[a.Symbol.Columns]=c,u[a.Symbol.ExtraConfigColumns]=l,n&&(u[J.Symbol.ExtraConfigBuilder]=n),Object.assign(u,{enableRLS:()=>(u[J.Symbol.EnableRLS]=!0,u)})}const fn=Object.assign((e,t,n)=>Y(e,t,n,void 0),{withRLS:(e,t,n)=>{let r=Y(e,t,n,void 0);return r[q]=!0,r}});var pn=class{static[t]=`PgPrimaryKeyBuilder`;columns;name;constructor(e,t){this.columns=e,this.name=t}build(e){return new mn(e,this.columns,this.name)}},mn=class{constructor(e,t,n){this.table=e,this.columns=t,this.name=n,this.isNameExplicit=!!n}static[t]=`PgPrimaryKey`;columns;name;isNameExplicit;getName(){return this.name??`${this.table[J.Symbol.Name]}_${this.columns.map(e=>e.name).join(`_`)}_pk`}};function X(e,t){return ne(t)&&!l(e)&&!r(e,m)&&!r(e,ee)&&!r(e,s)&&!r(e,a)&&!r(e,c)?new m(e,t):e}const hn=(e,t)=>h`${e} = ${X(t,e)}`,gn=(e,t)=>h`${e} <> ${X(t,e)}`;function _n(...e){let t=e.filter(e=>e!==void 0);if(t.length!==0)return t.length===1?new p(t):new p([new d(`(`),h.join(t,new d(` and `)),new d(`)`)])}function vn(...e){let t=e.filter(e=>e!==void 0);if(t.length!==0)return t.length===1?new p(t):new p([new d(`(`),h.join(t,new d(` or `)),new d(`)`)])}function yn(e){return h`not ${e}`}const bn=(e,t)=>h`${e} > ${X(t,e)}`,xn=(e,t)=>h`${e} >= ${X(t,e)}`,Sn=(e,t)=>h`${e} < ${X(t,e)}`,Cn=(e,t)=>h`${e} <= ${X(t,e)}`;function wn(e,t){return Array.isArray(t)?t.length===0?h`false`:h`${e} in ${t.map(t=>X(t,e))}`:h`${e} in ${X(t,e)}`}function Tn(e,t){return Array.isArray(t)?t.length===0?h`true`:h`${e} not in ${t.map(t=>X(t,e))}`:h`${e} not in ${X(t,e)}`}function En(e){return h`${e} is null`}function Dn(e){return h`${e} is not null`}function On(e){return h`exists ${e}`}function kn(e){return h`not exists ${e}`}function An(e,t,n){return h`${e} between ${X(t,e)} and ${X(n,e)}`}function jn(e,t,n){return h`${e} not between ${X(t,e)} and ${X(n,e)}`}function Mn(e,t){return h`${e} like ${t}`}function Nn(e,t){return h`${e} not like ${t}`}function Pn(e,t){return h`${e} ilike ${t}`}function Fn(e,t){return h`${e} not ilike ${t}`}function In(e,t){if(Array.isArray(t)){if(t.length===0)throw Error(`arrayContains requires at least one value`);return h`${e} @> ${h`${X(t,e)}`}`}return h`${e} @> ${X(t,e)}`}function Ln(e,t){if(Array.isArray(t)){if(t.length===0)throw Error(`arrayContained requires at least one value`);return h`${e} <@ ${h`${X(t,e)}`}`}return h`${e} <@ ${X(t,e)}`}function Rn(e,t){if(Array.isArray(t)){if(t.length===0)throw Error(`arrayOverlaps requires at least one value`);return h`${e} && ${h`${X(t,e)}`}`}return h`${e} && ${X(t,e)}`}function zn(e){return h`${e} asc`}function Bn(e){return h`${e} desc`}var Vn=class{constructor(e,t,n){this.sourceTable=e,this.referencedTable=t,this.relationName=n,this.referencedTableName=t[a.Symbol.Name]}static[t]=`Relation`;referencedTableName;fieldName},Hn=class{constructor(e,t){this.table=e,this.config=t}static[t]=`Relations`},Z=class e extends Vn{constructor(e,t,n,r){super(e,t,n?.relationName),this.config=n,this.isNullable=r}static[t]=`One`;withFieldName(t){let n=new e(this.sourceTable,this.referencedTable,this.config,this.isNullable);return n.fieldName=t,n}},Un=class e extends Vn{constructor(e,t,n){super(e,t,n?.relationName),this.config=n}static[t]=`Many`;withFieldName(t){let n=new e(this.sourceTable,this.referencedTable,this.config);return n.fieldName=t,n}};function Wn(){return{and:_n,between:An,eq:hn,exists:On,gt:bn,gte:xn,ilike:Pn,inArray:wn,isNull:En,isNotNull:Dn,like:Mn,lt:Sn,lte:Cn,ne:gn,not:yn,notBetween:jn,notExists:kn,notLike:Nn,notIlike:Fn,notInArray:Tn,or:vn,sql:h}}function Gn(){return{sql:h,asc:zn,desc:Bn}}function Kn(e,t){Object.keys(e).length===1&&`default`in e&&!r(e.default,a)&&(e=e.default);let i={},o={},s={};for(let[c,l]of Object.entries(e))if(r(l,a)){let e=n(l),t=o[e];i[e]=c,s[c]={tsName:c,dbName:l[a.Symbol.Name],schema:l[a.Symbol.Schema],columns:l[a.Symbol.Columns],relations:t?.relations??{},primaryKey:t?.primaryKey??[]};for(let e of Object.values(l[a.Symbol.Columns]))e.primary&&s[c].primaryKey.push(e);let u=l[a.Symbol.ExtraConfigBuilder]?.(l[a.Symbol.ExtraConfigColumns]);if(u)for(let e of Object.values(u))r(e,pn)&&s[c].primaryKey.push(...e.columns)}else if(r(l,Hn)){let e=n(l.table),r=i[e],a=l.config(t(l.table));for(let[t,n]of Object.entries(a))if(r){let e=s[r];e.relations[t]=n}else e in o||(o[e]={relations:{}}),o[e].relations[t]=n}return{tables:s,tableNamesMap:i}}function qn(e){return function(t,n){return new Z(e,t,n,n?.fields.reduce((e,t)=>e&&t.notNull,!0)??!1)}}function Jn(e){return function(t,n){return new Un(e,t,n)}}function Yn(e,t,i){if(r(i,Z)&&i.config)return{fields:i.config.fields,references:i.config.references};let o=t[n(i.referencedTable)];if(!o)throw Error(`Table "${i.referencedTable[a.Symbol.Name]}" not found in schema`);let s=e[o];if(!s)throw Error(`Table "${o}" not found in schema`);let c=i.sourceTable,l=t[n(c)];if(!l)throw Error(`Table "${c[a.Symbol.Name]}" not found in schema`);let u=[];for(let e of Object.values(s.relations))(i.relationName&&i!==e&&e.relationName===i.relationName||!i.relationName&&e.referencedTable===i.sourceTable)&&u.push(e);if(u.length>1)throw i.relationName?Error(`There are multiple relations with name "${i.relationName}" in table "${o}"`):Error(`There are multiple relations between "${o}" and "${i.sourceTable[a.Symbol.Name]}". Please specify relation name`);if(u[0]&&r(u[0],Z)&&u[0].config)return{fields:u[0].config.references,references:u[0].config.fields};throw Error(`There is not enough information to infer relation "${l}.${i.fieldName}"`)}function Xn(e){return{one:qn(e),many:Jn(e)}}function Q(e,t,n,i,a=e=>e){let o={};for(let[c,l]of i.entries())if(l.isJson){let i=t.relations[l.tsKey],s=n[c],u=typeof s==`string`?JSON.parse(s):s;o[l.tsKey]=r(i,Z)?u&&Q(e,e[l.relationTableTsKey],u,l.selection,a):u.map(t=>Q(e,e[l.relationTableTsKey],t,l.selection,a))}else{let e=a(n[c]),t=l.field,i;i=r(t,s)?t:r(t,p)?t.decoder:t.sql.decoder,o[l.tsKey]=e===null?null:i.mapFromDriverValue(e)}return o}function $(e,t,n,i,a=e=>e){let o={};for(let[c,l]of i.entries())if(l.isJson){let i=t.relations[l.tsKey],s=r(i,Z),u=n[c],d=u;(d||Array.isArray(d))&&(d=typeof u==`string`?JSON.parse(u):u,d=s?d.flatMap(e=>Array.isArray(e)?e:Object.values(e)):d.map(e=>Array.isArray(e)?e:Object.values(e))),o[l.tsKey]=s?d&&$(e,e[l.relationTableTsKey],d,l.selection,a):(d??[]).map(t=>$(e,e[l.relationTableTsKey],t,l.selection,a))}else{let e=a(n[c]),t=l.field,i;i=r(t,s)?t:r(t,p)?t.decoder:t.sql.decoder,o[l.tsKey]=e===null?null:i.mapFromDriverValue(e)}return o}var Zn=class extends Error{static[t]=`DrizzleError`;constructor({message:e,cause:t}){super(e),this.name=`DrizzleError`,this.cause=t}},Qn=class e extends Error{constructor(t,n,r){super(`Failed query: ${t}
|
|
3
|
+
params: ${n}`),this.query=t,this.params=n,this.cause=r,Error.captureStackTrace(this,e),r&&(this.cause=r)}static[t]=`DrizzleQueryError`},$n=class extends Zn{static[t]=`TransactionRollbackError`;constructor(){super({message:`Rollback`})}},er=class{static[t]=`TypedQueryBuilder`;getSelectedFields(){return this._.selectedFields}};export{sn as $,k as $n,tt as $t,Mn as A,Ee as An,Et as At,vn as B,V as Bn,mt as Bt,On as C,Pe as Cn,Nt as Ct,wn as D,Te as Dn,kt as Dt,Pn as E,je as En,At as Et,jn as F,U as Fn,bt as Ft,J as G,j as Gn,at as Gt,pn as H,I as Hn,ft as Ht,kn as I,H as In,yt as It,ln as J,F as Jn,it as Jt,fn as K,P as Kn,lt as Kt,Fn as L,be as Ln,St as Lt,Cn as M,Se as Mn,Tt as Mt,gn as N,xe as Nn,wt as Nt,Dn as O,we as On,jt as Ot,yn as P,Ce as Pn,G as Pt,an as Q,E as Qn,nt as Qt,Tn as R,B as Rn,xt as Rt,hn as S,Me as Sn,Lt as St,xn as T,ke as Tn,Pt as Tt,q as U,R as Un,dt as Ut,mn as V,L as Vn,pt as Vt,K as W,M as Wn,ht as Wt,un as X,w as Xn,ot as Xt,cn as Y,T as Yn,st as Yt,on as Z,D as Zn,ut as Zt,_n as _,Be as _n,y as _r,zt as _t,Un as a,Ye as an,me as ar,en as at,Rn as b,Le as bn,ie as br,It as bt,Xn as c,Ze as cn,ge as cr,Zt as ct,Gn as d,Ke as dn,de as dr,Jt as dt,rt as en,O as er,nn as et,Q as f,He as fn,pe as fr,Ht as ft,Bn as g,Re as gn,ue as gr,Gt as gt,zn as h,ze as hn,v as hr,Ut as ht,$n as i,Xe as in,ve as ir,Qt as it,Sn as j,Oe as jn,Ot as jt,En as k,De as kn,Dt as kt,Kn as l,Ge as ln,fe as lr,qt as lt,Yn as m,Ue as mn,ce as mr,Wt as mt,Zn as n,Qe as nn,C as nr,rn as nt,Z as o,qe as on,S as or,Xt as ot,$ as p,Ve as pn,x as pr,Vt as pt,Y as q,N as qn,ct as qt,Qn as r,et as rn,ye as rr,$t as rt,Hn as s,Je as sn,he as sr,Yt as st,er as t,$e as tn,A as tr,tn as tt,Wn as u,We as un,_e as ur,Kt as ut,Ln as v,Ie as vn,b as vr,Rt as vt,bn as w,Ae as wn,Mt as wt,An as x,Ne as xn,re as xr,Ft as xt,In as y,Fe as yn,oe as yr,Bt as yt,Nn as z,z as zn,Ct as zt};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{F as e,G as t,H as n,K as r,R as i,V as a,W as o,a as s,c,d as l,h as u,m as d,r as f,t as p,u as m,z as h}from"./sql-D-eKV1Dn.mjs";import{S as g,_,_r as v,a as y,ar as b,cr as x,d as S,f as C,fr as w,gr as T,hr as E,i as D,ir as O,lr as k,m as A,mr as j,n as M,o as ee,pr as N,r as P,rr as F,sr as te,t as ne,u as re,vr as I,yr as ie}from"./query-builder-V8-LDhvA.mjs";import{a as ae,c as L,i as oe,l as se,n as ce,o as le,r as ue,s as de,t as fe}from"./cache-3oO07miM.mjs";import{a as pe,i as R,t as z}from"./utils-CyoeCJlf.mjs";var B=class extends o{static[t]=`SQLiteColumn`;table;constructor(e,t){super(e,t),this.table=e}},V=class extends O{constructor(e,t,n,r){super(),this.table=e,this.session=t,this.dialect=n,this.config={table:e,withList:r}}static[t]=`SQLiteDelete`;config;where(e){return this.config.where=e,this}orderBy(...e){if(typeof e[0]==`function`){let t=e[0](new Proxy(this.config.table[i.Symbol.Columns],new F({sqlAliasedBehavior:`alias`,sqlBehavior:`sql`}))),n=Array.isArray(t)?t:[t];this.config.orderBy=n}else{let t=e;this.config.orderBy=t}return this}limit(e){return this.config.limit=e,this}returning(e=this.table[R.Symbol.Columns]){return this.config.returning=N(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,void 0,{type:`delete`,tables:z(this.config.table)})}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}},H=class extends s{static[t]=`SQLiteViewBase`},U=class{static[t]=`SQLiteDialect`;casing;constructor(e){this.casing=new ie(e?.casing)}escapeName(e){return`"${e}"`}escapeParam(e){return`?`}escapeString(e){return`'${e.replace(/'/g,`''`)}'`}buildWithCTE(e){if(!e?.length)return;let t=[m`with `];for(let[n,r]of e.entries())t.push(m`${m.identifier(r._.alias)} as (${r._.sql})`),n<e.length-1&&t.push(m`, `);return t.push(m` `),m.join(t)}buildDeleteQuery({table:e,where:t,returning:n,withList:r,limit:i,orderBy:a}){let o=this.buildWithCTE(r),s=n?m` returning ${this.buildSelection(n,{isSingleTable:!0})}`:void 0;return m`${o}delete from ${e}${t?m` where ${t}`:void 0}${s}${this.buildOrderBy(a)}${this.buildLimit(i)}`}buildUpdateSet(e,t){let n=e[i.Symbol.Columns],a=Object.keys(n).filter(e=>t[e]!==void 0||n[e]?.onUpdateFn!==void 0),o=a.length;return m.join(a.flatMap((e,i)=>{let a=n[e],s=a.onUpdateFn?.(),c=t[e]??(r(s,f)?s:m.param(s,a)),l=m`${m.identifier(this.casing.getColumnCasing(a))} = ${c}`;return i<o-1?[l,m.raw(`, `)]:[l]}))}buildUpdateQuery({table:e,set:t,where:n,returning:r,withList:i,joins:a,from:o,limit:s,orderBy:c}){let l=this.buildWithCTE(i),u=this.buildUpdateSet(e,t),d=o&&m.join([m.raw(` from `),this.buildFromTable(o)]),f=this.buildJoins(a),p=r?m` returning ${this.buildSelection(r,{isSingleTable:!0})}`:void 0;return m`${l}update ${e} set ${u}${d}${f}${n?m` where ${n}`:void 0}${p}${this.buildOrderBy(c)}${this.buildLimit(s)}`}buildSelection(e,{isSingleTable:t=!1}={}){let n=e.length,i=e.flatMap(({field:e},i)=>{let a=[];if(r(e,f.Aliased)&&e.isSelectionField)a.push(m.identifier(e.fieldAlias));else if(r(e,f.Aliased)||r(e,f)){let n=r(e,f.Aliased)?e.sql:e;t?a.push(new f(n.queryChunks.map(e=>r(e,o)?m.identifier(this.casing.getColumnCasing(e)):e))):a.push(n),r(e,f.Aliased)&&a.push(m` as ${m.identifier(e.fieldAlias)}`)}else if(r(e,o))e.columnType===`SQLiteNumericBigInt`?t?a.push(e.isAlias?m`cast(${m.identifier(this.casing.getColumnCasing(T(e)))} as text) as ${e}`:m`cast(${m.identifier(this.casing.getColumnCasing(e))} as text)`):a.push(e.isAlias?m`cast(${T(e)} as text) as ${e}`:m`cast(${e} as text)`):t?a.push(e.isAlias?m`${m.identifier(this.casing.getColumnCasing(T(e)))} as ${e}`:m.identifier(this.casing.getColumnCasing(e))):a.push(e.isAlias?m`${T(e)} as ${e}`:e);else if(r(e,d)){let t=Object.entries(e._.selectedFields);if(t.length===1){let n=t[0][1],i=r(n,f)?n.decoder:r(n,o)?{mapFromDriverValue:e=>n.mapFromDriverValue(e)}:n.sql.decoder;i&&(e._.sql.decoder=i)}a.push(e)}return i<n-1&&a.push(m`, `),a});return m.join(i)}buildJoins(e){if(!e||e.length===0)return;let t=[];if(e)for(let[n,i]of e.entries()){n===0&&t.push(m` `);let a=i.table,o=i.on?m` on ${i.on}`:void 0;if(r(a,R)){let e=a[R.Symbol.Name],n=a[R.Symbol.Schema],r=a[R.Symbol.OriginalName],s=e===r?void 0:i.alias;t.push(m`${m.raw(i.joinType)} join ${n?m`${m.identifier(n)}.`:void 0}${m.identifier(r)}${s&&m` ${m.identifier(s)}`}${o}`)}else t.push(m`${m.raw(i.joinType)} join ${a}${o}`);n<e.length-1&&t.push(m` `)}return m.join(t)}buildLimit(e){return typeof e==`object`||typeof e==`number`&&e>=0?m` limit ${e}`:void 0}buildOrderBy(e){let t=[];if(e)for(let[n,r]of e.entries())t.push(r),n<e.length-1&&t.push(m`, `);return t.length>0?m` order by ${m.join(t)}`:void 0}buildFromTable(e){return r(e,i)&&e[i.Symbol.IsAlias]?m`${m`${m.identifier(e[i.Symbol.Schema]??``)}.`.if(e[i.Symbol.Schema])}${m.identifier(e[i.Symbol.OriginalName])} ${m.identifier(e[i.Symbol.Name])}`:e}buildSelectQuery({withList:e,fields:t,fieldsFlat:n,where:s,having:c,table:u,joins:p,orderBy:h,groupBy:g,limit:_,offset:v,distinct:y,setOperators:b}){let x=n??N(t);for(let e of x)if(r(e.field,o)&&a(e.field.table)!==(r(u,d)?u._.alias:r(u,H)?u[l].name:r(u,f)?void 0:a(u))&&!(e=>p?.some(({alias:t})=>t===(e[i.Symbol.IsAlias]?a(e):e[i.Symbol.BaseName])))(e.field.table)){let t=a(e.field.table);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 S=!p||p.length===0,C=this.buildWithCTE(e),w=y?m` distinct`:void 0,T=this.buildSelection(x,{isSingleTable:S}),E=this.buildFromTable(u),D=this.buildJoins(p),O=s?m` where ${s}`:void 0,k=c?m` having ${c}`:void 0,A=[];if(g)for(let[e,t]of g.entries())A.push(t),e<g.length-1&&A.push(m`, `);let j=m`${C}select${w} ${T} from ${E}${D}${O}${A.length>0?m` group by ${m.join(A)}`:void 0}${k}${this.buildOrderBy(h)}${this.buildLimit(_)}${v?m` offset ${v}`:void 0}`;return b.length>0?this.buildSetOperations(j,b):j}buildSetOperations(e,t){let[n,...r]=t;if(!n)throw Error(`Cannot pass undefined values to any set operator`);return r.length===0?this.buildSetOperationQuery({leftSelect:e,setOperator:n}):this.buildSetOperations(this.buildSetOperationQuery({leftSelect:e,setOperator:n}),r)}buildSetOperationQuery({leftSelect:e,setOperator:{type:t,isAll:n,rightSelect:i,limit:a,orderBy:o,offset:s}}){let c=m`${e.getSQL()} `,l=m`${i.getSQL()}`,u;if(o&&o.length>0){let e=[];for(let t of o)if(r(t,B))e.push(m.identifier(t.name));else if(r(t,f)){for(let e=0;e<t.queryChunks.length;e++){let n=t.queryChunks[e];r(n,B)&&(t.queryChunks[e]=m.identifier(this.casing.getColumnCasing(n)))}e.push(m`${t}`)}else e.push(m`${t}`);u=m` order by ${m.join(e,m`, `)}`}let d=typeof a==`object`||typeof a==`number`&&a>=0?m` limit ${a}`:void 0,p=m.raw(`${t} ${n?`all `:``}`),h=s?m` offset ${s}`:void 0;return m`${c}${p}${l}${u}${d}${h}`}buildInsertQuery({table:e,values:t,onConflict:n,returning:a,withList:o,select:s}){let c=[],l=e[i.Symbol.Columns],u=Object.entries(l).filter(([e,t])=>!t.shouldDisableInsert()),d=u.map(([,e])=>m.identifier(this.casing.getColumnCasing(e)));if(s){let e=t;r(e,f)?c.push(e):c.push(e.getSQL())}else{let e=t;c.push(m.raw(`values `));for(let[t,n]of e.entries()){let i=[];for(let[e,t]of u){let a=n[e];if(a===void 0||r(a,p)&&a.value===void 0){let e;if(t.default!==null&&t.default!==void 0)e=r(t.default,f)?t.default:m.param(t.default,t);else if(t.defaultFn!==void 0){let n=t.defaultFn();e=r(n,f)?n:m.param(n,t)}else if(!t.default&&t.onUpdateFn!==void 0){let n=t.onUpdateFn();e=r(n,f)?n:m.param(n,t)}else e=m`null`;i.push(e)}else i.push(a)}c.push(i),t<e.length-1&&c.push(m`, `)}}let h=this.buildWithCTE(o),g=m.join(c),_=a?m` returning ${this.buildSelection(a,{isSingleTable:!0})}`:void 0;return m`${h}insert into ${e} ${d} ${g}${n?.length?m.join(n):void 0}${_}`}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:a,tableConfig:s,queryConfig:c,tableAlias:l,nestedQueryRelation:u,joinOn:p}){let h=[],b,x,C=[],w,T=[];if(c===!0)h=Object.entries(s.columns).map(([e,t])=>({dbKey:t.name,tsKey:e,field:E(t,l),relationTableTsKey:void 0,isJson:!1,selection:[]}));else{let a=Object.fromEntries(Object.entries(s.columns).map(([e,t])=>[e,E(t,l)]));if(c.where){let e=typeof c.where==`function`?c.where(a,re()):c.where;w=e&&I(e,l)}let u=[],d=[];if(c.columns){let e=!1;for(let[t,n]of Object.entries(c.columns))n!==void 0&&t in s.columns&&(!e&&n===!0&&(e=!0),d.push(t));d.length>0&&(d=e?d.filter(e=>c.columns?.[e]===!0):Object.keys(s.columns).filter(e=>!d.includes(e)))}else d=Object.keys(s.columns);for(let e of d){let t=s.columns[e];u.push({tsKey:e,value:t})}let p=[];c.with&&(p=Object.entries(c.with).filter(e=>!!e[1]).map(([e,t])=>({tsKey:e,queryConfig:t,relation:s.relations[e]})));let y;if(c.extras){y=typeof c.extras==`function`?c.extras(a,{sql:m}):c.extras;for(let[e,t]of Object.entries(y))u.push({tsKey:e,value:v(t,l)})}for(let{tsKey:e,value:t}of u)h.push({dbKey:r(t,f.Aliased)?t.fieldAlias:s.columns[e].name,tsKey:e,field:r(t,o)?E(t,l):t,relationTableTsKey:void 0,isJson:!1,selection:[]});let T=typeof c.orderBy==`function`?c.orderBy(a,S()):c.orderBy??[];Array.isArray(T)||(T=[T]),C=T.map(e=>r(e,o)?E(e,l):I(e,l)),b=c.limit,x=c.offset;for(let{tsKey:a,queryConfig:o,relation:s}of p){let c=A(t,i,s),u=i[n(s.referencedTable)],d=`${l}_${a}`,f=_(...c.fields.map((e,t)=>g(E(c.references[t],d),E(e,l)))),p=this._buildRelationalQuery({fullSchema:e,schema:t,tableNamesMap:i,table:e[u],tableConfig:t[u],queryConfig:r(s,ee)?o===!0?{limit:1}:{...o,limit:1}:o,tableAlias:d,joinOn:f,nestedQueryRelation:s}),v=m`(${p.sql})`.as(a);h.push({dbKey:a,tsKey:a,field:v,relationTableTsKey:u,isJson:!0,selection:p.selection})}}if(h.length===0)throw new M({message:`No fields selected for table "${s.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.`});let D;if(w=_(p,w),u){let e=m`json_array(${m.join(h.map(({field:e})=>r(e,B)?m.identifier(this.casing.getColumnCasing(e)):r(e,f.Aliased)?e.sql:e),m`, `)})`;r(u,y)&&(e=m`coalesce(json_group_array(${e}), json_array())`);let t=[{dbKey:`data`,tsKey:`data`,field:e.as(`data`),isJson:!0,relationTableTsKey:s.tsName,selection:h}];b!==void 0||x!==void 0||C.length>0?(D=this.buildSelectQuery({table:j(a,l),fields:{},fieldsFlat:[{path:[],field:m.raw(`*`)}],where:w,limit:b,offset:x,orderBy:C,setOperators:[]}),w=void 0,b=void 0,x=void 0,C=void 0):D=j(a,l),D=this.buildSelectQuery({table:r(D,R)?D:new d(D,{},l),fields:{},fieldsFlat:t.map(({field:e})=>({path:[],field:r(e,o)?E(e,l):e})),joins:T,where:w,limit:b,offset:x,orderBy:C,setOperators:[]})}else D=this.buildSelectQuery({table:j(a,l),fields:{},fieldsFlat:h.map(({field:e})=>({path:[],field:r(e,o)?E(e,l):e})),joins:T,where:w,limit:b,offset:x,orderBy:C,setOperators:[]});return{tableTsKey:s.tsName,sql:D,selection:h}}nestedSelectionerror(){throw new M({message:`Views with nested selections are not supported by the relational query builder`})}buildRqbColumn(e,t,n){if(r(t,o)){let r=m`${e}.${m.identifier(this.casing.getColumnCasing(t))}`;switch(t.columnType){case`SQLiteBigInt`:case`SQLiteBlobJson`:case`SQLiteBlobBuffer`:return m`hex(${r}) as ${m.identifier(n)}`;case`SQLiteNumeric`:case`SQLiteNumericNumber`:case`SQLiteNumericBigInt`:return m`cast(${r} as text) as ${m.identifier(n)}`;case`SQLiteCustomColumn`:return m`${t.jsonSelectIdentifier(r,m)} as ${m.identifier(n)}`;default:return m`${r} as ${m.identifier(n)}`}}return m`${e}.${r(t,f.Aliased)?m.identifier(t.fieldAlias):c(t)?m.identifier(n):this.nestedSelectionerror()} as ${m.identifier(n)}`}unwrapAllColumns=(e,t)=>m.join(Object.entries(e[h]).map(([n,r])=>(t.push({key:n,field:r}),this.buildRqbColumn(e,r,n))),m`, `);getSelectedTableColumns=(e,t)=>{let n=[],r=e[h],i=Object.entries(t),a;for(let[e,t]of i)if(t!==void 0&&(a||=t,t)){let t=r[e];n.push({column:t,tsName:e})}if(a===!1)for(let[e,i]of Object.entries(r))t[e]!==!1&&n.push({column:i,tsName:e});return n};buildColumns=(e,t,n)=>n?.columns?(()=>{let r=[],i=this.getSelectedTableColumns(e,n?.columns);for(let{column:n,tsName:a}of i)r.push(this.buildRqbColumn(e,n,a)),t.push({key:a,field:n});return r.length?m.join(r,m`, `):void 0})():this.unwrapAllColumns(e,t);buildRelationalQuery({schema:e,table:t,tableConfig:n,queryConfig:i,relationWhere:a,mode:o,isNested:s,errorPath:c,depth:l,throughJoin:u,jsonb:d}){let f=[],p=o===`first`,h=i===!0?void 0:i,g=c??``,v=l??0;v||(t=j(t,`d${v}`));let y=p?1:h?.limit,b=h?.offset,x=this.buildColumns(t,f,h),S=h?.where&&a?_(L(t,h.where,n.relations,e,this.casing),a):h?.where?L(t,h.where,n.relations,e,this.casing):a,C=h?.orderBy?se(t,h.orderBy):void 0,w=h?.extras?le(t,h.extras):void 0;w&&f.push(...w.selection);let T=h?(()=>{let{with:i}=h;if(!i)return;let a=Object.entries(i).filter(([e,t])=>t);if(a.length)return m.join(a.map(([i,a])=>{let o=n.relations[i],c=r(o,ue),l=j(o.targetTable,`d${v+1}`),u=o.throughTable?j(o.throughTable,`tr${v}`):void 0,{filter:p,joinCondition:h}=de(this.casing,o,t,l,u),_=u?m` inner join ${oe(u)} on ${h}`:void 0,y=this.buildRelationalQuery({table:l,mode:c?`first`:`many`,schema:e,queryConfig:a,tableConfig:e[o.targetTableName],relationWhere:p,isNested:!0,errorPath:`${g.length?`${g}.`:``}${i}`,depth:v+1,throughJoin:_,jsonb:d});f.push({field:l,key:i,selection:y.selection,isArray:!c,isOptional:(o.optional??!1)||a!==!0&&!!a.where});let b=m.join(y.selection.map(e=>m`${m.raw(this.escapeString(e.key))}, ${e.selection?m`${d}(${m.identifier(e.key)})`:m.identifier(e.key)}`),m`, `),x=s?d:m`json`;return c?m`(select ${x}_object(${b}) as ${m.identifier(`r`)} from (${y.sql}) as ${m.identifier(`t`)}) as ${m.identifier(i)}`:m`coalesce((select ${x}_group_array(json_object(${b})) as ${m.identifier(`r`)} from (${y.sql}) as ${m.identifier(`t`)}), ${d}_array()) as ${m.identifier(i)}`}),m`, `)})():void 0,E=[x,w?.sql,T].filter(e=>e!==void 0);if(!E.length)throw new M({message:`No fields selected for table "${n.name}"${g?` ("${g}")`:``}`});return{sql:m`select ${m.join(E,m`, `)} from ${oe(t)}${u}${m` where ${S}`.if(S)}${m` order by ${C}`.if(C)}${m` limit ${y}`.if(y!==void 0)}${m` offset ${b}`.if(b!==void 0)}`,selection:f}}},W=class extends U{static[t]=`SQLiteSyncDialect`;migrate(e,t,n){let r=n===void 0||typeof n==`string`?`__drizzle_migrations`:n.migrationsTable??`__drizzle_migrations`,i=m`
|
|
3
|
+
CREATE TABLE IF NOT EXISTS ${m.identifier(r)} (
|
|
4
|
+
id SERIAL PRIMARY KEY,
|
|
5
|
+
hash text NOT NULL,
|
|
6
|
+
created_at numeric
|
|
7
|
+
)
|
|
8
|
+
`;t.run(i);let a=t.values(m`SELECT id, hash, created_at FROM ${m.identifier(r)} ORDER BY created_at DESC LIMIT 1`);if(typeof n==`object`&&n.init){if(a.length)return{exitCode:`databaseMigrations`};if(e.length>1)return{exitCode:`localMigrations`};let[n]=e;if(!n)return;t.run(m`insert into ${m.identifier(r)} ("hash", "created_at") values(${n.hash}, ${n.folderMillis})`);return}let o=a[0]??void 0;t.run(m`BEGIN`);try{for(let n of e)if(!o||Number(o[2])<n.folderMillis){for(let e of n.sql)t.run(m.raw(e));t.run(m`INSERT INTO ${m.identifier(r)} ("hash", "created_at") VALUES(${n.hash}, ${n.folderMillis})`)}t.run(m`COMMIT`)}catch(e){throw t.run(m`ROLLBACK`),e}}},me=class extends U{static[t]=`SQLiteAsyncDialect`;async migrate(e,t,n){let r=n===void 0||typeof n==`string`?`__drizzle_migrations`:n.migrationsTable??`__drizzle_migrations`,i=m`
|
|
9
|
+
CREATE TABLE IF NOT EXISTS ${m.identifier(r)} (
|
|
10
|
+
id INTEGER PRIMARY KEY,
|
|
11
|
+
hash text NOT NULL,
|
|
12
|
+
created_at numeric
|
|
13
|
+
)
|
|
14
|
+
`;await t.run(i);let a=await t.values(m`SELECT id, hash, created_at FROM ${m.identifier(r)} ORDER BY created_at DESC LIMIT 1`);if(typeof n==`object`&&n.init){if(a.length)return{exitCode:`databaseMigrations`};if(e.length>1)return{exitCode:`localMigrations`};let[n]=e;if(!n)return;await t.run(m`insert into ${m.identifier(r)} ("hash", "created_at") values(${n.hash}, ${n.folderMillis})`);return}let o=a[0]??void 0;await t.transaction(async t=>{for(let n of e)if(!o||Number(o[2])<n.folderMillis){for(let e of n.sql)await t.run(m.raw(e));await t.run(m`INSERT INTO ${m.identifier(r)} ("hash", "created_at") VALUES(${n.hash}, ${n.folderMillis})`)}})}},G=class{static[t]=`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=!!this.fields,n;return n=this.fields?this.fields:r(e,d)?Object.fromEntries(Object.keys(e._.selectedFields).map(t=>[t,e[t]])):r(e,H)?e[l].selectedFields:r(e,f)?{}:te(e),new K({table:e,fields:n,isPartialSelect:t,session:this.session,dialect:this.dialect,withList:this.withList,distinct:this.distinct})}},he=class extends ne{static[t]=`SQLiteSelectQueryBuilder`;_;config;joinsNotNullableMap;tableName;isPartialSelect;session;dialect;cacheConfig=void 0;usedTables=new Set;constructor({table:e,fields:t,isPartialSelect:n,session:r,dialect:i,withList:a,distinct:o}){super(),this.config={withList:a,table:e,fields:{...t},distinct:o,setOperators:[]},this.isPartialSelect=n,this.session=r,this.dialect=i,this._={selectedFields:t,config:this.config},this.tableName=x(e),this.joinsNotNullableMap=typeof this.tableName==`string`?{[this.tableName]:!0}:{};for(let t of z(e))this.usedTables.add(t)}getUsedTables(){return[...this.usedTables]}createJoin(e){return(t,n)=>{let a=this.tableName,o=x(t);for(let e of z(t))this.usedTables.add(e);if(typeof o==`string`&&this.config.joins?.some(e=>e.alias===o))throw Error(`Alias "${o}" is already used in this query`);if(!this.isPartialSelect&&(Object.keys(this.joinsNotNullableMap).length===1&&typeof a==`string`&&(this.config.fields={[a]:this.config.fields}),typeof o==`string`&&!r(t,f))){let e=r(t,d)?t._.selectedFields:r(t,s)?t[l].selectedFields:t[i.Symbol.Columns];this.config.fields[o]=e}if(typeof n==`function`&&(n=n(new Proxy(this.config.fields,new F({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})))),this.config.joins||(this.config.joins=[]),this.config.joins.push({on:n,table:t,joinType:e,alias:o}),typeof o==`string`)switch(e){case`left`:this.joinsNotNullableMap[o]=!1;break;case`right`:this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[o]=!0;break;case`cross`:case`inner`:this.joinsNotNullableMap[o]=!0;break;case`full`:this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[o]=!1;break}return this}}leftJoin=this.createJoin(`left`);rightJoin=this.createJoin(`right`);innerJoin=this.createJoin(`inner`);fullJoin=this.createJoin(`full`);crossJoin=this.createJoin(`cross`);createSetOperator(e,t){return n=>{let r=typeof n==`function`?n(ge()):n;if(!k(this.getSelectedFields(),r.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:r}),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 typeof e==`function`&&(e=e(new Proxy(this.config.fields,new F({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})))),this.config.where=e,this}having(e){return typeof e==`function`&&(e=e(new Proxy(this.config.fields,new F({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})))),this.config.having=e,this}groupBy(...e){if(typeof e[0]==`function`){let t=e[0](new Proxy(this.config.fields,new F({sqlAliasedBehavior:`alias`,sqlBehavior:`sql`})));this.config.groupBy=Array.isArray(t)?t:[t]}else this.config.groupBy=e;return this}orderBy(...e){if(typeof e[0]==`function`){let t=e[0](new Proxy(this.config.fields,new F({sqlAliasedBehavior:`alias`,sqlBehavior:`sql`}))),n=Array.isArray(t)?t:[t];this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=n:this.config.orderBy=n}else{let t=e;this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=t:this.config.orderBy=t}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){let t=[];if(t.push(...z(this.config.table)),this.config.joins)for(let e of this.config.joins)t.push(...z(e.table));return new Proxy(new d(this.getSQL(),this.config.fields,e,!1,[...new Set(t)]),new F({alias:e,sqlAliasedBehavior:`alias`,sqlBehavior:`error`}))}getSelectedFields(){return new Proxy(this.config.fields,new F({alias:this.tableName,sqlAliasedBehavior:`alias`,sqlBehavior:`error`}))}$dynamic(){return this}},K=class extends he{static[t]=`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=N(this.config.fields),n=this.session[e?`prepareOneTimeQuery`:`prepareQuery`](this.dialect.sqlToQuery(this.getSQL()),t,`all`,!0,void 0,{type:`select`,tables:[...this.usedTables]},this.cacheConfig);return n.joinsNotNullableMap=this.joinsNotNullableMap,n}$withCache(e){return this.cacheConfig=e===void 0?{config:{},enable:!0,autoInvalidate:!0}:e===!1?{enable:!1}:{enable:!0,autoInvalidate:!0,...e},this}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()}};b(K,[O]);function q(e,t){return(n,r,...i)=>{let a=[r,...i].map(n=>({type:e,isAll:t,rightSelect:n}));for(let e of a)if(!k(n.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 n.addSetOperators(a)}}const ge=()=>({union:_e,unionAll:ve,intersect:ye,except:be}),_e=q(`union`,!1),ve=q(`union`,!0),ye=q(`intersect`,!1),be=q(`except`,!1);var J=class{static[t]=`SQLiteQueryBuilder`;dialect;dialectConfig;constructor(e){this.dialect=r(e,U)?e:void 0,this.dialectConfig=r(e,U)?void 0:e}$with=(e,t)=>{let n=this;return{as:r=>(typeof r==`function`&&(r=r(n)),new Proxy(new u(r.getSQL(),t??(`getSelectedFields`in r?r.getSelectedFields()??{}:{}),e,!0),new F({alias:e,sqlAliasedBehavior:`alias`,sqlBehavior:`error`})))}};with(...e){let t=this;function n(n){return new G({fields:n??void 0,session:void 0,dialect:t.getDialect(),withList:e})}function r(n){return new G({fields:n??void 0,session:void 0,dialect:t.getDialect(),withList:e,distinct:!0})}return{select:n,selectDistinct:r}}select(e){return new G({fields:e??void 0,session:void 0,dialect:this.getDialect()})}selectDistinct(e){return new G({fields:e??void 0,session:void 0,dialect:this.getDialect(),distinct:!0})}getDialect(){return this.dialect||=new W(this.dialectConfig),this.dialect}},Y=class{constructor(e,t,n,r){this.table=e,this.session=t,this.dialect=n,this.withList=r}static[t]=`SQLiteInsertBuilder`;values(e){if(e=Array.isArray(e)?e:[e],e.length===0)throw Error(`values() must be called with at least one value`);let t=e.map(e=>{let t={},n=this.table[i.Symbol.Columns];for(let i of Object.keys(e)){let a=e[i];t[i]=r(a,f)?a:new p(a,n[i])}return t});return new xe(this.table,t,this.session,this.dialect,this.withList)}select(e){let t=typeof e==`function`?e(new J):e;if(!r(t,f)&&!k(this.table[h],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 xe(this.table,t,this.session,this.dialect,this.withList,!0)}},xe=class extends O{constructor(e,t,n,r,i,a){super(),this.session=n,this.dialect=r,this.config={table:e,values:t,withList:i,select:a}}static[t]=`SQLiteInsert`;config;returning(e=this.config.table[R.Symbol.Columns]){return this.config.returning=N(e),this}onConflictDoNothing(e={}){if(this.config.onConflict||(this.config.onConflict=[]),e.target===void 0)this.config.onConflict.push(m` on conflict do nothing`);else{let t=Array.isArray(e.target)?m`${e.target}`:m`${[e.target]}`,n=e.where?m` where ${e.where}`:m``;this.config.onConflict.push(m` on conflict ${t} do nothing${n}`)}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.`);this.config.onConflict||(this.config.onConflict=[]);let t=e.where?m` where ${e.where}`:void 0,n=e.targetWhere?m` where ${e.targetWhere}`:void 0,r=e.setWhere?m` where ${e.setWhere}`:void 0,i=Array.isArray(e.target)?m`${e.target}`:m`${[e.target]}`,a=this.dialect.buildUpdateSet(this.config.table,w(this.config.table,e.set));return this.config.onConflict.push(m` on conflict ${i}${n} do update set ${a}${t}${r}`),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,void 0,{type:`insert`,tables:z(this.config.table)})}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}},Se=class{constructor(e,t,n,r){this.table=e,this.session=t,this.dialect=n,this.withList=r}static[t]=`SQLiteUpdateBuilder`;set(e){return new Ce(this.table,w(this.table,e),this.session,this.dialect,this.withList)}},Ce=class extends O{constructor(e,t,n,r,i){super(),this.session=n,this.dialect=r,this.config={set:t,table:e,withList:i,joins:[]}}static[t]=`SQLiteUpdate`;config;from(e){return this.config.from=e,this}createJoin(e){return((t,n)=>{let a=x(t);if(typeof a==`string`&&this.config.joins.some(e=>e.alias===a))throw Error(`Alias "${a}" is already used in this query`);if(typeof n==`function`){let e=this.config.from?r(t,R)?t[i.Symbol.Columns]:r(t,d)?t._.selectedFields:r(t,H)?t[l].selectedFields:void 0:void 0;n=n(new Proxy(this.config.table[i.Symbol.Columns],new F({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})),e&&new Proxy(e,new F({sqlAliasedBehavior:`sql`,sqlBehavior:`sql`})))}return this.config.joins.push({on:n,table:t,joinType:e,alias:a}),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(typeof e[0]==`function`){let t=e[0](new Proxy(this.config.table[i.Symbol.Columns],new F({sqlAliasedBehavior:`alias`,sqlBehavior:`sql`}))),n=Array.isArray(t)?t:[t];this.config.orderBy=n}else{let t=e;this.config.orderBy=t}return this}limit(e){return this.config.limit=e,this}returning(e=this.config.table[R.Symbol.Columns]){return this.config.returning=N(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,void 0,{type:`insert`,tables:z(this.config.table)})}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}},we=class{constructor(e,t,n,r,i,a,o,s){this.mode=e,this.fullSchema=t,this.schema=n,this.tableNamesMap=r,this.table=i,this.tableConfig=a,this.dialect=o,this.session=s}static[t]=`SQLiteAsyncRelationalQueryBuilder`;findMany(e){return this.mode===`sync`?new Te(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e||{},`many`):new X(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e||{},`many`)}findFirst(e){return this.mode===`sync`?new Te(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e?{...e,limit:1}:{limit:1},`first`):new X(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e?{...e,limit:1}:{limit:1},`first`)}},X=class extends O{constructor(e,t,n,r,i,a,o,s,c){super(),this.fullSchema=e,this.schema=t,this.tableNamesMap=n,this.table=r,this.tableConfig=i,this.dialect=a,this.session=o,this.config=s,this.mode=c}static[t]=`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:n}=this._toSQL();return this.session[e?`prepareOneTimeQuery`:`prepareQuery`](n,void 0,this.mode===`first`?`get`:`all`,!0,(e,n)=>{let r=e.map(e=>C(this.schema,this.tableConfig,e,t.selection,n));return this.mode===`first`?r[0]:r})}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});return{query:e,builtQuery:this.dialect.sqlToQuery(e.sql)}}toSQL(){return this._toSQL().builtQuery}executeRaw(){return this.mode===`first`?this._prepare(!1).get():this._prepare(!1).all()}async execute(){return this.executeRaw()}},Te=class extends X{static[t]=`SQLiteSyncRelationalQuery`;sync(){return this.executeRaw()}},Ee=class e extends f{constructor(t){super(e.buildEmbeddedCount(t.source,t.filters).queryChunks),this.params=t,this.session=t.session,this.sql=e.buildCount(t.source,t.filters)}sql;static[t]=`SQLiteCountBuilderAsync`;[Symbol.toStringTag]=`SQLiteCountBuilderAsync`;session;static buildEmbeddedCount(e,t){return m`(select count(*) from ${e}${m.raw(` where `).if(t)}${t})`}static buildCount(e,t){return m`select count(*) from ${e}${m.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})}},De=class{constructor(e,t,n,r,i,a,o,s){this.mode=e,this.schema=t,this.table=n,this.tableConfig=r,this.dialect=i,this.session=a,this.rowMode=o,this.forbidJsonb=s}static[t]=`SQLiteAsyncRelationalQueryBuilderV2`;findMany(e){return this.mode===`sync`?new Oe(this.schema,this.table,this.tableConfig,this.dialect,this.session,e??!0,`many`,this.rowMode,this.forbidJsonb):new Z(this.schema,this.table,this.tableConfig,this.dialect,this.session,e??!0,`many`,this.rowMode,this.forbidJsonb)}findFirst(e){return this.mode===`sync`?new Oe(this.schema,this.table,this.tableConfig,this.dialect,this.session,e??!0,`first`,this.rowMode,this.forbidJsonb):new Z(this.schema,this.table,this.tableConfig,this.dialect,this.session,e??!0,`first`,this.rowMode,this.forbidJsonb)}},Z=class extends O{constructor(e,t,n,r,i,a,o,s,c){super(),this.schema=e,this.tableConfig=n,this.dialect=r,this.session=i,this.config=a,this.rowMode=s,this.forbidJsonb=c,this.mode=o,this.table=t}static[t]=`SQLiteAsyncRelationalQueryV2`;mode;table;getSQL(){return this.dialect.buildRelationalQuery({schema:this.schema,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,mode:this.mode,jsonb:this.forbidJsonb?m`json`:m`jsonb`}).sql}_prepare(e=!0){let{query:t,builtQuery:n}=this._toSQL();return this.session[e?`prepareOneTimeRelationalQuery`:`prepareRelationalQuery`](n,void 0,this.mode===`first`?`get`:`all`,(e,n)=>{for(let r of e)ae(r,t.selection,n,!this.rowMode);return this.mode===`first`?e[0]:e})}prepare(){return this._prepare(!1)}_getQuery(){let e=this.forbidJsonb?m`json`:m`jsonb`,t=this.dialect.buildRelationalQuery({schema:this.schema,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,mode:this.mode,isNested:this.rowMode,jsonb:e});return this.rowMode&&(t.sql=m`select json_object(${m.join(t.selection.map(t=>m`${m.raw(this.dialect.escapeString(t.key))}, ${t.selection?m`${e}(${m.identifier(t.key)})`:m.identifier(t.key)}`),m`, `)}) as ${m.identifier(`r`)} from (${t.sql}) as ${m.identifier(`t`)}`),t}_toSQL(){let e=this._getQuery();return{query:e,builtQuery:this.dialect.sqlToQuery(e.sql)}}toSQL(){return this._toSQL().builtQuery}executeRaw(){return this.mode===`first`?this._prepare().get():this._prepare().all()}async execute(){return this.executeRaw()}},Oe=class extends Z{static[t]=`SQLiteSyncRelationalQueryV2`;sync(){return this.executeRaw()}},Q=class extends O{constructor(e,t,n,r,i){super(),this.execute=e,this.getSQL=t,this.dialect=r,this.mapBatchResult=i,this.config={action:n}}static[t]=`SQLiteRaw`;config;getQuery(){return{...this.dialect.sqlToQuery(this.getSQL()),method:this.config.action}}mapResult(e,t){return t?this.mapBatchResult(e):e}_prepare(){return this}isResponseInArrayMode(){return!1}},$=class{constructor(e,t,n,r,i,a,o){this.resultKind=e,this.dialect=t,this.session=n,this.rowModeRQB=a,this.forbidJsonb=o,this._=i?{schema:i.schema,fullSchema:i.fullSchema,tableNamesMap:i.tableNamesMap,relations:r}:{schema:void 0,fullSchema:{},tableNamesMap:{},relations:r},this._query={};let s=this._query;if(this._.schema)for(let[r,a]of Object.entries(this._.schema))s[r]=new we(e,i.fullSchema,this._.schema,this._.tableNamesMap,i.fullSchema[r],a,t,n);this.query={};for(let[i,s]of Object.entries(r))this.query[i]=new De(e,r,r[s.name].table,s,t,n,a,o);this.$cache={invalidate:async e=>{}}}static[t]=`BaseSQLiteDatabase`;_query;query;$with=(e,t)=>{let n=this;return{as:r=>(typeof r==`function`&&(r=r(new J(n.dialect))),new Proxy(new u(r.getSQL(),t??(`getSelectedFields`in r?r.getSelectedFields()??{}:{}),e,!0),new F({alias:e,sqlAliasedBehavior:`alias`,sqlBehavior:`error`})))}};$count(e,t){return new Ee({source:e,filters:t,session:this.session})}with(...e){let t=this;function n(n){return new G({fields:n??void 0,session:t.session,dialect:t.dialect,withList:e})}function r(n){return new G({fields:n??void 0,session:t.session,dialect:t.dialect,withList:e,distinct:!0})}function i(n){return new Se(n,t.session,t.dialect,e)}function a(n){return new Y(n,t.session,t.dialect,e)}function o(n){return new V(n,t.session,t.dialect,e)}return{select:n,selectDistinct:r,update:i,insert:a,delete:o}}select(e){return new G({fields:e??void 0,session:this.session,dialect:this.dialect})}selectDistinct(e){return new G({fields:e??void 0,session:this.session,dialect:this.dialect,distinct:!0})}update(e){return new Se(e,this.session,this.dialect)}$cache;insert(e){return new Y(e,this.session,this.dialect)}delete(e){return new V(e,this.session,this.dialect)}run(e){let t=typeof e==`string`?m.raw(e):e.getSQL();return this.resultKind===`async`?new Q(async()=>this.session.run(t),()=>t,`run`,this.dialect,this.session.extractRawRunValueFromBatchResult.bind(this.session)):this.session.run(t)}all(e){let t=typeof e==`string`?m.raw(e):e.getSQL();return this.resultKind===`async`?new Q(async()=>this.session.all(t),()=>t,`all`,this.dialect,this.session.extractRawAllValueFromBatchResult.bind(this.session)):this.session.all(t)}get(e){let t=typeof e==`string`?m.raw(e):e.getSQL();return this.resultKind===`async`?new Q(async()=>this.session.get(t),()=>t,`get`,this.dialect,this.session.extractRawGetValueFromBatchResult.bind(this.session)):this.session.get(t)}values(e){let t=typeof e==`string`?m.raw(e):e.getSQL();return this.resultKind===`async`?new Q(async()=>this.session.values(t),()=>t,`values`,this.dialect,this.session.extractRawValuesValueFromBatchResult.bind(this.session)):this.session.values(t)}transaction(e,t){return this.session.transaction(e,t)}},ke=class extends O{constructor(e){super(),this.resultCb=e}static[t]=`ExecuteResultSync`;async execute(){return this.resultCb()}sync(){return this.resultCb()}},Ae=class{constructor(e,t,n,r,i,a){this.mode=e,this.executeMethod=t,this.query=n,this.cache=r,this.queryMetadata=i,this.cacheConfig=a,r&&r.strategy()===`all`&&a===void 0&&(this.cacheConfig={enable:!0,autoInvalidate:!0}),this.cacheConfig?.enable||(this.cacheConfig=void 0)}static[t]=`PreparedQuery`;joinsNotNullableMap;async queryWithCache(e,t,n){if(this.cache===void 0||r(this.cache,fe)||this.queryMetadata===void 0)try{return await n()}catch(n){throw new P(e,t,n)}if(this.cacheConfig&&!this.cacheConfig.enable)try{return await n()}catch(n){throw new P(e,t,n)}if((this.queryMetadata.type===`insert`||this.queryMetadata.type===`update`||this.queryMetadata.type===`delete`)&&this.queryMetadata.tables.length>0)try{let[e]=await Promise.all([n(),this.cache.onMutate({tables:this.queryMetadata.tables})]);return e}catch(n){throw new P(e,t,n)}if(!this.cacheConfig)try{return await n()}catch(n){throw new P(e,t,n)}if(this.queryMetadata.type===`select`){let r=await this.cache.get(this.cacheConfig.tag??await ce(e,t),this.queryMetadata.tables,this.cacheConfig.tag!==void 0,this.cacheConfig.autoInvalidate);if(r===void 0){let r;try{r=await n()}catch(n){throw new P(e,t,n)}return await this.cache.put(this.cacheConfig.tag??await ce(e,t),r,this.cacheConfig.autoInvalidate?this.queryMetadata.tables:[],this.cacheConfig.tag!==void 0,this.cacheConfig.config),r}return r}try{return await n()}catch(n){throw new P(e,t,n)}}getQuery(){return this.query}mapRunResult(e,t){return e}mapAllResult(e,t){throw Error(`Not implemented`)}mapGetResult(e,t){throw Error(`Not implemented`)}execute(e){return this.mode===`async`?this[this.executeMethod](e):new ke(()=>this[this.executeMethod](e))}mapResult(e,t){switch(this.executeMethod){case`run`:return this.mapRunResult(e,t);case`all`:return this.mapAllResult(e,t);case`get`:return this.mapGetResult(e,t)}}},je=class{constructor(e){this.dialect=e}static[t]=`SQLiteSession`;prepareOneTimeQuery(e,t,n,r,i,a,o){return this.prepareQuery(e,t,n,r,i,a,o)}prepareOneTimeRelationalQuery(e,t,n,r){return this.prepareRelationalQuery(e,t,n,r)}run(e){let t=this.dialect.sqlToQuery(e);try{return this.prepareOneTimeQuery(t,void 0,`run`,!1).run()}catch(e){throw new M({cause:e,message:`Failed to run the query '${t.sql}'`})}}extractRawRunValueFromBatchResult(e){return e}all(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,`run`,!1).all()}extractRawAllValueFromBatchResult(e){throw Error(`Not implemented`)}get(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,`run`,!1).get()}extractRawGetValueFromBatchResult(e){throw Error(`Not implemented`)}values(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,`run`,!1).values()}async count(e){return(await this.values(e))[0][0]}extractRawValuesValueFromBatchResult(e){throw Error(`Not implemented`)}},Me=class extends ${constructor(e,t,n,r,i,a=0,o,s){super(e,t,n,r,i,o,s),this.relations=r,this.schema=i,this.nestedIndex=a}static[t]=`SQLiteTransaction`;rollback(){throw new D}};export{me as a,$ as i,je as n,W as o,Me as r,Ae as t};
|