npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

small-typeorm-persist-thread

v0.1.1

Published

Explicit persistence thread for TypeORM with dedicated QueryRunner, batching, transaction control and optional parallel flush.

Readme

small-typeorm-persist-thread

Explicit persistence thread for TypeORM with:

  • dedicated QueryRunner
  • explicit transaction control
  • queued operations
  • grouped save/remove/softRemove
  • high-performance insert/update/upsert/delete
  • optional parallel flush outside transactions
  • operation merging for compatible explicit operations

Install

npm install small-typeorm-persist-thread

typeorm must already be installed in your project.

Why

TypeORM already provides QueryRunner, transactions, and persistence APIs. This package adds an explicit persistence thread abstraction that:

  • keeps one database connection open during a unit of work
  • accumulates operations
  • flushes them in a controlled way
  • favors explicit intent over unreliable entity-state detection

Quick example

import { createPersistenceThread } from "typeorm-persist-thread";

const thread = await createPersistenceThread(dataSource);

try {
  await thread.startTransaction();

  thread.insert(User, [
    { email: "[email protected]", name: "A" },
    { email: "[email protected]", name: "B" }
  ]);

  thread.update(User, { active: false }, { active: true });

  thread.upsert(
    User,
    [{ externalId: "42", name: "Updated" }],
    ["externalId"]
  );

  await thread.flush();
  await thread.commit();
} catch (error) {
  await thread.rollback();
  throw error;
} finally {
  await thread.close();
}

Parallel flush

await thread.flush({ singleConnection: false });

Rules:

  • default is singleConnection: true
  • if a transaction is active, flush is always forced to single connection
  • parallel mode is best-effort and should be used only for independent operations
  • parallel mode is not globally atomic

Best-effort entity mode

thread.persist(userEntity);
thread.remove(oldSessionEntity);
thread.softRemove(oldTokenEntity);

await thread.flush();

This mode is convenient but less explicit than insert/update/upsert/delete.

Optimization

The thread merges compatible explicit operations before execution:

  • multiple insert(Entity, rows) become one merged insert per target
  • multiple upsert(Entity, rows, conflictPaths, options) become one merged upsert when target and conflict config match
  • multiple update(Entity, criteria, partial) may become one merged update when:
    • target is the same
    • partial is the same
    • criteria are simple flat objects with the same shape
  • multiple delete(Entity, criteria) may become one merged delete when:
    • target is the same
    • criteria are simple flat objects with the same shape

Example:

thread.insert(User, { email: "[email protected]" });
thread.insert(User, { email: "[email protected]" });
thread.insert(User, { email: "[email protected]" });

await thread.flush();

This becomes one merged insert call.

Caveat for merged update/delete

Merged update/delete only apply to simple criteria objects such as:

{ id: 1 }
{ email: "[email protected]" }
{ shopId: 10, active: false }

Complex operators, arrays, nested objects or custom expressions are kept as individual operations.

API

Lifecycle

  • startTransaction()
  • flush(options?)
  • commit()
  • rollback()
  • close()

Explicit operations

  • insert(Entity, rows)
  • update(Entity, criteria, partial)
  • upsert(Entity, rows, conflictPaths, options?)
  • delete(Entity, criteria)

Best-effort entity operations

  • persist(entity)
  • remove(entity)
  • softRemove(entity)

Notes

  • close() must always be called.
  • commit() flushes before committing.
  • rollback() clears queued operations and rolls back the current SQL transaction if active.
  • upsert() support depends on your TypeORM driver.
  • flush({ singleConnection: false }) may execute groups in parallel on multiple connections.

License

MIT