Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typeorm: Execute raw query with parameters

Tags:

typeorm

I'm trying to execute raw query in typeorm with parameters I tried following queries:

insert into data(id, name, gender) values(?, ?,?)
insert into data(id, name, gender) values($1, $2, $3)
insert into data(id, name, gender) values(:id, :name, :gender)

The typeorm code is:

import { getManager } from 'typeorm';
await getManager().query(query, [1, 'test', 'male']);

What is wrong? Is there any other way?

like image 365
Ashutosh Avatar asked Mar 31 '26 19:03

Ashutosh


1 Answers

Issue solved with this link. It depends on the underlying database which syntax to use.

https://github.com/typeorm/typeorm/issues/881

like image 75
Ashutosh Avatar answered Apr 03 '26 16:04

Ashutosh