ORM module to provide persistence to DDD applications in TypeScript through a relational database.
See the changelog to know all the features supported.
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
- 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.
- Kingdom SDK Core: DDD domain models.
- Inversify: Dependency injection.
- TypeORM: ORM framework.
- Reflect metadata: Metadata reflection required by TypeORM.
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"
You can test sorts of TypeScript code interactively through the ts-node
executable:
yarn ts-node
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.
- 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
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.