Seeding Your Database


DenoGres allows data to be populated to the PostgreSQL schema through data seeding. This is primarily useful during database design/development (i.e. an application requires a certain amount of data to function properly) Create a seed.ts within the project root directory, and execute the following CLI command:


denogres --db-seed

The associated database schema will be pre-populated based on the user's seed.ts file.



Seed.ts file structure


Seed data is stored within the seed.ts file as a collection of variables assigned to arrays of objects. The variable name used should correspond to the table within your database schema, and each object within the array is associated to a row of data to be inserted within your database. Each object contains properties which are tied to columns within those particular tables, and the property values are the desired values for those columns.


const people = [
  {
    name: "Anthony",
    species_id: 2
  },
  {
    name: "Eddie",
    species_id: 3
  },
  {
    name: "Carlos",
    species_id: 1
  },
  {
    name: "Henry",
    species_id: 1
  },
];