drizzle-orm 0.44.7 → 0.45.0-82993ae

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.
Files changed (53) hide show
  1. package/gel-core/dialect.cjs +10 -0
  2. package/gel-core/dialect.cjs.map +1 -1
  3. package/gel-core/dialect.js +10 -0
  4. package/gel-core/dialect.js.map +1 -1
  5. package/mysql-core/dialect.cjs +10 -0
  6. package/mysql-core/dialect.cjs.map +1 -1
  7. package/mysql-core/dialect.js +10 -0
  8. package/mysql-core/dialect.js.map +1 -1
  9. package/mysql-core/indexes.cjs +2 -2
  10. package/mysql-core/indexes.cjs.map +1 -1
  11. package/mysql-core/indexes.d.cts +3 -3
  12. package/mysql-core/indexes.d.ts +3 -3
  13. package/mysql-core/indexes.js +2 -2
  14. package/mysql-core/indexes.js.map +1 -1
  15. package/node-postgres/session.cjs +3 -2
  16. package/node-postgres/session.cjs.map +1 -1
  17. package/node-postgres/session.js +3 -2
  18. package/node-postgres/session.js.map +1 -1
  19. package/operations.cjs.map +1 -1
  20. package/operations.d.cts +3 -2
  21. package/operations.d.ts +3 -2
  22. package/package.json +49 -49
  23. package/pg-core/dialect.cjs +10 -0
  24. package/pg-core/dialect.cjs.map +1 -1
  25. package/pg-core/dialect.js +10 -0
  26. package/pg-core/dialect.js.map +1 -1
  27. package/query-builders/select.types.cjs.map +1 -1
  28. package/query-builders/select.types.d.cts +4 -4
  29. package/query-builders/select.types.d.ts +4 -4
  30. package/singlestore-core/dialect.cjs +10 -0
  31. package/singlestore-core/dialect.cjs.map +1 -1
  32. package/singlestore-core/dialect.js +10 -0
  33. package/singlestore-core/dialect.js.map +1 -1
  34. package/singlestore-core/indexes.cjs +2 -2
  35. package/singlestore-core/indexes.cjs.map +1 -1
  36. package/singlestore-core/indexes.d.cts +3 -3
  37. package/singlestore-core/indexes.d.ts +3 -3
  38. package/singlestore-core/indexes.js +2 -2
  39. package/singlestore-core/indexes.js.map +1 -1
  40. package/sqlite-core/dialect.cjs +11 -0
  41. package/sqlite-core/dialect.cjs.map +1 -1
  42. package/sqlite-core/dialect.js +11 -0
  43. package/sqlite-core/dialect.js.map +1 -1
  44. package/utils.cjs +3 -1
  45. package/utils.cjs.map +1 -1
  46. package/utils.d.cts +5 -0
  47. package/utils.d.ts +5 -0
  48. package/utils.js +3 -1
  49. package/utils.js.map +1 -1
  50. package/version.cjs +1 -1
  51. package/version.d.cts +1 -1
  52. package/version.d.ts +1 -1
  53. package/version.js +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/node-postgres/session.ts"],"sourcesContent":["import type { Client, PoolClient, QueryArrayConfig, QueryConfig, QueryResult, QueryResultRow } from 'pg';\nimport pg from 'pg';\nimport { type Cache, NoopCache } from '~/cache/core/index.ts';\nimport type { WithCacheConfig } from '~/cache/core/types.ts';\nimport { entityKind } from '~/entity.ts';\nimport { type Logger, NoopLogger } from '~/logger.ts';\nimport type { PgDialect } from '~/pg-core/dialect.ts';\nimport { PgTransaction } from '~/pg-core/index.ts';\nimport type { SelectedFieldsOrdered } from '~/pg-core/query-builders/select.types.ts';\nimport type { PgQueryResultHKT, PgTransactionConfig, PreparedQueryConfig } from '~/pg-core/session.ts';\nimport { PgPreparedQuery, PgSession } from '~/pg-core/session.ts';\nimport type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { fillPlaceholders, type Query, type SQL, sql } from '~/sql/sql.ts';\nimport { tracer } from '~/tracing.ts';\nimport { type Assume, mapResultRow } from '~/utils.ts';\n\nconst { Pool, types } = pg;\n\nexport type NodePgClient = pg.Pool | PoolClient | Client;\n\nexport class NodePgPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {\n\tstatic override readonly [entityKind]: string = 'NodePgPreparedQuery';\n\n\tprivate rawQueryConfig: QueryConfig;\n\tprivate queryConfig: QueryArrayConfig;\n\n\tconstructor(\n\t\tprivate client: NodePgClient,\n\t\tprivate queryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tcache: Cache,\n\t\tqueryMetadata: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t} | undefined,\n\t\tcacheConfig: WithCacheConfig | undefined,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (rows: unknown[][]) => T['execute'],\n\t) {\n\t\tsuper({ sql: queryString, params }, cache, queryMetadata, cacheConfig);\n\t\tthis.rawQueryConfig = {\n\t\t\tname,\n\t\t\ttext: queryString,\n\t\t\ttypes: {\n\t\t\t\t// @ts-ignore\n\t\t\t\tgetTypeParser: (typeId, format) => {\n\t\t\t\t\tif (typeId === types.builtins.TIMESTAMPTZ) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.TIMESTAMP) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.DATE) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.INTERVAL) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// numeric[]\n\t\t\t\t\tif (typeId === 1231) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// timestamp[]\n\t\t\t\t\tif (typeId === 1115) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// timestamp with timezone[]\n\t\t\t\t\tif (typeId === 1185) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// interval[]\n\t\t\t\t\tif (typeId === 1187) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// date[]\n\t\t\t\t\tif (typeId === 1182) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\treturn types.getTypeParser(typeId, format);\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t\tthis.queryConfig = {\n\t\t\tname,\n\t\t\ttext: queryString,\n\t\t\trowMode: 'array',\n\t\t\ttypes: {\n\t\t\t\t// @ts-ignore\n\t\t\t\tgetTypeParser: (typeId, format) => {\n\t\t\t\t\tif (typeId === types.builtins.TIMESTAMPTZ) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.TIMESTAMP) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.DATE) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.INTERVAL) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// numeric[]\n\t\t\t\t\tif (typeId === 1231) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// timestamp[]\n\t\t\t\t\tif (typeId === 1115) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// timestamp with timezone[]\n\t\t\t\t\tif (typeId === 1185) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// interval[]\n\t\t\t\t\tif (typeId === 1187) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// date[]\n\t\t\t\t\tif (typeId === 1182) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\treturn types.getTypeParser(typeId, format);\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\tasync execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {\n\t\treturn tracer.startActiveSpan('drizzle.execute', async () => {\n\t\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\n\t\t\tthis.logger.logQuery(this.rawQueryConfig.text, params);\n\n\t\t\tconst { fields, rawQueryConfig: rawQuery, client, queryConfig: query, joinsNotNullableMap, customResultMapper } =\n\t\t\t\tthis;\n\t\t\tif (!fields && !customResultMapper) {\n\t\t\t\treturn tracer.startActiveSpan('drizzle.driver.execute', async (span) => {\n\t\t\t\t\tspan?.setAttributes({\n\t\t\t\t\t\t'drizzle.query.name': rawQuery.name,\n\t\t\t\t\t\t'drizzle.query.text': rawQuery.text,\n\t\t\t\t\t\t'drizzle.query.params': JSON.stringify(params),\n\t\t\t\t\t});\n\t\t\t\t\treturn this.queryWithCache(rawQuery.text, params, async () => {\n\t\t\t\t\t\treturn await client.query(rawQuery, params);\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst result = await tracer.startActiveSpan('drizzle.driver.execute', (span) => {\n\t\t\t\tspan?.setAttributes({\n\t\t\t\t\t'drizzle.query.name': query.name,\n\t\t\t\t\t'drizzle.query.text': query.text,\n\t\t\t\t\t'drizzle.query.params': JSON.stringify(params),\n\t\t\t\t});\n\t\t\t\treturn this.queryWithCache(query.text, params, async () => {\n\t\t\t\t\treturn await client.query(query, params);\n\t\t\t\t});\n\t\t\t});\n\n\t\t\treturn tracer.startActiveSpan('drizzle.mapResponse', () => {\n\t\t\t\treturn customResultMapper\n\t\t\t\t\t? customResultMapper(result.rows)\n\t\t\t\t\t: result.rows.map((row) => mapResultRow<T['execute']>(fields!, row, joinsNotNullableMap));\n\t\t\t});\n\t\t});\n\t}\n\n\tall(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['all']> {\n\t\treturn tracer.startActiveSpan('drizzle.execute', () => {\n\t\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\t\t\tthis.logger.logQuery(this.rawQueryConfig.text, params);\n\t\t\treturn tracer.startActiveSpan('drizzle.driver.execute', (span) => {\n\t\t\t\tspan?.setAttributes({\n\t\t\t\t\t'drizzle.query.name': this.rawQueryConfig.name,\n\t\t\t\t\t'drizzle.query.text': this.rawQueryConfig.text,\n\t\t\t\t\t'drizzle.query.params': JSON.stringify(params),\n\t\t\t\t});\n\t\t\t\treturn this.queryWithCache(this.rawQueryConfig.text, params, async () => {\n\t\t\t\t\treturn this.client.query(this.rawQueryConfig, params);\n\t\t\t\t}).then((result) => result.rows);\n\t\t\t});\n\t\t});\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode(): boolean {\n\t\treturn this._isResponseInArrayMode;\n\t}\n}\n\nexport interface NodePgSessionOptions {\n\tlogger?: Logger;\n\tcache?: Cache;\n}\n\nexport class NodePgSession<\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n> extends PgSession<NodePgQueryResultHKT, TFullSchema, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgSession';\n\n\tprivate logger: Logger;\n\tprivate cache: Cache;\n\n\tconstructor(\n\t\tprivate client: NodePgClient,\n\t\tdialect: PgDialect,\n\t\tprivate schema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: NodePgSessionOptions = {},\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t\tthis.cache = options.cache ?? new NoopCache();\n\t}\n\n\tprepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tisResponseInArrayMode: boolean,\n\t\tcustomResultMapper?: (rows: unknown[][]) => T['execute'],\n\t\tqueryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t},\n\t\tcacheConfig?: WithCacheConfig,\n\t): PgPreparedQuery<T> {\n\t\treturn new NodePgPreparedQuery(\n\t\t\tthis.client,\n\t\t\tquery.sql,\n\t\t\tquery.params,\n\t\t\tthis.logger,\n\t\t\tthis.cache,\n\t\t\tqueryMetadata,\n\t\t\tcacheConfig,\n\t\t\tfields,\n\t\t\tname,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t);\n\t}\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>,\n\t\tconfig?: PgTransactionConfig | undefined,\n\t): Promise<T> {\n\t\tconst session = this.client instanceof Pool // eslint-disable-line no-instanceof/no-instanceof\n\t\t\t? new NodePgSession(await this.client.connect(), this.dialect, this.schema, this.options)\n\t\t\t: this;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TSchema>(this.dialect, session, this.schema);\n\t\tawait tx.execute(sql`begin${config ? sql` ${tx.getTransactionConfigSQL(config)}` : undefined}`);\n\t\ttry {\n\t\t\tconst result = await transaction(tx);\n\t\t\tawait tx.execute(sql`commit`);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tawait tx.execute(sql`rollback`);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tif (this.client instanceof Pool) { // eslint-disable-line no-instanceof/no-instanceof\n\t\t\t\t(session.client as PoolClient).release();\n\t\t\t}\n\t\t}\n\t}\n\n\toverride async count(sql: SQL): Promise<number> {\n\t\tconst res = await this.execute<{ rows: [{ count: string }] }>(sql);\n\t\treturn Number(\n\t\t\tres['rows'][0]['count'],\n\t\t);\n\t}\n}\n\nexport class NodePgTransaction<\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n> extends PgTransaction<NodePgQueryResultHKT, TFullSchema, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgTransaction';\n\n\toverride async transaction<T>(transaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T> {\n\t\tconst savepointName = `sp${this.nestedIndex + 1}`;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tthis.schema,\n\t\t\tthis.nestedIndex + 1,\n\t\t);\n\t\tawait tx.execute(sql.raw(`savepoint ${savepointName}`));\n\t\ttry {\n\t\t\tconst result = await transaction(tx);\n\t\t\tawait tx.execute(sql.raw(`release savepoint ${savepointName}`));\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tawait tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n\nexport interface NodePgQueryResultHKT extends PgQueryResultHKT {\n\ttype: QueryResult<Assume<this['row'], QueryResultRow>>;\n}\n"],"mappings":"AACA,OAAO,QAAQ;AACf,SAAqB,iBAAiB;AAEtC,SAAS,kBAAkB;AAC3B,SAAsB,kBAAkB;AAExC,SAAS,qBAAqB;AAG9B,SAAS,iBAAiB,iBAAiB;AAE3C,SAAS,kBAAwC,WAAW;AAC5D,SAAS,cAAc;AACvB,SAAsB,oBAAoB;AAE1C,MAAM,EAAE,MAAM,MAAM,IAAI;AAIjB,MAAM,4BAA2D,gBAAmB;AAAA,EAM1F,YACS,QACA,aACA,QACA,QACR,OACA,eAIA,aACQ,QACR,MACQ,wBACA,oBACP;AACD,UAAM,EAAE,KAAK,aAAa,OAAO,GAAG,OAAO,eAAe,WAAW;AAf7D;AACA;AACA;AACA;AAOA;AAEA;AACA;AAGR,SAAK,iBAAiB;AAAA,MACrB;AAAA,MACA,MAAM;AAAA,MACN,OAAO;AAAA;AAAA,QAEN,eAAe,CAAC,QAAQ,WAAW;AAClC,cAAI,WAAW,MAAM,SAAS,aAAa;AAC1C,mBAAO,CAAC,QAAQ;AAAA,UACjB;AACA,cAAI,WAAW,MAAM,SAAS,WAAW;AACxC,mBAAO,CAAC,QAAQ;AAAA,UACjB;AACA,cAAI,WAAW,MAAM,SAAS,MAAM;AACnC,mBAAO,CAAC,QAAQ;AAAA,UACjB;AACA,cAAI,WAAW,MAAM,SAAS,UAAU;AACvC,mBAAO,CAAC,QAAQ;AAAA,UACjB;AAEA,cAAI,WAAW,MAAM;AACpB,mBAAO,CAAC,QAAQ;AAAA,UACjB;AAEA,cAAI,W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F,UAAM,GAAG,QAAQ,WAAW,SAAS,OAAO,GAAG,wBAAwB,MAAM,CAAC,KAAK,MAAS,EAAE;AAC9F,QAAI;AACH,YAAM,SAAS,MAAM,YAAY,EAAE;AACnC,YAAM,GAAG,QAAQ,WAAW;AAC5B,aAAO;AAAA,IACR,SAAS,OAAO;AACf,YAAM,GAAG,QAAQ,aAAa;AAC9B,YAAM;AAAA,IACP,UAAE;AACD,UAAI,KAAK,kBAAkB,MAAM;AAChC,QAAC,QAAQ,OAAsB,QAAQ;AAAA,MACxC;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAe,MAAMA,MAA2B;AAC/C,UAAM,MAAM,MAAM,KAAK,QAAuCA,IAAG;AACjE,WAAO;AAAA,MACN,IAAI,MAAM,EAAE,CAAC,EAAE,OAAO;AAAA,IACvB;AAAA,EACD;AACD;AAEO,MAAM,0BAGH,cAA0D;AAAA,EACnE,QAA0B,UAAU,IAAY;AAAA,EAEhD,MAAe,YAAe,aAAsF;AACnH,UAAM,gBAAgB,KAAK,KAAK,cAAc,CAAC;AAC/C,UAAM,KAAK,IAAI;AAAA,MACd,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,cAAc;AAAA,IACpB;AACA,UAAM,GAAG,QAAQ,IAAI,IAAI,aAAa,aAAa,EAAE,CAAC;AACtD,QAAI;AACH,YAAM,SAAS,MAAM,YAAY,EAAE;AACnC,YAAM,GAAG,QAAQ,IAAI,IAAI,qBAAqB,aAAa,EAAE,CAAC;AAC9D,aAAO;AAAA,IACR,SAAS,KAAK;AACb,YAAM,GAAG,QAAQ,IAAI,IAAI,yBAAyB,aAAa,EAAE,CAAC;AAClE,YAAM;AAAA,IACP;AAAA,EACD;AACD;","names":["sql"]}
1
+ {"version":3,"sources":["../../src/node-postgres/session.ts"],"sourcesContent":["import type { Client, PoolClient, QueryArrayConfig, QueryConfig, QueryResult, QueryResultRow } from 'pg';\nimport pg from 'pg';\nimport { type Cache, NoopCache } from '~/cache/core/index.ts';\nimport type { WithCacheConfig } from '~/cache/core/types.ts';\nimport { entityKind } from '~/entity.ts';\nimport { type Logger, NoopLogger } from '~/logger.ts';\nimport type { PgDialect } from '~/pg-core/dialect.ts';\nimport { PgTransaction } from '~/pg-core/index.ts';\nimport type { SelectedFieldsOrdered } from '~/pg-core/query-builders/select.types.ts';\nimport type { PgQueryResultHKT, PgTransactionConfig, PreparedQueryConfig } from '~/pg-core/session.ts';\nimport { PgPreparedQuery, PgSession } from '~/pg-core/session.ts';\nimport type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { fillPlaceholders, type Query, type SQL, sql } from '~/sql/sql.ts';\nimport { tracer } from '~/tracing.ts';\nimport { type Assume, mapResultRow } from '~/utils.ts';\n\nconst { Pool, types } = pg;\nconst NativePool = (<any> pg).native ? (<{ Pool: typeof Pool }> (<any> pg).native).Pool : undefined;\n\nexport type NodePgClient = pg.Pool | PoolClient | Client;\n\nexport class NodePgPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {\n\tstatic override readonly [entityKind]: string = 'NodePgPreparedQuery';\n\n\tprivate rawQueryConfig: QueryConfig;\n\tprivate queryConfig: QueryArrayConfig;\n\n\tconstructor(\n\t\tprivate client: NodePgClient,\n\t\tprivate queryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tcache: Cache,\n\t\tqueryMetadata: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t} | undefined,\n\t\tcacheConfig: WithCacheConfig | undefined,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (rows: unknown[][]) => T['execute'],\n\t) {\n\t\tsuper({ sql: queryString, params }, cache, queryMetadata, cacheConfig);\n\t\tthis.rawQueryConfig = {\n\t\t\tname,\n\t\t\ttext: queryString,\n\t\t\ttypes: {\n\t\t\t\t// @ts-ignore\n\t\t\t\tgetTypeParser: (typeId, format) => {\n\t\t\t\t\tif (typeId === types.builtins.TIMESTAMPTZ) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.TIMESTAMP) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.DATE) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.INTERVAL) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// numeric[]\n\t\t\t\t\tif (typeId === 1231) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// timestamp[]\n\t\t\t\t\tif (typeId === 1115) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// timestamp with timezone[]\n\t\t\t\t\tif (typeId === 1185) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// interval[]\n\t\t\t\t\tif (typeId === 1187) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// date[]\n\t\t\t\t\tif (typeId === 1182) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\treturn types.getTypeParser(typeId, format);\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t\tthis.queryConfig = {\n\t\t\tname,\n\t\t\ttext: queryString,\n\t\t\trowMode: 'array',\n\t\t\ttypes: {\n\t\t\t\t// @ts-ignore\n\t\t\t\tgetTypeParser: (typeId, format) => {\n\t\t\t\t\tif (typeId === types.builtins.TIMESTAMPTZ) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.TIMESTAMP) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.DATE) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId === types.builtins.INTERVAL) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// numeric[]\n\t\t\t\t\tif (typeId === 1231) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// timestamp[]\n\t\t\t\t\tif (typeId === 1115) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// timestamp with timezone[]\n\t\t\t\t\tif (typeId === 1185) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// interval[]\n\t\t\t\t\tif (typeId === 1187) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// date[]\n\t\t\t\t\tif (typeId === 1182) {\n\t\t\t\t\t\treturn (val) => val;\n\t\t\t\t\t}\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\treturn types.getTypeParser(typeId, format);\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\tasync execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {\n\t\treturn tracer.startActiveSpan('drizzle.execute', async () => {\n\t\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\n\t\t\tthis.logger.logQuery(this.rawQueryConfig.text, params);\n\n\t\t\tconst { fields, rawQueryConfig: rawQuery, client, queryConfig: query, joinsNotNullableMap, customResultMapper } =\n\t\t\t\tthis;\n\t\t\tif (!fields && !customResultMapper) {\n\t\t\t\treturn tracer.startActiveSpan('drizzle.driver.execute', async (span) => {\n\t\t\t\t\tspan?.setAttributes({\n\t\t\t\t\t\t'drizzle.query.name': rawQuery.name,\n\t\t\t\t\t\t'drizzle.query.text': rawQuery.text,\n\t\t\t\t\t\t'drizzle.query.params': JSON.stringify(params),\n\t\t\t\t\t});\n\t\t\t\t\treturn this.queryWithCache(rawQuery.text, params, async () => {\n\t\t\t\t\t\treturn await client.query(rawQuery, params);\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst result = await tracer.startActiveSpan('drizzle.driver.execute', (span) => {\n\t\t\t\tspan?.setAttributes({\n\t\t\t\t\t'drizzle.query.name': query.name,\n\t\t\t\t\t'drizzle.query.text': query.text,\n\t\t\t\t\t'drizzle.query.params': JSON.stringify(params),\n\t\t\t\t});\n\t\t\t\treturn this.queryWithCache(query.text, params, async () => {\n\t\t\t\t\treturn await client.query(query, params);\n\t\t\t\t});\n\t\t\t});\n\n\t\t\treturn tracer.startActiveSpan('drizzle.mapResponse', () => {\n\t\t\t\treturn customResultMapper\n\t\t\t\t\t? customResultMapper(result.rows)\n\t\t\t\t\t: result.rows.map((row) => mapResultRow<T['execute']>(fields!, row, joinsNotNullableMap));\n\t\t\t});\n\t\t});\n\t}\n\n\tall(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['all']> {\n\t\treturn tracer.startActiveSpan('drizzle.execute', () => {\n\t\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\t\t\tthis.logger.logQuery(this.rawQueryConfig.text, params);\n\t\t\treturn tracer.startActiveSpan('drizzle.driver.execute', (span) => {\n\t\t\t\tspan?.setAttributes({\n\t\t\t\t\t'drizzle.query.name': this.rawQueryConfig.name,\n\t\t\t\t\t'drizzle.query.text': this.rawQueryConfig.text,\n\t\t\t\t\t'drizzle.query.params': JSON.stringify(params),\n\t\t\t\t});\n\t\t\t\treturn this.queryWithCache(this.rawQueryConfig.text, params, async () => {\n\t\t\t\t\treturn this.client.query(this.rawQueryConfig, params);\n\t\t\t\t}).then((result) => result.rows);\n\t\t\t});\n\t\t});\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode(): boolean {\n\t\treturn this._isResponseInArrayMode;\n\t}\n}\n\nexport interface NodePgSessionOptions {\n\tlogger?: Logger;\n\tcache?: Cache;\n}\n\nexport class NodePgSession<\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n> extends PgSession<NodePgQueryResultHKT, TFullSchema, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgSession';\n\n\tprivate logger: Logger;\n\tprivate cache: Cache;\n\n\tconstructor(\n\t\tprivate client: NodePgClient,\n\t\tdialect: PgDialect,\n\t\tprivate schema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: NodePgSessionOptions = {},\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t\tthis.cache = options.cache ?? new NoopCache();\n\t}\n\n\tprepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tisResponseInArrayMode: boolean,\n\t\tcustomResultMapper?: (rows: unknown[][]) => T['execute'],\n\t\tqueryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t},\n\t\tcacheConfig?: WithCacheConfig,\n\t): PgPreparedQuery<T> {\n\t\treturn new NodePgPreparedQuery(\n\t\t\tthis.client,\n\t\t\tquery.sql,\n\t\t\tquery.params,\n\t\t\tthis.logger,\n\t\t\tthis.cache,\n\t\t\tqueryMetadata,\n\t\t\tcacheConfig,\n\t\t\tfields,\n\t\t\tname,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t);\n\t}\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>,\n\t\tconfig?: PgTransactionConfig | undefined,\n\t): Promise<T> {\n\t\tconst session = (this.client instanceof Pool || (NativePool && this.client instanceof NativePool)) // eslint-disable-line no-instanceof/no-instanceof\n\t\t\t? new NodePgSession(await this.client.connect(), this.dialect, this.schema, this.options)\n\t\t\t: this;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TSchema>(this.dialect, session, this.schema);\n\t\tawait tx.execute(sql`begin${config ? sql` ${tx.getTransactionConfigSQL(config)}` : undefined}`);\n\t\ttry {\n\t\t\tconst result = await transaction(tx);\n\t\t\tawait tx.execute(sql`commit`);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tawait tx.execute(sql`rollback`);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tif (this.client instanceof Pool || (NativePool && this.client instanceof NativePool)) { // eslint-disable-line no-instanceof/no-instanceof\n\t\t\t\t(session.client as PoolClient).release();\n\t\t\t}\n\t\t}\n\t}\n\n\toverride async count(sql: SQL): Promise<number> {\n\t\tconst res = await this.execute<{ rows: [{ count: string }] }>(sql);\n\t\treturn Number(\n\t\t\tres['rows'][0]['count'],\n\t\t);\n\t}\n}\n\nexport class NodePgTransaction<\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n> extends PgTransaction<NodePgQueryResultHKT, TFullSchema, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgTransaction';\n\n\toverride async transaction<T>(transaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T> {\n\t\tconst savepointName = `sp${this.nestedIndex + 1}`;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tthis.schema,\n\t\t\tthis.nestedIndex + 1,\n\t\t);\n\t\tawait tx.execute(sql.raw(`savepoint ${savepointName}`));\n\t\ttry {\n\t\t\tconst result = await transaction(tx);\n\t\t\tawait tx.execute(sql.raw(`release savepoint ${savepointName}`));\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tawait tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n\nexport interface NodePgQueryResultHKT extends PgQueryResultHKT {\n\ttype: QueryResult<Assume<this['row'], QueryResultRow>>;\n}\n"],"mappings":"AACA,OAAO,QAAQ;AACf,SAAqB,iBAAiB;AAEtC,SAAS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AkB,QAAS,cAAc,KAAK,kBAAkB,YAAa;AACrF,QAAC,QAAQ,OAAsB,QAAQ;AAAA,MACxC;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAe,MAAMA,MAA2B;AAC/C,UAAM,MAAM,MAAM,KAAK,QAAuCA,IAAG;AACjE,WAAO;AAAA,MACN,IAAI,MAAM,EAAE,CAAC,EAAE,OAAO;AAAA,IACvB;AAAA,EACD;AACD;AAEO,MAAM,0BAGH,cAA0D;AAAA,EACnE,QAA0B,UAAU,IAAY;AAAA,EAEhD,MAAe,YAAe,aAAsF;AACnH,UAAM,gBAAgB,KAAK,KAAK,cAAc,CAAC;AAC/C,UAAM,KAAK,IAAI;AAAA,MACd,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,cAAc;AAAA,IACpB;AACA,UAAM,GAAG,QAAQ,IAAI,IAAI,aAAa,aAAa,EAAE,CAAC;AACtD,QAAI;AACH,YAAM,SAAS,MAAM,YAAY,EAAE;AACnC,YAAM,GAAG,QAAQ,IAAI,IAAI,qBAAqB,aAAa,EAAE,CAAC;AAC9D,aAAO;AAAA,IACR,SAAS,KAAK;AACb,YAAM,GAAG,QAAQ,IAAI,IAAI,yBAAyB,aAAa,EAAE,CAAC;AAClE,YAAM;AAAA,IACP;AAAA,EACD;AACD;","names":["sql"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/operations.ts"],"sourcesContent":["import type { AnyColumn, Column } from './column.ts';\nimport type { SQL } from './sql/sql.ts';\nimport type { Table } from './table.ts';\n\nexport type RequiredKeyOnly<TKey extends string, T extends Column> = T extends AnyColumn<{\n\tnotNull: true;\n\thasDefault: false;\n}> ? TKey\n\t: never;\n\nexport type OptionalKeyOnly<TKey extends string, T extends Column, OverrideT extends boolean | undefined = false> =\n\tTKey extends RequiredKeyOnly<TKey, T> ? never : T extends {\n\t\t_: {\n\t\t\tgenerated: undefined;\n\t\t};\n\t} ? (T extends {\n\t\t\t_: {\n\t\t\t\tidentity: undefined;\n\t\t\t};\n\t\t} ? TKey\n\t\t\t: T['_']['identity'] extends 'always' ? OverrideT extends true ? TKey : never\n\t\t\t: TKey)\n\t: never;\n\n// TODO: SQL -> SQLWrapper\nexport type SelectedFieldsFlat<TColumn extends Column> = Record<\n\tstring,\n\tTColumn | SQL | SQL.Aliased\n>;\n\nexport type SelectedFieldsFlatFull<TColumn extends Column> = Record<\n\tstring,\n\tTColumn | SQL | SQL.Aliased\n>;\n\nexport type SelectedFields<TColumn extends Column, TTable extends Table> = Record<\n\tstring,\n\tSelectedFieldsFlat<TColumn>[string] | TTable | SelectedFieldsFlat<TColumn>\n>;\n\nexport type SelectedFieldsOrdered<TColumn extends Column> = {\n\tpath: string[];\n\tfield: TColumn | SQL | SQL.Aliased;\n}[];\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../src/operations.ts"],"sourcesContent":["import type { AnyColumn, Column } from './column.ts';\nimport type { SQL } from './sql/sql.ts';\nimport type { Subquery } from './subquery.ts';\nimport type { Table } from './table.ts';\n\nexport type RequiredKeyOnly<TKey extends string, T extends Column> = T extends AnyColumn<{\n\tnotNull: true;\n\thasDefault: false;\n}> ? TKey\n\t: never;\n\nexport type OptionalKeyOnly<TKey extends string, T extends Column, OverrideT extends boolean | undefined = false> =\n\tTKey extends RequiredKeyOnly<TKey, T> ? never : T extends {\n\t\t_: {\n\t\t\tgenerated: undefined;\n\t\t};\n\t} ? (T extends {\n\t\t\t_: {\n\t\t\t\tidentity: undefined;\n\t\t\t};\n\t\t} ? TKey\n\t\t\t: T['_']['identity'] extends 'always' ? OverrideT extends true ? TKey : never\n\t\t\t: TKey)\n\t: never;\n\n// TODO: SQL -> SQLWrapper\nexport type SelectedFieldsFlat<TColumn extends Column> = Record<\n\tstring,\n\tTColumn | SQL | SQL.Aliased | Subquery\n>;\n\nexport type SelectedFieldsFlatFull<TColumn extends Column> = Record<\n\tstring,\n\tTColumn | SQL | SQL.Aliased\n>;\n\nexport type SelectedFields<TColumn extends Column, TTable extends Table> = Record<\n\tstring,\n\tSelectedFieldsFlat<TColumn>[string] | TTable | SelectedFieldsFlat<TColumn>\n>;\n\nexport type SelectedFieldsOrdered<TColumn extends Column> = {\n\tpath: string[];\n\tfield: TColumn | SQL | SQL.Aliased | Subquery;\n}[];\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
package/operations.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { AnyColumn, Column } from "./column.cjs";
2
2
  import type { SQL } from "./sql/sql.cjs";
3
+ import type { Subquery } from "./subquery.cjs";
3
4
  import type { Table } from "./table.cjs";
4
5
  export type RequiredKeyOnly<TKey extends string, T extends Column> = T extends AnyColumn<{
5
6
  notNull: true;
@@ -14,10 +15,10 @@ export type OptionalKeyOnly<TKey extends string, T extends Column, OverrideT ext
14
15
  identity: undefined;
15
16
  };
16
17
  } ? TKey : T['_']['identity'] extends 'always' ? OverrideT extends true ? TKey : never : TKey) : never;
17
- export type SelectedFieldsFlat<TColumn extends Column> = Record<string, TColumn | SQL | SQL.Aliased>;
18
+ export type SelectedFieldsFlat<TColumn extends Column> = Record<string, TColumn | SQL | SQL.Aliased | Subquery>;
18
19
  export type SelectedFieldsFlatFull<TColumn extends Column> = Record<string, TColumn | SQL | SQL.Aliased>;
19
20
  export type SelectedFields<TColumn extends Column, TTable extends Table> = Record<string, SelectedFieldsFlat<TColumn>[string] | TTable | SelectedFieldsFlat<TColumn>>;
20
21
  export type SelectedFieldsOrdered<TColumn extends Column> = {
21
22
  path: string[];
22
- field: TColumn | SQL | SQL.Aliased;
23
+ field: TColumn | SQL | SQL.Aliased | Subquery;
23
24
  }[];
package/operations.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { AnyColumn, Column } from "./column.js";
2
2
  import type { SQL } from "./sql/sql.js";
3
+ import type { Subquery } from "./subquery.js";
3
4
  import type { Table } from "./table.js";
4
5
  export type RequiredKeyOnly<TKey extends string, T extends Column> = T extends AnyColumn<{
5
6
  notNull: true;
@@ -14,10 +15,10 @@ export type OptionalKeyOnly<TKey extends string, T extends Column, OverrideT ext
14
15
  identity: undefined;
15
16
  };
16
17
  } ? TKey : T['_']['identity'] extends 'always' ? OverrideT extends true ? TKey : never : TKey) : never;
17
- export type SelectedFieldsFlat<TColumn extends Column> = Record<string, TColumn | SQL | SQL.Aliased>;
18
+ export type SelectedFieldsFlat<TColumn extends Column> = Record<string, TColumn | SQL | SQL.Aliased | Subquery>;
18
19
  export type SelectedFieldsFlatFull<TColumn extends Column> = Record<string, TColumn | SQL | SQL.Aliased>;
19
20
  export type SelectedFields<TColumn extends Column, TTable extends Table> = Record<string, SelectedFieldsFlat<TColumn>[string] | TTable | SelectedFieldsFlat<TColumn>>;
20
21
  export type SelectedFieldsOrdered<TColumn extends Column> = {
21
22
  path: string[];
22
- field: TColumn | SQL | SQL.Aliased;
23
+ field: TColumn | SQL | SQL.Aliased | Subquery;
23
24
  }[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "0.44.7",
3
+ "version": "0.45.0-82993ae",
4
4
  "description": "Drizzle ORM package for SQL databases",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -557,54 +557,6 @@
557
557
  "types": "./better-sqlite3/session.d.ts",
558
558
  "default": "./better-sqlite3/session.js"
559
559
  },
560
- "./bun-sqlite/driver": {
561
- "import": {
562
- "types": "./bun-sqlite/driver.d.ts",
563
- "default": "./bun-sqlite/driver.js"
564
- },
565
- "require": {
566
- "types": "./bun-sqlite/driver.d.cts",
567
- "default": "./bun-sqlite/driver.cjs"
568
- },
569
- "types": "./bun-sqlite/driver.d.ts",
570
- "default": "./bun-sqlite/driver.js"
571
- },
572
- "./bun-sqlite": {
573
- "import": {
574
- "types": "./bun-sqlite/index.d.ts",
575
- "default": "./bun-sqlite/index.js"
576
- },
577
- "require": {
578
- "types": "./bun-sqlite/index.d.cts",
579
- "default": "./bun-sqlite/index.cjs"
580
- },
581
- "types": "./bun-sqlite/index.d.ts",
582
- "default": "./bun-sqlite/index.js"
583
- },
584
- "./bun-sqlite/migrator": {
585
- "import": {
586
- "types": "./bun-sqlite/migrator.d.ts",
587
- "default": "./bun-sqlite/migrator.js"
588
- },
589
- "require": {
590
- "types": "./bun-sqlite/migrator.d.cts",
591
- "default": "./bun-sqlite/migrator.cjs"
592
- },
593
- "types": "./bun-sqlite/migrator.d.ts",
594
- "default": "./bun-sqlite/migrator.js"
595
- },
596
- "./bun-sqlite/session": {
597
- "import": {
598
- "types": "./bun-sqlite/session.d.ts",
599
- "default": "./bun-sqlite/session.js"
600
- },
601
- "require": {
602
- "types": "./bun-sqlite/session.d.cts",
603
- "default": "./bun-sqlite/session.cjs"
604
- },
605
- "types": "./bun-sqlite/session.d.ts",
606
- "default": "./bun-sqlite/session.js"
607
- },
608
560
  "./bun-sql/driver": {
609
561
  "import": {
610
562
  "types": "./bun-sql/driver.d.ts",
@@ -653,6 +605,54 @@
653
605
  "types": "./bun-sql/session.d.ts",
654
606
  "default": "./bun-sql/session.js"
655
607
  },
608
+ "./bun-sqlite/driver": {
609
+ "import": {
610
+ "types": "./bun-sqlite/driver.d.ts",
611
+ "default": "./bun-sqlite/driver.js"
612
+ },
613
+ "require": {
614
+ "types": "./bun-sqlite/driver.d.cts",
615
+ "default": "./bun-sqlite/driver.cjs"
616
+ },
617
+ "types": "./bun-sqlite/driver.d.ts",
618
+ "default": "./bun-sqlite/driver.js"
619
+ },
620
+ "./bun-sqlite": {
621
+ "import": {
622
+ "types": "./bun-sqlite/index.d.ts",
623
+ "default": "./bun-sqlite/index.js"
624
+ },
625
+ "require": {
626
+ "types": "./bun-sqlite/index.d.cts",
627
+ "default": "./bun-sqlite/index.cjs"
628
+ },
629
+ "types": "./bun-sqlite/index.d.ts",
630
+ "default": "./bun-sqlite/index.js"
631
+ },
632
+ "./bun-sqlite/migrator": {
633
+ "import": {
634
+ "types": "./bun-sqlite/migrator.d.ts",
635
+ "default": "./bun-sqlite/migrator.js"
636
+ },
637
+ "require": {
638
+ "types": "./bun-sqlite/migrator.d.cts",
639
+ "default": "./bun-sqlite/migrator.cjs"
640
+ },
641
+ "types": "./bun-sqlite/migrator.d.ts",
642
+ "default": "./bun-sqlite/migrator.js"
643
+ },
644
+ "./bun-sqlite/session": {
645
+ "import": {
646
+ "types": "./bun-sqlite/session.d.ts",
647
+ "default": "./bun-sqlite/session.js"
648
+ },
649
+ "require": {
650
+ "types": "./bun-sqlite/session.d.cts",
651
+ "default": "./bun-sqlite/session.cjs"
652
+ },
653
+ "types": "./bun-sqlite/session.d.ts",
654
+ "default": "./bun-sqlite/session.js"
655
+ },
656
656
  "./d1/driver": {
657
657
  "import": {
658
658
  "types": "./d1/driver.d.ts",
@@ -171,6 +171,16 @@ class PgDialect {
171
171
  } else {
172
172
  chunk.push(field);
173
173
  }
174
+ } else if ((0, import_entity.is)(field, import_subquery.Subquery)) {
175
+ const entries = Object.entries(field._.selectedFields);
176
+ if (entries.length === 1) {
177
+ const entry = entries[0][1];
178
+ const fieldDecoder = (0, import_entity.is)(entry, import_sql2.SQL) ? entry.decoder : (0, import_entity.is)(entry, import_column.Column) ? { mapFromDriverValue: (v) => entry.mapFromDriverValue(v) } : entry.sql.decoder;
179
+ if (fieldDecoder) {
180
+ field._.sql.decoder = fieldDecoder;
181
+ }
182
+ }
183
+ chunk.push(field);
174
184
  }
175
185
  if (i < columnsLen - 1) {
176
186
  chunk.push(import_sql2.sql`, `);