barreller
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Barreller

Ever wanted to populate a postgres db with tons of fake data? Well, barreller does that.

Barreller prescribes a way to define your tables, column values, and relationships, and then import infinite data into postgres.

Inspiration came from wanting to create lots of fake data, but being constained by maintaining the relationships between that data. Especially when sometimes those relationships depend on server-side generated primary keys.

As of this writing - very much a Work In Progress... But it does work!

Example usage:

// define the type for the table
type Food = {
  foodId: string;
  calories: number;
}
 
// define columns
const foodColumnId: ColumnDefinition<FoodTable, 'foodId'> = {
  // name equals the table's column name
  name: 'food_id',
 
  // prop is optional and will be the key used when generating the data locally
  prop: 'foodId',
 
  // value can be a constant (i.e. a string, number, void, date, etc.)
  // or it can be a function and is invoked each time a row is generated
  value() { return faker.random.word(); }
};
 
const foodColumnCalories: ColumnDefinition<FoodTable, 'calories'> = {
  name: 'calories',
  value: 100
};
 
const foodColumns: ColumnDefinitions<FoodTable> = [
  foodColumnId,
  foodColumnCalories
];
 
const barrel = new Barrel({ pgConnectionObject });
 
// 'food' is the table name and it is also the string used to generate rows
barrel.addTable('food', foodColumns);
 
// this queues up the data to be inserted, but does NOT insert it
barrel.generateRow('food');
 
// inserts any queued up data. This is an async function.
barrel.insert();
 

TODO

  • finish the abstract Barrel class
    • connect method
    • disconnect method
  • Convert current Barrel class to PostgresBarrel as subclass of Barrel
  • Move driver implementation into drivers/pg.ts
  • support generatedKey(tableName, columnName) for server generated private keys.
  • consider batch.insertFunction as a deferred promise object

Readme

Keywords

none

Package Sidebar

Install

npm i barreller

Weekly Downloads

3

Version

0.0.2

License

MIT

Unpacked Size

75.5 kB

Total Files

38

Last publish

Collaborators

  • joebartels