diff --git a/changelogs/drizzle-orm/0.17.6.md b/changelogs/drizzle-orm/0.17.6.md new file mode 100644 index 000000000..b83773df2 --- /dev/null +++ b/changelogs/drizzle-orm/0.17.6.md @@ -0,0 +1,3 @@ +Fix circular dependency for query building on all pg and mysql drivers + +Moved all aws data api typings specific logic to dialect from sql to prevent circular dependency issues \ No newline at end of file diff --git a/drizzle-orm/package.json b/drizzle-orm/package.json index 8979ae92f..6bdf7e3e0 100644 --- a/drizzle-orm/package.json +++ b/drizzle-orm/package.json @@ -1,6 +1,6 @@ { "name": "drizzle-orm", - "version": "0.17.5", + "version": "0.17.6", "description": "Drizzle ORM package for SQL databases", "scripts": { "build": "tsc && resolve-tspaths && cp ../README.md package.json dist/", diff --git a/drizzle-orm/src/pg-core/dialect.ts b/drizzle-orm/src/pg-core/dialect.ts index 4b4135e83..ce8396ea6 100644 --- a/drizzle-orm/src/pg-core/dialect.ts +++ b/drizzle-orm/src/pg-core/dialect.ts @@ -1,12 +1,12 @@ import { AnyColumn, Column } from '~/column'; import { MigrationMeta } from '~/migrator'; import { SelectFieldsOrdered } from '~/operations'; -import { AnyPgColumn, PgColumn } from '~/pg-core/columns'; +import { AnyPgColumn, PgColumn, PgDate, PgJson, PgJsonb, PgNumeric, PgTime, PgTimestamp, PgUUID } from '~/pg-core/columns'; import { PgDatabase } from '~/pg-core/db'; import { PgDeleteConfig, PgInsertConfig, PgUpdateConfig, PgUpdateSet } from '~/pg-core/query-builders'; import { PgSelectConfig } from '~/pg-core/query-builders/select.types'; import { AnyPgTable, PgTable } from '~/pg-core/table'; -import { Name, Query, SQL, sql, SQLResponse, SQLSourceParam } from '~/sql'; +import { DriverValueEncoder, Name, Query, QueryTypingsValue, SQL, sql, SQLResponse, SQLSourceParam } from '~/sql'; import { Table } from '~/table'; import { PgSession } from './session'; @@ -248,10 +248,30 @@ export class PgDialect { return sql`insert into ${table} ${insertOrder} values ${valuesSql}${onConflictSql}${returningSql}`; } + prepareTyping(encoder: DriverValueEncoder): QueryTypingsValue { + if ( + encoder instanceof PgJsonb || encoder instanceof PgJson + ) { + return 'json'; + } else if (encoder instanceof PgNumeric) { + return 'decimal'; + } else if (encoder instanceof PgTime) { + return 'time'; + } else if (encoder instanceof PgTimestamp) { + return 'timestamp'; + } else if (encoder instanceof PgDate) { + return 'date'; + } else if (encoder instanceof PgUUID) { + return 'uuid'; + } else { + return 'none'; + } + } + sqlToQuery(sql: SQL): Query { return sql.toQuery({ escapeName: this.escapeName, escapeParam: this.escapeParam, - }); + }, this.prepareTyping); } } diff --git a/drizzle-orm/src/sql/index.ts b/drizzle-orm/src/sql/index.ts index 28e676ead..edb526f37 100644 --- a/drizzle-orm/src/sql/index.ts +++ b/drizzle-orm/src/sql/index.ts @@ -1,5 +1,3 @@ -import { MySqlDate, MySqlDecimal, MySqlJson, MySqlTime, MySqlTimestamp } from '~/mysql-core'; -import { PgDate, PgJson, PgJsonb, PgNumeric, PgTime, PgTimestamp, PgUUID } from '~/pg-core'; import { AnyColumn, Column } from '../column'; import { Table } from '../table'; @@ -40,33 +38,15 @@ export function isSQLWrapper(value: unknown): value is SQLWrapper { && typeof (value as any).getSQL === 'function'; } -function prepareTyping(encoder: DriverValueEncoder): QueryTypingsValue { - if ( - encoder instanceof PgJsonb || encoder instanceof PgJson - || encoder instanceof MySqlJson - ) { - return 'json'; - } else if (encoder instanceof MySqlDecimal || encoder instanceof PgNumeric) { - return 'decimal'; - } else if (encoder instanceof PgTime || encoder instanceof MySqlTime) { - return 'time'; - } else if (encoder instanceof PgTimestamp || encoder instanceof MySqlTimestamp) { - return 'timestamp'; - } else if (encoder instanceof PgDate || encoder instanceof MySqlDate) { - return 'date'; - } else if (encoder instanceof PgUUID) { - return 'uuid'; - } else { - return 'none'; - } -} - export class SQL implements SQLWrapper { declare protected $brand: 'SQL'; constructor(readonly queryChunks: Chunk[]) {} - toQuery({ escapeName, escapeParam }: BuildQueryConfig): Query { + toQuery( + { escapeName, escapeParam }: BuildQueryConfig, + prepareTyping?: (encoder: DriverValueEncoder) => QueryTypingsValue, + ): Query { const params: unknown[] = []; const typings: QueryTypingsValue[] = []; @@ -84,7 +64,7 @@ export class SQL implements SQLWrapper { return escapeName(chunk.table[Table.Symbol.Name]) + '.' + escapeName(chunk.name); } else if (chunk instanceof Param) { params.push(chunk.encoder.mapToDriverValue(chunk.value)); - typings.push(prepareTyping(chunk.encoder)); + if (typeof prepareTyping !== 'undefined') typings.push(prepareTyping(chunk.encoder)); return escapeParam(params.length - 1, chunk.value); } else { const err = new Error('Unexpected chunk type!');