Skip to content

A library for populate large amounts of data to PostgreSQL database with TypeScript

License

Notifications You must be signed in to change notification settings

peeeuzin/pgbulk

Repository files navigation

pgbulk

GitHub License GitHub Issues or Pull Requests

What's pgbulk?

A library for bulk inserts into PostgreSQL with TypeScript, you just need to parse it.

Populate can be used for bulk insert CSV files into PostgreSQL with performance.

Installation

You can install the package using npm:

# npm
npm install pgbulk 

# yarn
yarn add pgbulk

# pnpm
pnpm add pgbulk

Example

import { PGBulk } from 'pgbulk';

class Users extends PGBulk {
  constructor(connectionURL: string) {
    super({
      connection: {
        connectionString: connectionURL,
      },
      strategy: "csv",
      tables: {
        users: [
          {
            databaseColumn: "id",
            type: "TEXT",
          },

          {
            databaseColumn: "name",
            type: "TEXT",
          },

          {
            databaseColumn: "nickname",
            csvColumn: "aka",
            type: "TEXT",
          },
        ]
      },
      allowDisableIndexes: true,
      allowDisableForeignKeys: true,
    })

    this.register("pathto/data", "users-*.csv");
  },

  await parse(row: Row) {
    // do some parsing thing
    // ...
    return row
  }
}

const usersPopulate = new Users("<postgres_url>");

await usersPopulate.start();
await usersPopulate.finish();

About

A library for populate large amounts of data to PostgreSQL database with TypeScript

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published