Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
¿Nodejs mysql .query() con Crypto.PBKDF2() diferencia?
const key = CryptoJS.PBKDF2(passphrase, salt, { hasher: CryptoJS.algo.SHA512, keySize: 512/32, iterations: 1000}); const sql = ` SELECT p.PRIVILEGE_LEVEL_NAME, user.USER_ID, user.USER_NAME ,user.PERMITTED_FUNCTIONS FROM user_priviledge_table p INNER JOIN user_account_table user on user.PRIVILEGE_LEVEL = p.PRIVILEGE_LEVEL WHERE user.user_name='${req.body.user_name}' and user.password='${key}' LIMIT 1 `; const [payload] = await db.query(sql);

Sería igual al mismo resultado que:

 const key = CryptoJS.PBKDF2(passphrase, salt, { hasher: CryptoJS.algo.SHA512, keySize: 512/32, iterations: 1000}); const sql = ` SELECT p.PRIVILEGE_LEVEL_NAME, user.USER_ID, user.USER_NAME ,user.PERMITTED_FUNCTIONS FROM user_priviledge_table p INNER JOIN user_account_table user on user.PRIVILEGE_LEVEL = p.PRIVILEGE_LEVEL WHERE user.user_name=? and user.password=? LIMIT 1 `; const [payload] = await db.query(sql, [req.body.user_name, key.toString(CryptoJS.enc.Hex)]);

Quiero saber cómo db.query(sql) podría hechizar el objeto WordArray a String y la diferencia exacta entre estos dos métodos.

¿Cuál sería mejor usar?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El método query() está estructurado de esta manera:

 Connection.prototype.query = function query(sql, values, cb) { var query = Connection.createQuery(sql, values, cb); query._connection = this; if (!(typeof sql === 'object' && 'typeCast' in sql)) { query.typeCast = this.config.typeCast; } if (query.sql) { query.sql = this.format(query.sql, query.values); } if (query._callback) { query._callback = wrapCallbackInDomain(this, query._callback); } this._implyConnect(); return this._protocol._enqueue(query); };

createQuery()

 Connection.createQuery = function createQuery(sql, values, callback) { if (sql instanceof Query) { return sql; } var cb = callback; var options = {}; if (typeof sql === 'function') { cb = sql; } else if (typeof sql === 'object') { options = Object.create(sql); if (typeof values === 'function') { cb = values; } else if (values !== undefined) { Object.defineProperty(options, 'values', { value: values }); } } else { options.sql = sql; if (typeof values === 'function') { cb = values; } else if (values !== undefined) { options.values = values; } } if (cb !== undefined) { cb = wrapCallbackInDomain(null, cb); if (cb === undefined) { throw new TypeError('argument callback must be a function when provided'); } } return new Query(options, cb); };

comprobar archivos


Por otro lado, creo que los dos métodos que describe son técnicamente iguales, la diferencia es la forma en que se pasan los valores, también normalmente en la documentación podemos encontrar 3 formas de invocar query() .

La forma más simple de .query() es .query(sqlString, callback) , donde una cadena SQL es el primer argumento y el segundo es una devolución de llamada:

 connection.query('SELECT * FROM `books` WHERE `author` = "David"', function (error, results, fields) { // error will be an Error if one occurred during the query // results will contain the results of the query // fields will contain information about the returned results fields (if any) });

La segunda forma .query(sqlString, values, callback) aparece cuando se usan valores de marcador de posición (ver valores de consulta de escape):

 connection.query('SELECT * FROM `books` WHERE `author` = ?', ['David'], function (error, results, fields) { // error will be an Error if one occurred during the query // results will contain the results of the query // fields will contain information about the returned results fields (if any) });

La tercera forma .query(options, callback) aparece cuando se usan varias opciones avanzadas en la consulta, como escapar de los valores de la consulta, uniones con nombres de columnas superpuestos, tiempos de espera y conversión de tipos.

 connection.query({ sql: 'SELECT * FROM `books` WHERE `author` = ?', timeout: 40000, // 40s values: ['David'] }, function (error, results, fields) { // error will be an Error if one occurred during the query // results will contain the results of the query // fields will contain information about the returned results fields (if any) });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!