Coder Social home page Coder Social logo

nest_boilerplate's Introduction

Nest Logo

pipeline status

coverage report

Latest Release

Description

Nest framework TypeScript starter repository.

Start server with docker compose

$ pnpm install
$ docker compose up -d

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

TYPEORM config start

Configuring package.json

NOTE: the migration script runs inside the Docker container

To be able to run these commands, it's best to expose them in your package.json file in the scripts section.

Copy and paste the below:

{
	"scripts": {
		"migration:create": "ts-node -r tsconfig-paths/register src/cli.ts typeorm migration:create",
		"migration:generate": "ts-node -r tsconfig-paths/register src/cli.ts typeorm migration:generate",
		"migration:run": "ts-node -r tsconfig-paths/register src/cli.ts typeorm migration:run",
		"migration:revert": "ts-node -r tsconfig-paths/register src/cli.ts typeorm migration:revert",
		"migration:show": "ts-node -r tsconfig-paths/register src/cli.ts typeorm migration:show",
		"schema:drop": "ts-node -r tsconfig-paths/register src/cli.ts typeorm schema:drop",
		"schema:log": "ts-node -r tsconfig-paths/register src/cli.ts typeorm schema:log",
		"schema:sync": "ts-node -r tsconfig-paths/register src/cli.ts typeorm schema:sync",
		"typeorm:cache:clear": "ts-node -r tsconfig-paths/register src/cli.ts typeorm cache:clear",
		"typeorm:query": "ts-node -r tsconfig-paths/register src/cli.ts typeorm query",
		"typeorm:version": "ts-node -r tsconfig-paths/register src/cli.ts typeorm version"
	}
}

If you are not using NestJS's monorepo and you use relative paths for imports, as well as no aliases, you may omit the -r tsconfig-paths/register part of these commands, for readability.

If you have integrated nest-commander via a different file than src/cli.ts then replace it here.

Usage

Now you have access to the following commands:

  • npm run migration:create MigrationName - create an empty migration with the given name
  • npm run migration:generate MigrationName - automatically create a migration with the given name
  • npm run migration:run - run pending migrations
  • npm run migration:revert -- revert last migration
  • npm run migration:show - show list of migrations and their status
  • npm run schema:drop - drop the db schema
  • npm run schema:log - show diff between db schema and codebase
  • npm run schema:sync - sync the db schema with the codebase
  • npm run typeorm:cache:clear - clear query cache
  • npm run typeorm:query "SELECT * FROM migrations" - run an SQL query
  • npm run typeorm:version - check TypeORM version

Disclaimer

This package simply reimplements the TypeORM CLI commands in a "NestJS-way", injecting the application's DataSource into the commands, so the configuration can be fully reused. The actual command code is 100% based on the original commands and some small features might be missing.

For full visibility:

  • the commands use the default DataSource (connection) to the database. Support for handling multiple connections / specifying which connection should be used in on TODO list.
  • migration:generate and migration:create only supports TypeScript migrations, no JS files
  • Output coloring has been removed for simplicity. It might be added later.
  • Error handling is simplified and errors simply uncaught.

TYPEORM config end

nest_boilerplate's People

Contributors

leon220189 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.