Using the WITH clause with inserts
Hi. I'm trying to use the WITH clause with inserts.
Unfortunately, I'm seeing the following error.
Looks like
const createdAddress = this.drizzleService.db
.$with('created_address')
.as(
this.drizzleService.db
.insert(databaseSchema.addresses)
.values(user.address)
.returning(),
);
const createdAddress = this.drizzleService.db
.$with('created_address')
.as(
this.drizzleService.db
.insert(databaseSchema.addresses)
.values(user.address)
.returning(),
);
$with()
is not ready to use with inserts. Or maybe I'm missing something?2 Replies
error TS2345: Argument of type 'Omit<PgInsertBase<PgTableWithColumns<{ name: "addresses"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "addresses"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; street: PgCo...' is not assignable to parameter of type 'TypedQueryBuilder<ColumnsSelection, unknown> | ((qb: QueryBuilder) => TypedQueryBuilder<ColumnsSelection, unknown>)'.
Type 'Omit<PgInsertBase<PgTableWithColumns<{ name: "addresses"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "addresses"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; street: PgCo...' is not assignable to type 'TypedQueryBuilder<ColumnsSelection, unknown>'.
Types of property '_' are incompatible.
Property 'selectedFields' is missing in type '{ readonly dialect: "pg"; readonly table: PgTableWithColumns<{ name: "addresses"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "addresses"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; ...' but required in type '{ selectedFields: ColumnsSelection; result: unknown; }'.
67 this.drizzleService.db
~~~~~~~~~~~~~~~~~~~~~~
68 .insert(databaseSchema.addresses)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 .values(user.address)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70 .returning(),
~~~~~~~~~~~~~~~~~~~~~~
node_modules/drizzle-orm/query-builders/query-builder.d.ts:6:9
6 selectedFields: TSelection;
~~~~~~~~~~~~~~
'selectedFields' is declared here.
error TS2345: Argument of type 'Omit<PgInsertBase<PgTableWithColumns<{ name: "addresses"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "addresses"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; street: PgCo...' is not assignable to parameter of type 'TypedQueryBuilder<ColumnsSelection, unknown> | ((qb: QueryBuilder) => TypedQueryBuilder<ColumnsSelection, unknown>)'.
Type 'Omit<PgInsertBase<PgTableWithColumns<{ name: "addresses"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "addresses"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; street: PgCo...' is not assignable to type 'TypedQueryBuilder<ColumnsSelection, unknown>'.
Types of property '_' are incompatible.
Property 'selectedFields' is missing in type '{ readonly dialect: "pg"; readonly table: PgTableWithColumns<{ name: "addresses"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "addresses"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; ...' but required in type '{ selectedFields: ColumnsSelection; result: unknown; }'.
67 this.drizzleService.db
~~~~~~~~~~~~~~~~~~~~~~
68 .insert(databaseSchema.addresses)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 .values(user.address)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70 .returning(),
~~~~~~~~~~~~~~~~~~~~~~
node_modules/drizzle-orm/query-builders/query-builder.d.ts:6:9
6 selectedFields: TSelection;
~~~~~~~~~~~~~~
'selectedFields' is declared here.
Hi, I checked the declaration files and it seems it only support select query as the subquery as of now