Learning how to work with tree entities in TypeORM
- Departments CRUD
In order to understand the entities, I've created the following database model:
You need to install Node.js and Yarn first, then in order to clone the project via HTTPS, run this command:
git clone https://github.com/cunhaedu/typeorm-tree-entities.git
Install dependencies
yarn install
Or
npm install
Create your environment variables based on the examples of .env.example
cp .env.example .env
Setup a database
Install Postgres to create a database and create a database, then you should modify the .env
and ormconfig.json
with your credentials
Run the transactions in order to configure the database schema:
yarn typeorm migration:run
Run the following command in order to start the application in a development environment:
yarn dev
Run the following command in order to convert the .ts file to .js file in a folder called dist:
yarn build
Run the following command in order to start the application in a production environment:
yarn start
Check the following status codes in this API:
Status Code | Description |
---|---|
200 | OK |
400 | BAD REQUEST |
404 | NOT FOUND |
500 | INTERNAL SERVER ERROR |
Question: What patterns of tree entities are used in this project?
Answer: For now, this project use just the closure-table, that are the best way to read and write tree relations. In future, it'll contain more use examples of another patterns.
Question: What are the technologies used in this project?
Answer: The technologies used in this project are NodeJS + Express Framework to handle the server and TypeORM
To get more info, please see this section of typeorm documentation about tree entities.