Created
October 3, 2017 03:45
-
-
Save alextanhongpin/ed262a584e411b5cc120e36e80c748f1 to your computer and use it in GitHub Desktop.
Simple mysql script for inserting fake data
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
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