drizzle-orm 1.0.0-beta.1-fd5d1e8 → 1.0.0-beta.1-867d080

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 (67) hide show
  1. package/mysql-core/columns/decimal.cjs +86 -1
  2. package/mysql-core/columns/decimal.cjs.map +1 -1
  3. package/mysql-core/columns/decimal.d.cts +47 -3
  4. package/mysql-core/columns/decimal.d.ts +47 -3
  5. package/mysql-core/columns/decimal.js +82 -1
  6. package/mysql-core/columns/decimal.js.map +1 -1
  7. package/mysql-core/dialect.cjs +3 -0
  8. package/mysql-core/dialect.cjs.map +1 -1
  9. package/mysql-core/dialect.js +3 -0
  10. package/mysql-core/dialect.js.map +1 -1
  11. package/neon-serverless/session.cjs +6 -0
  12. package/neon-serverless/session.cjs.map +1 -1
  13. package/neon-serverless/session.js +6 -0
  14. package/neon-serverless/session.js.map +1 -1
  15. package/node-postgres/session.cjs +6 -0
  16. package/node-postgres/session.cjs.map +1 -1
  17. package/node-postgres/session.js +6 -0
  18. package/node-postgres/session.js.map +1 -1
  19. package/package.json +1 -1
  20. package/pg-core/columns/numeric.cjs +86 -1
  21. package/pg-core/columns/numeric.cjs.map +1 -1
  22. package/pg-core/columns/numeric.d.cts +61 -6
  23. package/pg-core/columns/numeric.d.ts +61 -6
  24. package/pg-core/columns/numeric.js +82 -1
  25. package/pg-core/columns/numeric.js.map +1 -1
  26. package/pg-core/dialect.cjs +2 -0
  27. package/pg-core/dialect.cjs.map +1 -1
  28. package/pg-core/dialect.js +2 -0
  29. package/pg-core/dialect.js.map +1 -1
  30. package/pglite/session.cjs +8 -0
  31. package/pglite/session.cjs.map +1 -1
  32. package/pglite/session.js +8 -0
  33. package/pglite/session.js.map +1 -1
  34. package/postgres-js/driver.cjs +1 -1
  35. package/postgres-js/driver.cjs.map +1 -1
  36. package/postgres-js/driver.js +1 -1
  37. package/postgres-js/driver.js.map +1 -1
  38. package/postgres-js/session.cjs +0 -1
  39. package/postgres-js/session.cjs.map +1 -1
  40. package/postgres-js/session.d.cts +0 -1
  41. package/postgres-js/session.d.ts +0 -1
  42. package/postgres-js/session.js +0 -1
  43. package/postgres-js/session.js.map +1 -1
  44. package/relations.cjs +0 -2
  45. package/relations.cjs.map +1 -1
  46. package/relations.d.cts +3 -3
  47. package/relations.d.ts +3 -3
  48. package/relations.js +0 -2
  49. package/relations.js.map +1 -1
  50. package/sqlite-core/columns/numeric.cjs +64 -2
  51. package/sqlite-core/columns/numeric.cjs.map +1 -1
  52. package/sqlite-core/columns/numeric.d.cts +43 -2
  53. package/sqlite-core/columns/numeric.d.ts +43 -2
  54. package/sqlite-core/columns/numeric.js +60 -2
  55. package/sqlite-core/columns/numeric.js.map +1 -1
  56. package/sqlite-core/dialect.cjs +5 -0
  57. package/sqlite-core/dialect.cjs.map +1 -1
  58. package/sqlite-core/dialect.js +5 -0
  59. package/sqlite-core/dialect.js.map +1 -1
  60. package/vercel-postgres/session.cjs +6 -0
  61. package/vercel-postgres/session.cjs.map +1 -1
  62. package/vercel-postgres/session.js +6 -0
  63. package/vercel-postgres/session.js.map +1 -1
  64. package/version.cjs +1 -1
  65. package/version.d.cts +1 -1
  66. package/version.d.ts +1 -1
  67. 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 * as V1 from '~/_relations.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 { AnyRelations, 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, TIsRqbV2 extends boolean = false>\n\textends PgPreparedQuery<T>\n{\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\tqueryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (\n\t\t\trows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][],\n\t\t) => T['execute'],\n\t\tprivate isRqbV2Query?: TIsRqbV2,\n\t) {\n\t\tsuper({ sql: queryString, params });\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// 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// 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\tif (this.isRqbV2Query) return this.executeRqbV2(placeholderValues);\n\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 client.query(rawQuery, params);\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 client.query(query, params);\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 as (rows: unknown[][]) => T['execute'])(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\tprivate async executeRqbV2(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 { rawQueryConfig: rawQuery, client, customResultMapper } = this;\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': rawQuery.name,\n\t\t\t\t\t'drizzle.query.text': rawQuery.text,\n\t\t\t\t\t'drizzle.query.params': JSON.stringify(params),\n\t\t\t\t});\n\t\t\t\treturn client.query(rawQuery, params);\n\t\t\t});\n\n\t\t\treturn tracer.startActiveSpan('drizzle.mapResponse', () => {\n\t\t\t\treturn (customResultMapper as (rows: Record<string, unknown>[]) => T['execute'])(result.rows);\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.client.query(this.rawQueryConfig, params).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}\n\nexport class NodePgSession<\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTTablesConfig extends TablesRelationalConfig,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends PgSession<NodePgQueryResultHKT, TFullSchema, TRelations, TTablesConfig, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgSession';\n\n\tprivate logger: Logger;\n\n\tconstructor(\n\t\tprivate client: NodePgClient,\n\t\tdialect: PgDialect,\n\t\tprivate relations: AnyRelations | undefined,\n\t\tprivate schema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: NodePgSessionOptions = {},\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\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): 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\tfields,\n\t\t\tname,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t);\n\t}\n\n\tprepareRelationalQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tcustomResultMapper?: (rows: Record<string, unknown>[]) => T['execute'],\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\tfields,\n\t\t\tname,\n\t\t\tfalse,\n\t\t\tcustomResultMapper,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: NodePgTransaction<TFullSchema, TRelations, TTablesConfig, 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.relations, this.schema, this.options)\n\t\t\t: this;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tsession,\n\t\t\tthis.relations,\n\t\t\tthis.schema,\n\t\t);\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\tTRelations extends AnyRelations,\n\tTTablesConfig extends TablesRelationalConfig,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends PgTransaction<NodePgQueryResultHKT, TFullSchema, TRelations, TTablesConfig, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgTransaction';\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>) => Promise<T>,\n\t): Promise<T> {\n\t\tconst savepointName = `sp${this.nestedIndex + 1}`;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tthis.relations,\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gBAAe;AAEf,oBAA2B;AAC3B,oBAAwC;AAExC,qBAA8B;AAG9B,qBAA2C;AAE3C,iBAA4D;AAC5D,qBAAuB;AACvB,mBAA0C;AAE1C,MAAM,EAAE,MAAM,MAAM,IAAI,UAAAA;AAIjB,MAAM,4BACJ,+BACT;AAAA,EAMC,YACS,QACR,aACQ,QACA,QACA,QACR,MACQ,wBACA,oBAGA,cACP;AACD,UAAM,EAAE,KAAK,aAAa,OAAO,CAAC;AAZ1B;AAEA;AACA;AACA;AAEA;AACA;AAGA;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,WAAW,MAAM;AACpB,mBAAO,CAAC,QAAQ;AAAA,UACjB;AAEA,cAAI,WAAW,MAAM;AACpB,mBAAO,CAAC,QAAQ;AAAA,UACjB;AAEA,cAAI,WAAW,MAAM;A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ACnC,YAAM,GAAG,QAAQ,eAAI,IAAI,qBAAqB,aAAa,EAAE,CAAC;AAC9D,aAAO;AAAA,IACR,SAAS,KAAK;AACb,YAAM,GAAG,QAAQ,eAAI,IAAI,yBAAyB,aAAa,EAAE,CAAC;AAClE,YAAM;AAAA,IACP;AAAA,EACD;AACD;","names":["pg","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 * as V1 from '~/_relations.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 { AnyRelations, 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, TIsRqbV2 extends boolean = false>\n\textends PgPreparedQuery<T>\n{\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\tqueryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (\n\t\t\trows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][],\n\t\t) => T['execute'],\n\t\tprivate isRqbV2Query?: TIsRqbV2,\n\t) {\n\t\tsuper({ sql: queryString, params });\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\tif (this.isRqbV2Query) return this.executeRqbV2(placeholderValues);\n\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 client.query(rawQuery, params);\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 client.query(query, params);\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 as (rows: unknown[][]) => T['execute'])(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\tprivate async executeRqbV2(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 { rawQueryConfig: rawQuery, client, customResultMapper } = this;\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': rawQuery.name,\n\t\t\t\t\t'drizzle.query.text': rawQuery.text,\n\t\t\t\t\t'drizzle.query.params': JSON.stringify(params),\n\t\t\t\t});\n\t\t\t\treturn client.query(rawQuery, params);\n\t\t\t});\n\n\t\t\treturn tracer.startActiveSpan('drizzle.mapResponse', () => {\n\t\t\t\treturn (customResultMapper as (rows: Record<string, unknown>[]) => T['execute'])(result.rows);\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.client.query(this.rawQueryConfig, params).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}\n\nexport class NodePgSession<\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTTablesConfig extends TablesRelationalConfig,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends PgSession<NodePgQueryResultHKT, TFullSchema, TRelations, TTablesConfig, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgSession';\n\n\tprivate logger: Logger;\n\n\tconstructor(\n\t\tprivate client: NodePgClient,\n\t\tdialect: PgDialect,\n\t\tprivate relations: AnyRelations | undefined,\n\t\tprivate schema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: NodePgSessionOptions = {},\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\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): 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\tfields,\n\t\t\tname,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t);\n\t}\n\n\tprepareRelationalQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tcustomResultMapper?: (rows: Record<string, unknown>[]) => T['execute'],\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\tfields,\n\t\t\tname,\n\t\t\tfalse,\n\t\t\tcustomResultMapper,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: NodePgTransaction<TFullSchema, TRelations, TTablesConfig, 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.relations, this.schema, this.options)\n\t\t\t: this;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tsession,\n\t\t\tthis.relations,\n\t\t\tthis.schema,\n\t\t);\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\tTRelations extends AnyRelations,\n\tTTablesConfig extends TablesRelationalConfig,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends PgTransaction<NodePgQueryResultHKT, TFullSchema, TRelations, TTablesConfig, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgTransaction';\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>) => Promise<T>,\n\t): Promise<T> {\n\t\tconst savepointName = `sp${this.nestedIndex + 1}`;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tthis.relations,\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gBAAe;AAEf,oBAA2B;AAC3B,oBAAwC;AAExC,qBAA8B;AAG9B,qBAA2C;AAE3C,iBAA4D;AAC5D,qBAAuB;AACvB,mBA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35
35
  if (typeId === types.builtins.INTERVAL) {
36
36
  return (val) => val;
37
37
  }
38
+ if (typeId === 1231) {
39
+ return (val) => val;
40
+ }
38
41
  if (typeId === 1115) {
39
42
  return (val) => val;
40
43
  }
@@ -70,6 +73,9 @@ class NodePgPreparedQuery extends PgPreparedQuery {
70
73
  if (typeId === types.builtins.INTERVAL) {
71
74
  return (val) => val;
72
75
  }
76
+ if (typeId === 1231) {
77
+ return (val) => val;
78
+ }
73
79
  if (typeId === 1115) {
74
80
  return (val) => val;
75
81
  }
@@ -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 * as V1 from '~/_relations.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 { AnyRelations, 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, TIsRqbV2 extends boolean = false>\n\textends PgPreparedQuery<T>\n{\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\tqueryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (\n\t\t\trows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][],\n\t\t) => T['execute'],\n\t\tprivate isRqbV2Query?: TIsRqbV2,\n\t) {\n\t\tsuper({ sql: queryString, params });\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// 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// 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\tif (this.isRqbV2Query) return this.executeRqbV2(placeholderValues);\n\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 client.query(rawQuery, params);\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 client.query(query, params);\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 as (rows: unknown[][]) => T['execute'])(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\tprivate async executeRqbV2(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 { rawQueryConfig: rawQuery, client, customResultMapper } = this;\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': rawQuery.name,\n\t\t\t\t\t'drizzle.query.text': rawQuery.text,\n\t\t\t\t\t'drizzle.query.params': JSON.stringify(params),\n\t\t\t\t});\n\t\t\t\treturn client.query(rawQuery, params);\n\t\t\t});\n\n\t\t\treturn tracer.startActiveSpan('drizzle.mapResponse', () => {\n\t\t\t\treturn (customResultMapper as (rows: Record<string, unknown>[]) => T['execute'])(result.rows);\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.client.query(this.rawQueryConfig, params).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}\n\nexport class NodePgSession<\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTTablesConfig extends TablesRelationalConfig,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends PgSession<NodePgQueryResultHKT, TFullSchema, TRelations, TTablesConfig, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgSession';\n\n\tprivate logger: Logger;\n\n\tconstructor(\n\t\tprivate client: NodePgClient,\n\t\tdialect: PgDialect,\n\t\tprivate relations: AnyRelations | undefined,\n\t\tprivate schema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: NodePgSessionOptions = {},\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\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): 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\tfields,\n\t\t\tname,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t);\n\t}\n\n\tprepareRelationalQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tcustomResultMapper?: (rows: Record<string, unknown>[]) => T['execute'],\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\tfields,\n\t\t\tname,\n\t\t\tfalse,\n\t\t\tcustomResultMapper,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: NodePgTransaction<TFullSchema, TRelations, TTablesConfig, 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.relations, this.schema, this.options)\n\t\t\t: this;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tsession,\n\t\t\tthis.relations,\n\t\t\tthis.schema,\n\t\t);\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\tTRelations extends AnyRelations,\n\tTTablesConfig extends TablesRelationalConfig,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends PgTransaction<NodePgQueryResultHKT, TFullSchema, TRelations, TTablesConfig, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgTransaction';\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>) => Promise<T>,\n\t): Promise<T> {\n\t\tconst savepointName = `sp${this.nestedIndex + 1}`;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tthis.relations,\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;AAEf,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,4BACJ,gBAC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AAG,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,0BAKH,cAAqF;AAAA,EAC9F,QAA0B,UAAU,IAAY;AAAA,EAEhD,MAAe,YACd,aACa;AACb,UAAM,gBAAgB,KAAK,KAAK,cAAc,CAAC;AAC/C,UAAM,KAAK,IAAI;AAAA,MACd,KAAK;AAAA,MACL,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 * as V1 from '~/_relations.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 { AnyRelations, 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, TIsRqbV2 extends boolean = false>\n\textends PgPreparedQuery<T>\n{\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\tqueryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (\n\t\t\trows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][],\n\t\t) => T['execute'],\n\t\tprivate isRqbV2Query?: TIsRqbV2,\n\t) {\n\t\tsuper({ sql: queryString, params });\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\tif (this.isRqbV2Query) return this.executeRqbV2(placeholderValues);\n\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 client.query(rawQuery, params);\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 client.query(query, params);\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 as (rows: unknown[][]) => T['execute'])(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\tprivate async executeRqbV2(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 { rawQueryConfig: rawQuery, client, customResultMapper } = this;\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': rawQuery.name,\n\t\t\t\t\t'drizzle.query.text': rawQuery.text,\n\t\t\t\t\t'drizzle.query.params': JSON.stringify(params),\n\t\t\t\t});\n\t\t\t\treturn client.query(rawQuery, params);\n\t\t\t});\n\n\t\t\treturn tracer.startActiveSpan('drizzle.mapResponse', () => {\n\t\t\t\treturn (customResultMapper as (rows: Record<string, unknown>[]) => T['execute'])(result.rows);\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.client.query(this.rawQueryConfig, params).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}\n\nexport class NodePgSession<\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTTablesConfig extends TablesRelationalConfig,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends PgSession<NodePgQueryResultHKT, TFullSchema, TRelations, TTablesConfig, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgSession';\n\n\tprivate logger: Logger;\n\n\tconstructor(\n\t\tprivate client: NodePgClient,\n\t\tdialect: PgDialect,\n\t\tprivate relations: AnyRelations | undefined,\n\t\tprivate schema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: NodePgSessionOptions = {},\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\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): 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\tfields,\n\t\t\tname,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t);\n\t}\n\n\tprepareRelationalQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tcustomResultMapper?: (rows: Record<string, unknown>[]) => T['execute'],\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\tfields,\n\t\t\tname,\n\t\t\tfalse,\n\t\t\tcustomResultMapper,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: NodePgTransaction<TFullSchema, TRelations, TTablesConfig, 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.relations, this.schema, this.options)\n\t\t\t: this;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tsession,\n\t\t\tthis.relations,\n\t\t\tthis.schema,\n\t\t);\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\tTRelations extends AnyRelations,\n\tTTablesConfig extends TablesRelationalConfig,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends PgTransaction<NodePgQueryResultHKT, TFullSchema, TRelations, TTablesConfig, TSchema> {\n\tstatic override readonly [entityKind]: string = 'NodePgTransaction';\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>) => Promise<T>,\n\t): Promise<T> {\n\t\tconst savepointName = `sp${this.nestedIndex + 1}`;\n\t\tconst tx = new NodePgTransaction<TFullSchema, TRelations, TTablesConfig, TSchema>(\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tthis.relations,\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;AAEf,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,4BACJ,gBACT;AAAA,EAMC,YACS,QACR,aACQ,QACA,QACA,QACR,MACQ,wBACA,oBAGA,cACP;AACD,UAAM,EAAE,KAAK,aAAa,OAAO,CAAC;AAZ1B;AAEA;AACA;AACA;AAEA;AACA;AAGA;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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N,IAAI,MAAM,EAAE,CAAC,EAAE,OAAO;AAAA,IACvB;AAAA,EACD;AACD;AAEO,MAAM,0BAKH,cAAqF;AAAA,EAC9F,QAA0B,UAAU,IAAY;AAAA,EAEhD,MAAe,YACd,aACa;AACb,UAAM,gBAAgB,KAAK,KAAK,cAAc,CAAC;AAC/C,UAAM,KAAK,IAAI;AAAA,MACd,KAAK;AAAA,MACL,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "1.0.0-beta.1-fd5d1e8",
3
+ "version": "1.0.0-beta.1-867d080",
4
4
  "description": "Drizzle ORM package for SQL databases",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -19,7 +19,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var numeric_exports = {};
20
20
  __export(numeric_exports, {
21
21
  PgNumeric: () => PgNumeric,
22
+ PgNumericBigInt: () => PgNumericBigInt,
23
+ PgNumericBigIntBuilder: () => PgNumericBigIntBuilder,
22
24
  PgNumericBuilder: () => PgNumericBuilder,
25
+ PgNumericNumber: () => PgNumericNumber,
26
+ PgNumericNumberBuilder: () => PgNumericNumberBuilder,
23
27
  decimal: () => decimal,
24
28
  numeric: () => numeric
25
29
  });
@@ -63,15 +67,96 @@ class PgNumeric extends import_common.PgColumn {
63
67
  }
64
68
  }
65
69
  }
70
+ class PgNumericNumberBuilder extends import_common.PgColumnBuilder {
71
+ static [import_entity.entityKind] = "PgNumericNumberBuilder";
72
+ constructor(name, precision, scale) {
73
+ super(name, "number", "PgNumericNumber");
74
+ this.config.precision = precision;
75
+ this.config.scale = scale;
76
+ }
77
+ /** @internal */
78
+ build(table) {
79
+ return new PgNumericNumber(
80
+ table,
81
+ this.config
82
+ );
83
+ }
84
+ }
85
+ class PgNumericNumber extends import_common.PgColumn {
86
+ static [import_entity.entityKind] = "PgNumericNumber";
87
+ precision;
88
+ scale;
89
+ constructor(table, config) {
90
+ super(table, config);
91
+ this.precision = config.precision;
92
+ this.scale = config.scale;
93
+ }
94
+ mapFromDriverValue(value) {
95
+ if (typeof value === "number")
96
+ return value;
97
+ return Number(value);
98
+ }
99
+ mapToDriverValue = String;
100
+ getSQLType() {
101
+ if (this.precision !== void 0 && this.scale !== void 0) {
102
+ return `numeric(${this.precision}, ${this.scale})`;
103
+ } else if (this.precision === void 0) {
104
+ return "numeric";
105
+ } else {
106
+ return `numeric(${this.precision})`;
107
+ }
108
+ }
109
+ }
110
+ class PgNumericBigIntBuilder extends import_common.PgColumnBuilder {
111
+ static [import_entity.entityKind] = "PgNumericBigIntBuilder";
112
+ constructor(name, precision, scale) {
113
+ super(name, "bigint", "PgNumericBigInt");
114
+ this.config.precision = precision;
115
+ this.config.scale = scale;
116
+ }
117
+ /** @internal */
118
+ build(table) {
119
+ return new PgNumericBigInt(
120
+ table,
121
+ this.config
122
+ );
123
+ }
124
+ }
125
+ class PgNumericBigInt extends import_common.PgColumn {
126
+ static [import_entity.entityKind] = "PgNumericBigInt";
127
+ precision;
128
+ scale;
129
+ constructor(table, config) {
130
+ super(table, config);
131
+ this.precision = config.precision;
132
+ this.scale = config.scale;
133
+ }
134
+ mapFromDriverValue = BigInt;
135
+ mapToDriverValue = String;
136
+ getSQLType() {
137
+ if (this.precision !== void 0 && this.scale !== void 0) {
138
+ return `numeric(${this.precision}, ${this.scale})`;
139
+ } else if (this.precision === void 0) {
140
+ return "numeric";
141
+ } else {
142
+ return `numeric(${this.precision})`;
143
+ }
144
+ }
145
+ }
66
146
  function numeric(a, b) {
67
147
  const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
68
- return new PgNumericBuilder(name, config?.precision, config?.scale);
148
+ const mode = config?.mode;
149
+ return mode === "number" ? new PgNumericNumberBuilder(name, config?.precision, config?.scale) : mode === "bigint" ? new PgNumericBigIntBuilder(name, config?.precision, config?.scale) : new PgNumericBuilder(name, config?.precision, config?.scale);
69
150
  }
