Skip to content
Advertisement

Mikro-ORM: error: there is no parameter $1

Alright so I’ve been trying to search Mikro-ORM’s docs to find how to pass in native sql query params in but I haven’t been able to find anything. After playing with the code a bit this is what it looks like which I think is sort of right but I’m getting this error

My code currently looks like this

Just for some context userData[‘sub’] is the userID of type string from the googleOAuth API. Thank you!

Advertisement

Answer

You need to use ? instead of $1 in the raw query. This is how knex, the underlying query builder, works.

Alternatively you could use knex’s named bindings, which is similar (allows to use one parameter multiple times in the query):

Or the MikroORM query builder has qb.raw() method that is just a shortcut to em.getKnex().raw():

https://github.com/mikro-orm/mikro-orm/blob/master/tests/QueryBuilder.test.ts#L1314-L1319

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement