mariadb-corporation / mariadb-connector-nodejs

MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.
GNU Lesser General Public License v2.1
363 stars 93 forks source link

can I disable prepare when use execute ? #270

Closed i18nsite closed 2 months ago

i18nsite commented 5 months ago

as title

rusher commented 5 months ago

connection.execute() is a shortcut of SQL PREPARE + SQL EXECUTE. example :

  const prepare = await conn.prepare('SELECT * FROM mysql.user where host = ?');
  try {
    const res = prepare.execute(['localhost']);    
  } finally {
    prepare.close();
  }

that can be shortened as :

  const res = await conn.execute('SELECT * FROM mysql.user where host = ?', ['localhost']);

In the super rare cases when command are not supported by prepare protocol (for old server there is still some cases) , you can just use connection.query that will do exactly the same without prepare first

rusher commented 2 months ago

closing, since i think this answer the issue. feel free to comment / create new issue if this is not the case