AppReports/seeds/fake.js
2020-07-31 19:37:30 +02:00

33 lines
743 B
JavaScript

'use strict';
const faker = require ('faker');
const sn = require ('simplex-noise');
function create_log (index, simplex) {
const data = {
num1: faker.random.number (),
num2: simplex.noise2D (index * 0.1, 0),
num3: simplex.noise2D (index * 0.1, 1000)
};
return {
app: faker.random.word (),
message: faker.random.words (),
data: JSON.stringify (data),
timestamp: faker.date.recent ()
};
}
async function seed (knex) {
console.log ('creating seeds');
const simplex = (new sn);
const log = (Array (20))
.fill (() => null)
.map ((a, index) => create_log (index, simplex));
await knex ('log')
.del ();
await knex.batchInsert ('log', log, 10);
}
module.exports = { seed };