AppReports/seeds/fake.js

34 lines
784 B
JavaScript
Raw Normal View History

2020-07-29 20:56:03 +02:00
'use strict';
const faker = require ('faker');
2020-07-31 19:37:30 +02:00
const sn = require ('simplex-noise');
2020-07-29 20:56:03 +02:00
2020-07-31 19:37:30 +02:00
function create_log (index, simplex) {
2020-07-30 18:39:37 +02:00
const data = {
num1: faker.random.number (),
2020-07-31 19:37:30 +02:00
num2: simplex.noise2D (index * 0.1, 0),
num3: simplex.noise2D (index * 0.1, 1000)
2020-07-30 18:39:37 +02:00
};
2020-07-29 20:56:03 +02:00
return {
app: faker.random.word (),
message: faker.random.words (),
2020-07-30 18:39:37 +02:00
data: JSON.stringify (data),
2020-07-29 20:56:03 +02:00
timestamp: faker.date.recent ()
};
}
async function seed (knex) {
2020-08-15 15:19:52 +02:00
// eslint-disable-next-line no-console
2020-07-29 20:56:03 +02:00
console.log ('creating seeds');
2020-07-31 19:37:30 +02:00
const simplex = (new sn);
2020-07-30 22:24:07 +02:00
const log = (Array (20))
2020-07-30 18:39:37 +02:00
.fill (() => null)
2020-07-31 19:37:30 +02:00
.map ((a, index) => create_log (index, simplex));
2020-07-30 18:39:37 +02:00
await knex ('log')
.del ();
await knex.batchInsert ('log', log, 10);
2020-07-29 20:56:03 +02:00
}
module.exports = { seed };