0

I have an example of the following prepared statement code in MSSQL below:

const db = require('../database.js');    

module.exports = {
      getUserName: async name => db(async pool => 
        await pool.request()
        .input('name', dataTypes.VarChar, name)
        .query(`SELECT * FROM person WHERE name = @name;`))
    };

I have been looking at MariaDB docs and online resources but couldn't find the right docs and figure out. Is it possible to create prepared statement in MariaDB? Or Any equivalent to MariaDB?

amstriker
  • 339
  • 7
  • 19
  • 1
    Which connector or driver are you using to connect to the database? If you want a simple option, the [MariaDB NodeJS connector](https://mariadb.com/kb/en/getting-started-with-the-nodejs-connector/) could be an option. – markusjm Sep 27 '21 at 06:04

1 Answers1

2

My node.js knowledge is limited however I suspect its:

const db = require('../database.js');    

module.exports = {
      getUserName: async name => db(async pool => 
        await pool.request()
        .query('SELECT * FROM person WHERE name = ?', name))
    };

Prepared statements are a native part of MariaDB. Ref: based on other answers like this.

Using prepared statement is better than all the explicit escaping that seems common in nodejs documentation.

danblack
  • 12,130
  • 2
  • 22
  • 41