Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)}`
)
}
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
}
const init = async pool => {
await connect(pool)
if (pool.disposed) {
throw new Error('Adapter is disposed')
}
await pool.connection.execute(`CREATE TABLE IF NOT EXISTS ${escapeId(
pool.tableName
)} (
${escapeId('SnapshotKey')} MEDIUMBLOB NOT NULL,
${escapeId('SnapshotContent')} LONGBLOB,
PRIMARY KEY(${escapeId('SnapshotKey')}(255))
)`)
}