const { fakerLV : faker } = require('@faker-js/faker'); const PLACE_COUNT = 1000; const BBOX_RIGA = [23.755875,56.815914,24.466553,57.067617]; const [ BBOX_MIN_LAT, BBOX_MIN_LON, BBOX_MAX_LAT, BBOX_MAX_LON ] = BBOX_RIGA; /** * @param { import("knex").Knex } knex * @returns { Promise } */ exports.seed = async function(knex) { const createPlace = () => { const coords = [ faker.location.latitude({ min: BBOX_MIN_LAT, max: BBOX_MAX_LAT }), faker.location.longitude({ min: BBOX_MIN_LON, max: BBOX_MAX_LON }) ]; return { name: faker.company.name(), coordinates: knex.raw('ST_SetSRID(ST_MakePoint(?, ?), 4326)', coords), } }; // Deletes ALL existing entries await knex('places').del() await knex('places').insert([ ...new Array(PLACE_COUNT).fill(() => createPlace()).map((fn, i) => fn(i)), ]); };