Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Created October 3, 2017 03:45
Show Gist options
  • Save alextanhongpin/ed262a584e411b5cc120e36e80c748f1 to your computer and use it in GitHub Desktop.
Save alextanhongpin/ed262a584e411b5cc120e36e80c748f1 to your computer and use it in GitHub Desktop.
Simple mysql script for inserting fake data
const faker = require('faker')
const mysql = require('mysql2/promise')
// function createRow () {
// return {
// column: faker.database.column(),
// type: faker.database.type(),
// collation: faker.database.collation(),
// engine: faker.database.engine()
// }
// }
async function main () {
// create the connection to database
const connection = await mysql.createConnection({
host: '',
user: '',
database: '',
password: ''
})
// const ok = await connection.query('UPDATE `test` SET field = ? WHERE id >= ?', ['hello', 1000])
// const ok = await connection.query('DELETE FROM `test` WHERE id >= ?', [1000])
const ok = await connection.query('INSERT INTO `test` SET ?', { id: 1001, field: 'hello' })
// const [ rows ] = await connection.execute('SELECT * FROM `test`')
return 'listening to port *:3000'
}
main()
.then(console.log)
.catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment