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 🙏

© 2024 – Pkg Stats / Ryan Hefner

typeorm-database-cleaner

v1.0.2

Published

This is a database cleaner for TypeORM. It can use different cleaning strategies (and be extended with any of your own.)

Downloads

237

Readme

TypeORM Database Cleaner

This is a database cleaner for TypeORM. It can use different cleaning strategies (and be extended with any of your own.)

It is primarily useful in testing code where you want to make sure that the database is reset quickly and completely to a blank slate between each test.

For this purpose it provides FastTruncateStrategy which is a quick and effective way of removing all entity data in the database. FastTruncateStrategy is much quicker then doing a full sync, or going through the ORM repository and deleting entities through there.

Warning: Currently this library only works on PostgreSQL!!

Setup

In order to use database cleaner in your project simply install it as a devDependency.

npm install --save-dev typeorm-database-cleaner

Then in the relevant testing files you can setup DatabaseCleaner to use a particular cleaning strategy.

DatabaseCleaner.useStrategy(FastTruncateStrategy); // this is default already

Currently there are 3 cleaning strategies.

  • FastTruncateStrategy - quickly cleans all entity data, this is the fastest cleaner. Your schema should be correct before running this as it does not touch that schema.

  • FullSychronizeStrategy - Drops all tables and fully synchronizes the schema to match your entity structure.

  • NullStrategy - Does nothing.

And then clean your database whenever you like.

DatabaseCleaner.clean(connection); // connection is a typeorm Connection object

Extending

You can create your own cleaning strategy by inheriting from IDatabaseCleanerStrategy and implementing the do(connection:Connection) method. Given the typeorm connection you may do anything needed to clean the database in your own custom strategy.

Development Setup

In order to develop on the library itself, do the following things.

  1. Install and use the correct node version: nvm install && nvm use
  2. cp sample-env .env
  3. Customize environment variables for your database.
  4. Create the testing database: createdb typeorm-database-cleaner-test
  5. Run the tests: npm test

Publish to npm

  1. Bump the version using npm version [major | minor | patch]
  2. Build the modules npm run build
  3. Publish to npm npm publish