Skip to content

ORM module to provide persistence to DDD applications in TypeScript through a relational database

License

Notifications You must be signed in to change notification settings

t10d/kingdom-node-sdk-orm

Repository files navigation

🏰 Kingdom SDK: ORM module

ORM module to provide persistence to DDD applications in TypeScript through a relational database.

Features

See the changelog to know all the features supported.

Installation

Use the package manager npm to install @kingdom-sdk/orm.

npm install @kingdom-sdk/orm

You can use yarn as well.

yarn add @kingdom-sdk/orm

Development Dependencies

  • TypeScript: Add support to static typing.
  • TS node: TypeScript interactive shell (REPL).
  • TS config paths: Simplify imports using an custom "@".
  • ESLint: Style and code enforcement.
  • Prettier: Style enforcement.
  • Babel: JS compiler.
  • Husky: Git hooks utility (pre-commit).
  • Lint staged: Run style check only for staged files (pre-commit).
  • Jest: Testing framework.

Production Dependencies

Adding a Git hook

After installing the dependencies, automatically the script prepare will set up the husky to git hooks.

To add a script to be run before every commit (such as code enforcement), follow the example below or edit by hand the pre-commit file.

yarn husky add .husky/pre-commit "yarn lint-staged"

REPL

You can test sorts of TypeScript code interactively through the ts-node executable:

yarn ts-node

Setup a database

This is a wrapper to TypeORM, you have to install the database driver as dependencys and configure the environment variable TYPEORM_CONNECTION.

Follow the cheat-sheet to match your needs:

Database Driver (npm package) TYPEORM_CONNECTION
MySQL mysql mysql
MariaDB mysql mariadb
PostgreSQL pg postgres
CockroachDB pg cockroachdb
SQLite sqlite3 sqlite

See the TypeORM documentation to check other supported databases.

Database Migrations

  • To create manually:
typeorm migration:create -n <name-without-spaces>
  • To auto-generate according to models:
// typeorm migration:generate -n <name-without-spaces>
  • To run the pending migrations:
// typeorm migration:run
  • To revert the last migration:
// typeorm migration:revert

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

About

ORM module to provide persistence to DDD applications in TypeScript through a relational database

Resources

License

Stars

Watchers

Forks

Packages

No packages published