-
Notifications
You must be signed in to change notification settings - Fork 0
/
initGuessings.js
39 lines (35 loc) · 921 Bytes
/
initGuessings.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
'use strict'
const { query } = require('./mysql/query')
const faker = require('faker')
const init = async (config) => {
// Initializing load of guessings table
let batch = []
for (let i = 0; i < config.guessingsRecords; i++) {
// Generate fake data of guessings
const guess = {
group_id: faker.random.number({
min: 1,
max: config.groupRecords
}),
game_id: faker.random.number({
min: 1,
max: config.gameRecords
}),
user_id: faker.random.number({
min: 1,
max: config.userRecords
}),
result_a: faker.random.number({
max: 5
}),
result_b: faker.random.number({
max: 5
}),
score: faker.random.arrayElement([25, 50, 75, 100])
}
batch.push(query('INSERT INTO guessings SET ?', guess))
}
const results = await Promise.all(batch)
return results
}
module.exports = init