70
151
  const decimal = numeric;
71
152
  // Annotate the CommonJS export names for ESM import in node:
72
153
  0 && (module.exports = {
73
154
  PgNumeric,
155
+ PgNumericBigInt,
156
+ PgNumericBigIntBuilder,
74
157
  PgNumericBuilder,
158
+ PgNumericNumber,
159
+ PgNumericNumberBuilder,
75
160
  decimal,
76
161
  numeric
77
162
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/pg-core/columns/numeric.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnyPgTable } from '~/pg-core/table.ts';\nimport { getColumnNameAndConfig } from '~/utils.ts';\nimport { PgColumn, PgColumnBuilder } from './common.ts';\n\nexport type PgNumericBuilderInitial<TName extends string> = PgNumericBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'PgNumeric';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericBuilder<T extends ColumnBuilderBaseConfig<'string', 'PgNumeric'>> extends PgColumnBuilder<\n\tT,\n\t{\n\t\tprecision: number | undefined;\n\t\tscale: number | undefined;\n\t}\n> {\n\tstatic override readonly [entityKind]: string = 'PgNumericBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'string', 'PgNumeric');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumeric<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumeric<MakeColumnConfig<T, TTableName>>(table, this.config as ColumnBuilderRuntimeConfig<any, any>);\n\t}\n}\n\nexport class PgNumeric<T extends ColumnBaseConfig<'string', 'PgNumeric'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumeric';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue(value: unknown): string {\n\t\tif (typeof value === 'string') return value;\n\n\t\treturn String(value);\n\t}\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericConfig =\n\t| { precision: number; scale?: number }\n\t| { precision?: number; scale: number }\n\t| { precision: number; scale: number };\n\nexport function numeric(): PgNumericBuilderInitial<''>;\nexport function numeric(\n\tconfig?: PgNumericConfig,\n): PgNumericBuilderInitial<''>;\nexport function numeric<TName extends string>(\n\tname: TName,\n\tconfig?: PgNumericConfig,\n): PgNumericBuilderInitial<TName>;\nexport function numeric(a?: string | PgNumericConfig, b?: PgNumericConfig) {\n\tconst { name, config } = getColumnNameAndConfig<PgNumericConfig>(a, b);\n\treturn new PgNumericBuilder(name, config?.precision, config?.scale);\n}\n\nexport const decimal = numeric;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA2B;AAE3B,mBAAuC;AACvC,oBAA0C;AAWnC,MAAM,yBAAmF,8BAM9F;AAAA,EACD,QAA0B,wBAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,WAAoB,OAAgB;AAChE,UAAM,MAAM,UAAU,WAAW;AACjC,SAAK,OAAO,YAAY;AACxB,SAAK,OAAO,QAAQ;AAAA,EACrB;AAAA;AAAA,EAGS,MACR,OAC6C;AAC7C,WAAO,IAAI,UAA2C,OAAO,KAAK,MAA8C;AAAA,EACjH;AACD;AAEO,MAAM,kBAAqE,uBAAY;AAAA,EAC7F,QAA0B,wBAAU,IAAY;AAAA,EAEvC;AAAA,EACA;AAAA,EAET,YAAY,OAA6C,QAAuC;AAC/F,UAAM,OAAO,MAAM;AACnB,SAAK,YAAY,OAAO;AACxB,SAAK,QAAQ,OAAO;AAAA,EACrB;AAAA,EAES,mBAAmB,OAAwB;AACnD,QAAI,OAAO,UAAU;AAAU,aAAO;AAEtC,WAAO,OAAO,KAAK;AAAA,EACpB;AAAA,EAEA,aAAqB;AACpB,QAAI,KAAK,cAAc,UAAa,KAAK,UAAU,QAAW;AAC7D,aAAO,WAAW,KAAK,SAAS,KAAK,KAAK,KAAK;AAAA,IAChD,WAAW,KAAK,cAAc,QAAW;AACxC,aAAO;AAAA,IACR,OAAO;AACN,aAAO,WAAW,KAAK,SAAS;AAAA,IACjC;AAAA,EACD;AACD;AAeO,SAAS,QAAQ,GAA8B,GAAqB;AAC1E,QAAM,EAAE,MAAM,OAAO,QAAI,qCAAwC,GAAG,CAAC;AACrE,SAAO,IAAI,iBAAiB,MAAM,QAAQ,WAAW,QAAQ,KAAK;AACnE;AAEO,MAAM,UAAU;","names":[]}
1
+ {"version":3,"sources":["../../../src/pg-core/columns/numeric.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnyPgTable } from '~/pg-core/table.ts';\nimport { type Equal, getColumnNameAndConfig } from '~/utils.ts';\nimport { PgColumn, PgColumnBuilder } from './common.ts';\n\nexport type PgNumericBuilderInitial<TName extends string> = PgNumericBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'PgNumeric';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericBuilder<T extends ColumnBuilderBaseConfig<'string', 'PgNumeric'>> extends PgColumnBuilder<\n\tT,\n\t{\n\t\tprecision: number | undefined;\n\t\tscale: number | undefined;\n\t}\n> {\n\tstatic override readonly [entityKind]: string = 'PgNumericBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'string', 'PgNumeric');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumeric<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumeric<MakeColumnConfig<T, TTableName>>(table, this.config as ColumnBuilderRuntimeConfig<any, any>);\n\t}\n}\n\nexport class PgNumeric<T extends ColumnBaseConfig<'string', 'PgNumeric'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumeric';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue(value: unknown): string {\n\t\tif (typeof value === 'string') return value;\n\n\t\treturn String(value);\n\t}\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericNumberBuilderInitial<TName extends string> = PgNumericNumberBuilder<{\n\tname: TName;\n\tdataType: 'number';\n\tcolumnType: 'PgNumericNumber';\n\tdata: number;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericNumberBuilder<T extends ColumnBuilderBaseConfig<'number', 'PgNumericNumber'>>\n\textends PgColumnBuilder<\n\t\tT,\n\t\t{\n\t\t\tprecision: number | undefined;\n\t\t\tscale: number | undefined;\n\t\t}\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'PgNumericNumberBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'number', 'PgNumericNumber');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumericNumber<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumericNumber<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class PgNumericNumber<T extends ColumnBaseConfig<'number', 'PgNumericNumber'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumericNumber';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericNumberBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue(value: unknown): number {\n\t\tif (typeof value === 'number') return value;\n\n\t\treturn Number(value);\n\t}\n\n\toverride mapToDriverValue = String;\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericBigIntBuilderInitial<TName extends string> = PgNumericBigIntBuilder<{\n\tname: TName;\n\tdataType: 'bigint';\n\tcolumnType: 'PgNumericBigInt';\n\tdata: bigint;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericBigIntBuilder<T extends ColumnBuilderBaseConfig<'bigint', 'PgNumericBigInt'>>\n\textends PgColumnBuilder<\n\t\tT,\n\t\t{\n\t\t\tprecision: number | undefined;\n\t\t\tscale: number | undefined;\n\t\t}\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'PgNumericBigIntBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'bigint', 'PgNumericBigInt');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumericBigInt<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumericBigInt<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class PgNumericBigInt<T extends ColumnBaseConfig<'bigint', 'PgNumericBigInt'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumericBigInt';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericBigIntBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue = BigInt;\n\n\toverride mapToDriverValue = String;\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericConfig<T extends 'string' | 'number' | 'bigint' = 'string' | 'number' | 'bigint'> =\n\t| { precision: number; scale?: number; mode?: T }\n\t| { precision?: number; scale: number; mode?: T }\n\t| { precision?: number; scale?: number; mode: T };\n\nexport function numeric<TMode extends 'string' | 'number' | 'bigint'>(\n\tconfig?: PgNumericConfig<TMode>,\n): Equal<TMode, 'number'> extends true ? PgNumericNumberBuilderInitial<''>\n\t: Equal<TMode, 'bigint'> extends true ? PgNumericBigIntBuilderInitial<''>\n\t: PgNumericBuilderInitial<''>;\nexport function numeric<TName extends string, TMode extends 'string' | 'number' | 'bigint'>(\n\tname: TName,\n\tconfig?: PgNumericConfig<TMode>,\n): Equal<TMode, 'number'> extends true ? PgNumericNumberBuilderInitial<TName>\n\t: Equal<TMode, 'bigint'> extends true ? PgNumericBigIntBuilderInitial<TName>\n\t: PgNumericBuilderInitial<TName>;\nexport function numeric(a?: string | PgNumericConfig, b?: PgNumericConfig) {\n\tconst { name, config } = getColumnNameAndConfig<PgNumericConfig>(a, b);\n\tconst mode = config?.mode;\n\treturn mode === 'number'\n\t\t? new PgNumericNumberBuilder(name, config?.precision, config?.scale)\n\t\t: mode === 'bigint'\n\t\t? new PgNumericBigIntBuilder(name, config?.precision, config?.scale)\n\t\t: new PgNumericBuilder(name, config?.precision, config?.scale);\n}\n\nexport const decimal = numeric;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA2B;AAE3B,mBAAmD;AACnD,oBAA0C;AAWnC,MAAM,yBAAmF,8BAM9F;AAAA,EACD,QAA0B,wBAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,WAAoB,OAAgB;AAChE,UAAM,MAAM,UAAU,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WACb,IAAI,uBAAuB,MAAM,QAAQ,WAAW,QAAQ,KAAK,IACjE,SAAS,WACT,IAAI,uBAAuB,MAAM,QAAQ,WAAW,QAAQ,KAAK,IACjE,IAAI,iBAAiB,MAAM,QAAQ,WAAW,QAAQ,KAAK;AAC/D;AAEO,MAAM,UAAU;","names":[]}
@@ -2,6 +2,7 @@ import type { ColumnBuilderBaseConfig } from "../../column-builder.cjs";
2
2
  import type { ColumnBaseConfig } from "../../column.cjs";
3
3
  import { entityKind } from "../../entity.cjs";
4
4
  import type { AnyPgTable } from "../table.cjs";
5
+ import { type Equal } from "../../utils.cjs";
5
6
  import { PgColumn, PgColumnBuilder } from "./common.cjs";
6
7
  export type PgNumericBuilderInitial<TName extends string> = PgNumericBuilder<{
7
8
  name: TName;
@@ -28,17 +29,71 @@ export declare class PgNumeric<T extends ColumnBaseConfig<'string', 'PgNumeric'>
28
29
  mapFromDriverValue(value: unknown): string;
29
30
  getSQLType(): string;
30
31
  }
31
- export type PgNumericConfig = {
32
+ export type PgNumericNumberBuilderInitial<TName extends string> = PgNumericNumberBuilder<{
33
+ name: TName;
34
+ dataType: 'number';
35
+ columnType: 'PgNumericNumber';
36
+ data: number;
37
+ driverParam: string;
38
+ enumValues: undefined;
39
+ }>;
40
+ export declare class PgNumericNumberBuilder<T extends ColumnBuilderBaseConfig<'number', 'PgNumericNumber'>> extends PgColumnBuilder<T, {
41
+ precision: number | undefined;
42
+ scale: number | undefined;
43
+ }> {
44
+ static readonly [entityKind]: string;
45
+ constructor(name: T['name'], precision?: number, scale?: number);
46
+ }
47
+ export declare class PgNumericNumber<T extends ColumnBaseConfig<'number', 'PgNumericNumber'>> extends PgColumn<T> {
48
+ static readonly [entityKind]: string;
49
+ readonly precision: number | undefined;
50
+ readonly scale: number | undefined;
51
+ constructor(table: AnyPgTable<{
52
+ name: T['tableName'];
53
+ }>, config: PgNumericNumberBuilder<T>['config']);
54
+ mapFromDriverValue(value: unknown): number;
55
+ mapToDriverValue: StringConstructor;
56
+ getSQLType(): string;
57
+ }
58
+ export type PgNumericBigIntBuilderInitial<TName extends string> = PgNumericBigIntBuilder<{
59
+ name: TName;
60
+ dataType: 'bigint';
61
+ columnType: 'PgNumericBigInt';
62
+ data: bigint;
63
+ driverParam: string;
64
+ enumValues: undefined;
65
+ }>;
66
+ export declare class PgNumericBigIntBuilder<T extends ColumnBuilderBaseConfig<'bigint', 'PgNumericBigInt'>> extends PgColumnBuilder<T, {
67
+ precision: number | undefined;
68
+ scale: number | undefined;
69
+ }> {
70
+ static readonly [entityKind]: string;
71
+ constructor(name: T['name'], precision?: number, scale?: number);
72
+ }
73
+ export declare class PgNumericBigInt<T extends ColumnBaseConfig<'bigint', 'PgNumericBigInt'>> extends PgColumn<T> {
74
+ static readonly [entityKind]: string;
75
+ readonly precision: number | undefined;
76
+ readonly scale: number | undefined;
77
+ constructor(table: AnyPgTable<{
78
+ name: T['tableName'];
79
+ }>, config: PgNumericBigIntBuilder<T>['config']);
80
+ mapFromDriverValue: BigIntConstructor;
81
+ mapToDriverValue: StringConstructor;
82
+ getSQLType(): string;
83
+ }
84
+ export type PgNumericConfig<T extends 'string' | 'number' | 'bigint' = 'string' | 'number' | 'bigint'> = {
32
85
  precision: number;
33
86
  scale?: number;
87
+ mode?: T;
34
88
  } | {
35
89
  precision?: number;
36
90
  scale: number;
91
+ mode?: T;
37
92
  } | {
38
- precision: number;
39
- scale: number;
93
+ precision?: number;
94
+ scale?: number;
95
+ mode: T;
40
96
  };
41
- export declare function numeric(): PgNumericBuilderInitial<''>;
42
- export declare function numeric(config?: PgNumericConfig): PgNumericBuilderInitial<''>;
43
- export declare function numeric<TName extends string>(name: TName, config?: PgNumericConfig): PgNumericBuilderInitial<TName>;
97
+ export declare function numeric<TMode extends 'string' | 'number' | 'bigint'>(config?: PgNumericConfig<TMode>): Equal<TMode, 'number'> extends true ? PgNumericNumberBuilderInitial<''> : Equal<TMode, 'bigint'> extends true ? PgNumericBigIntBuilderInitial<''> : PgNumericBuilderInitial<''>;
98
+ export declare function numeric<TName extends string, TMode extends 'string' | 'number' | 'bigint'>(name: TName, config?: PgNumericConfig<TMode>): Equal<TMode, 'number'> extends true ? PgNumericNumberBuilderInitial<TName> : Equal<TMode, 'bigint'> extends true ? PgNumericBigIntBuilderInitial<TName> : PgNumericBuilderInitial<TName>;
44
99
  export declare const decimal: typeof numeric;
@@ -2,6 +2,7 @@ import type { ColumnBuilderBaseConfig } from "../../column-builder.js";
2
2
  import type { ColumnBaseConfig } from "../../column.js";
3
3
  import { entityKind } from "../../entity.js";
4
4
  import type { AnyPgTable } from "../table.js";
5
+ import { type Equal } from "../../utils.js";
5
6
  import { PgColumn, PgColumnBuilder } from "./common.js";
6
7
  export type PgNumericBuilderInitial<TName extends string> = PgNumericBuilder<{
7
8
  name: TName;
@@ -28,17 +29,71 @@ export declare class PgNumeric<T extends ColumnBaseConfig<'string', 'PgNumeric'>
28
29
  mapFromDriverValue(value: unknown): string;
29
30
  getSQLType(): string;
30
31
  }
31
- export type PgNumericConfig = {
32
+ export type PgNumericNumberBuilderInitial<TName extends string> = PgNumericNumberBuilder<{
33
+ name: TName;
34
+ dataType: 'number';
35
+ columnType: 'PgNumericNumber';
36
+ data: number;
37
+ driverParam: string;
38
+ enumValues: undefined;
39
+ }>;
40
+ export declare class PgNumericNumberBuilder<T extends ColumnBuilderBaseConfig<'number', 'PgNumericNumber'>> extends PgColumnBuilder<T, {
41
+ precision: number | undefined;
42
+ scale: number | undefined;
43
+ }> {
44
+ static readonly [entityKind]: string;
45
+ constructor(name: T['name'], precision?: number, scale?: number);
46
+ }
47
+ export declare class PgNumericNumber<T extends ColumnBaseConfig<'number', 'PgNumericNumber'>> extends PgColumn<T> {
48
+ static readonly [entityKind]: string;
49
+ readonly precision: number | undefined;
50
+ readonly scale: number | undefined;
51
+ constructor(table: AnyPgTable<{
52
+ name: T['tableName'];
53
+ }>, config: PgNumericNumberBuilder<T>['config']);
54
+ mapFromDriverValue(value: unknown): number;
55
+ mapToDriverValue: StringConstructor;
56
+ getSQLType(): string;
57
+ }
58
+ export type PgNumericBigIntBuilderInitial<TName extends string> = PgNumericBigIntBuilder<{
59
+ name: TName;
60
+ dataType: 'bigint';
61
+ columnType: 'PgNumericBigInt';
62
+ data: bigint;
63
+ driverParam: string;
64
+ enumValues: undefined;
65
+ }>;
66
+ export declare class PgNumericBigIntBuilder<T extends ColumnBuilderBaseConfig<'bigint', 'PgNumericBigInt'>> extends PgColumnBuilder<T, {
67
+ precision: number | undefined;
68
+ scale: number | undefined;
69
+ }> {
70
+ static readonly [entityKind]: string;
71
+ constructor(name: T['name'], precision?: number, scale?: number);
72
+ }
73
+ export declare class PgNumericBigInt<T extends ColumnBaseConfig<'bigint', 'PgNumericBigInt'>> extends PgColumn<T> {
74
+ static readonly [entityKind]: string;
75
+ readonly precision: number | undefined;
76
+ readonly scale: number | undefined;
77
+ constructor(table: AnyPgTable<{
78
+ name: T['tableName'];
79
+ }>, config: PgNumericBigIntBuilder<T>['config']);
80
+ mapFromDriverValue: BigIntConstructor;
81
+ mapToDriverValue: StringConstructor;
82
+ getSQLType(): string;
83
+ }
84
+ export type PgNumericConfig<T extends 'string' | 'number' | 'bigint' = 'string' | 'number' | 'bigint'> = {
32
85
  precision: number;
33
86
  scale?: number;
87
+ mode?: T;
34
88
  } | {
35
89
  precision?: number;
36
90
  scale: number;
91
+ mode?: T;
37
92
  } | {
38
- precision: number;
39
- scale: number;
93
+ precision?: number;
94
+ scale?: number;
95
+ mode: T;
40
96
  };
41
- export declare function numeric(): PgNumericBuilderInitial<''>;
42
- export declare function numeric(config?: PgNumericConfig): PgNumericBuilderInitial<''>;
43
- export declare function numeric<TName extends string>(name: TName, config?: PgNumericConfig): PgNumericBuilderInitial<TName>;
97
+ export declare function numeric<TMode extends 'string' | 'number' | 'bigint'>(config?: PgNumericConfig<TMode>): Equal<TMode, 'number'> extends true ? PgNumericNumberBuilderInitial<''> : Equal<TMode, 'bigint'> extends true ? PgNumericBigIntBuilderInitial<''> : PgNumericBuilderInitial<''>;
98
+ export declare function numeric<TName extends string, TMode extends 'string' | 'number' | 'bigint'>(name: TName, config?: PgNumericConfig<TMode>): Equal<TMode, 'number'> extends true ? PgNumericNumberBuilderInitial<TName> : Equal<TMode, 'bigint'> extends true ? PgNumericBigIntBuilderInitial<TName> : PgNumericBuilderInitial<TName>;
44
99
  export declare const decimal: typeof numeric;
@@ -37,14 +37,95 @@ class PgNumeric extends PgColumn {
37
37
  }
38
38
  }
39
39
  }
40
+ class PgNumericNumberBuilder extends PgColumnBuilder {
41
+ static [entityKind] = "PgNumericNumberBuilder";
42
+ constructor(name, precision, scale) {
43
+ super(name, "number", "PgNumericNumber");
44
+ this.config.precision = precision;
45
+ this.config.scale = scale;
46
+ }
47
+ /** @internal */
48
+ build(table) {
49
+ return new PgNumericNumber(
50
+ table,
51
+ this.config
52
+ );
53
+ }
54
+ }
55
+ class PgNumericNumber extends PgColumn {
56
+ static [entityKind] = "PgNumericNumber";
57
+ precision;
58
+ scale;
59
+ constructor(table, config) {
60
+ super(table, config);
61
+ this.precision = config.precision;
62
+ this.scale = config.scale;
63
+ }
64
+ mapFromDriverValue(value) {
65
+ if (typeof value === "number")
66
+ return value;
67
+ return Number(value);
68
+ }
69
+ mapToDriverValue = String;
70
+ getSQLType() {
71
+ if (this.precision !== void 0 && this.scale !== void 0) {
72
+ return `numeric(${this.precision}, ${this.scale})`;
73
+ } else if (this.precision === void 0) {
74
+ return "numeric";
75
+ } else {
76
+ return `numeric(${this.precision})`;
77
+ }
78
+ }
79
+ }
80
+ class PgNumericBigIntBuilder extends PgColumnBuilder {
81
+ static [entityKind] = "PgNumericBigIntBuilder";
82
+ constructor(name, precision, scale) {
83
+ super(name, "bigint", "PgNumericBigInt");
84
+ this.config.precision = precision;
85
+ this.config.scale = scale;
86
+ }
87
+ /** @internal */
88
+ build(table) {
89
+ return new PgNumericBigInt(
90
+ table,
91
+ this.config
92
+ );
93
+ }
94
+ }
95
+ class PgNumericBigInt extends PgColumn {
96
+ static [entityKind] = "PgNumericBigInt";
97
+ precision;
98
+ scale;
99
+ constructor(table, config) {
100
+ super(table, config);
101
+ this.precision = config.precision;
102
+ this.scale = config.scale;
103
+ }
104
+ mapFromDriverValue = BigInt;
105
+ mapToDriverValue = String;
106
+ getSQLType() {
107
+ if (this.precision !== void 0 && this.scale !== void 0) {
108
+ return `numeric(${this.precision}, ${this.scale})`;
109
+ } else if (this.precision === void 0) {
110
+ return "numeric";
111
+ } else {
112
+ return `numeric(${this.precision})`;
113
+ }
114
+ }
115
+ }
40
116
  function numeric(a, b) {
41
117
  const { name, config } = getColumnNameAndConfig(a, b);
42
- return new PgNumericBuilder(name, config?.precision, config?.scale);
118
+ const mode = config?.mode;
119
+ return mode === "number" ? new PgNumericNumberBuilder(name, config?.precision, config?.scale) : mode === "bigint" ? new PgNumericBigIntBuilder(name, config?.precision, config?.scale) : new PgNumericBuilder(name, config?.precision, config?.scale);
43
120
  }
44
121
  const decimal = numeric;
45
122
  export {
46
123
  PgNumeric,
124
+ PgNumericBigInt,
125
+ PgNumericBigIntBuilder,
47
126
  PgNumericBuilder,
127
+ PgNumericNumber,
128
+ PgNumericNumberBuilder,
48
129
  decimal,
49
130
  numeric
50
131
  };