2

I build api use hapi js and postgresql with ORM objection js (knexjs). I create own function in postgresql with two argument. When I try to call my function use objection .raw it's doesn't work. This one of the codes that I have tried and it doesn't work:

let _data = await Model.knex().raw('select * from fn_user_profiling('+ Model.knex().raw('??', ['840018']).toString() +', ' + Model.knex().raw('??', ['human capital']).toString() + ')');

This the error when I run the code:

select * from fn_user_profiling("840018", "human capital") - column "840018" does not exist

I try to follow this thred in this link, but not work for me.

I hope advance can help to give the answer or clue to solve this problems.

Thank you very much.

Sukma Saputra
  • 1,539
  • 17
  • 32

1 Answers1

0

I found the answer. I use objection js to call knex raw.

let _data = await Model.knex().raw('select * from function_name(?, ?)', [arg_1, arg_2]);

I hope this can help someone.

Sukma Saputra
  • 1,539
  • 17
  • 32
  • 1
    Used your solution. got this. `calling knex without a tableName is deprecated. Use knex.queryBuilder() instead. (node:18) UnhandledPromiseRejectionWarning: TypeError: databaseProvider.knex(...).raw is not a function` – Aditya Gaddhyan Apr 04 '21 at 01:56