How to use the mysql2.escape function in mysql2

To help you get started, we’ve selected a few mysql2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reimagined / resolve / packages / adapters / snapshot-adapters / resolve-snapshot-mysql / src / index.js View on Github external
pool.counters.set(snapshotKey, 0)
  }

  if (pool.counters.get(snapshotKey) < pool.bucketSize) {
    pool.counters.set(snapshotKey, pool.counters.get(snapshotKey) + 1)
    return
  }
  pool.counters.set(snapshotKey, 0)

  const stringContent = JSON.stringify(content)

  await pool.connection.execute(
    `INSERT INTO ${escapeId(pool.tableName)}(${escapeId(
      'SnapshotKey'
    )}, ${escapeId('SnapshotContent')})
    VALUES(${escape(snapshotKey)}, ${escape(stringContent)})
    ON DUPLICATE KEY UPDATE
    ${escapeId('SnapshotContent')} = ${escape(stringContent)}`
  )
}
github reimagined / resolve / packages / adapters / snapshot-adapters / resolve-snapshot-mysql / src / index.js View on Github external
const loadSnapshot = async (pool, snapshotKey) => {
  await connect(pool)
  if (pool.disposed) {
    throw new Error('Adapter is disposed')
  }

  const [rows] = await pool.connection.execute(
    `SELECT ${escapeId('SnapshotContent')} FROM ${escapeId(pool.tableName)}
   WHERE ${escapeId('SnapshotKey')}= ${escape(snapshotKey)} `
  )
  const content = rows.length > 0 ? rows[0].SnapshotContent.toString() : null
  return content != null ? JSON.parse(content) : null
}