Created
January 18, 2020 21:26
-
-
Save Leask/0537aa132778df93b8780d84607cb38a to your computer and use it in GitHub Desktop.
Testing script for this issue: https://github.com/sidorares/node-mysql2/pull/1105 https://github.com/sidorares/node-mysql2/issues/476#issuecomment-264342349
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// CREATE TABLE `test`( | |
// `id` BIGINT(20) NOT NULL AUTO_INCREMENT, | |
// `content` TEXT NOT NULL, | |
// PRIMARY KEY(`id`) | |
// ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; | |
const util = require('util'); | |
const mysql = require('mysql2').createPool({ | |
host: '**********', | |
port: 3306, | |
database: '**********',, | |
user: '**********',, | |
password: '**********',, | |
charset: 'utf8mb4', | |
}); | |
const query = util.promisify(mysql.query.bind(mysql)); | |
const execute = util.promisify(mysql.execute.bind(mysql)); | |
(async () => { | |
// 准备数据 | |
await execute('DELETE FROM `test`'); | |
await execute('INSERT INTO `test` SET `id` = 1, `content` = "anything"'); | |
await execute('INSERT INTO `test` SET `id` = 2, `content` = "anything"'); | |
await execute('INSERT INTO `test` SET `id` = 3, `content` = "anything"'); | |
await execute('INSERT INTO `test` SET `id` = 4, `content` = "anything"'); | |
await execute('INSERT INTO `test` SET `id` = 5, `content` = "anything"'); | |
await execute('INSERT INTO `test` SET `id` = 6, `content` = "anything"'); | |
await execute('INSERT INTO `test` SET `id` = 7, `content` = "anything"'); | |
await execute('INSERT INTO `test` SET `id` = 8, `content` = "anything"'); | |
await execute('INSERT INTO `test` SET `id` = 9, `content` = "anything"'); | |
// 测试前检查 | |
const a = await query('SELECT * FROM `test`'); | |
console.log('ALL: ', a); | |
// 测试直接删除 | |
await execute('DELETE FROM `test` WHERE `id` IN (?)', [[5, 6, 7, 8, 9]]); | |
const b = await query('SELECT * FROM `test`'); | |
console.log('TEST DEL 1: ', b); | |
// // 测试直接删除 | |
// await query('DELETE FROM `test` WHERE `id` IN (?)', [[5, 6, 7, 8, 9]]); | |
// const e = await query('SELECT * FROM `test`'); | |
// console.log('TEST DEL 3: ', e); | |
// // 测试先格式化SQL再删除 | |
// await execute(mysql.format('DELETE FROM `test` WHERE `id` IN (?)', [[5, 6, 7, 8, 9]])); | |
// const c = await query('SELECT * FROM `test`'); | |
// console.log('TEST DEL 2: ', c); | |
process.exit(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment