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

0.9.1 • Public • Published

TypeORM batch

This project provides a simple way to batch select data from any database supported by TypeORM, in two flavors:

  • async generator
  • readable stream

See below for how to use each of them.

Installation

npm install typeorm-batch

Usage

Async generator

import { batch } from "typeorm-batch";
import { Connection, createConnection } from "typeorm";
import { User } from "./User"; // Your entity

const queryBuilder = connection
  .getRepository(User)
  .createQueryBuilder("user")
  .select("user.id");

const usersBatches = batch(queryBuilder, 1_000);
for await (const usersBatch of usersBatches) {
  console.log(usersBatch);
}

Readable stream

import { BatchStream } from "typeorm-batch";
import { Connection, createConnection } from "typeorm";
import { User } from "./User"; // Your entity

const queryBuilder = connection
  .getRepository(User)
  .createQueryBuilder("user")
  .select("user.id");

const usersStream = BatchStream(queryBuilder, 1_000); // usersStream is a Readable stream

usersStream.on("data", (usersBatch) => {
  console.log(usersBatch);
});

Readme

Keywords

none

Package Sidebar

Install

npm i typeorm-batch

Weekly Downloads

3

Version

0.9.1

License

MIT

Unpacked Size

8.67 kB

Total Files

17

Last publish

Collaborators

  • chrisp1tv