Thursday, 18 May 2017

Is is possible to use :bind (oracle style) in a MYSQL query with Node?

I am migrating the database of my node.js/typescript project from Oracle to MYSQL. My queries/dml in Oracle are all bind in this style

conn.execute('select date, name from table
              where id = :ID and field = :VAR', 
             {ID: variable1, VAR: variable2});

When using MYSQL I found this:

connection.query('select date, name from table
                  where id = ? and field = ?',
                  [variable1, variable2]);

The second approach is worse for me because: 1- I would to rewrite a lot of sql calls in my code 2- I think the first approach is much more reliable, as you are not concerning of having unpredictable results due to changing in SQL

Although I found some mention to the first style here, it couldn't make it work

Any tips?



via Encoder

No comments:

Post a Comment