-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfakeDataTrigger.js
54 lines (40 loc) · 1.3 KB
/
fakeDataTrigger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const myFaker = require('faker')
const mySQL = require('mysql')
const connection = mySQL.createConnection({
host: 'localhost',
user: 'root',
password: 'tina',
database: 'join_us',
})
// // SELECTING DATA
// const q = 'SELECT COUNT(*) AS total_users FROM users'
// connection.query(q, function (error, results, fields) {
// if (error) throw error
// console.log(results[0].total_users)
// })
// // INSERTING DATA
// const person = {email: myFaker.internet.email(), created_at: myFaker.date.post()}
// connection.query('INSERT INTO users SET ?', person, function(error, result) {
// if (error) throw error
// console.log(result)
// })
// connection.query('SELECT * FROM users', function(error, result) {
// if (error) throw error
// console.log(result)
// })
// INSERTING 500
const data = []
for (let index = 0; index < 600; index++) {
data.push([myFaker.internet.email(), myFaker.date.past()])
}
const q = 'INSERT INTO users (email, created_at) VALUES ?'
connection.query(q, [data], function (error, results) {
console.log(error)
console.log(results)
})
const q1 = 'SELECT COUNT(*) AS total_users FROM users'
connection.query(q1, function (error, results, fields) {
if (error) throw error
console.log('Total Count: ', results[0].total_users)
})
connection.end()