0.7.0 • Published 2 years ago

@kingdom-sdk/orm v0.7.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

🏰 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

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:

DatabaseDriver (npm package)TYPEORM_CONNECTION
MySQLmysqlmysql
MariaDBmysqlmariadb
PostgreSQLpgpostgres
CockroachDBpgcockroachdb
SQLitesqlite3sqlite

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