Broks Randolfs Gailītis 1c2d245f7c
Some checks failed
CI / main (push) Failing after 4m54s
Initial places and map implementation
2025-03-15 12:52:17 +02:00

31 lines
868 B
JavaScript

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<void> }
*/
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)),
]);
};