Overview of ORM Database Tools

Object Relational Mapping (ORM)
Summary
- Concepts of ORM
- Prisma ORM
- Type ORM
- Sequelize ORM
- Micro ORM
References
1. Concepts of ORM
Object-Relational Mapping (ORM) is a technique that lets you query and manipulates data from a database using an object-oriented paradigm. When talking about ORM, most people are referring to a library that implements the Object-Relational Mapping technique, hence the phrase “an ORM”.
An ORM library is a completely ordinary library written in your language of choice that encapsulates the code needed to manipulate the data, so you don’t use SQL anymore; you interact directly with an object in the same language you’re using.
2. Prisma ORM



Postgres Installation with Docker
docker run --name postgresql -e POSTGRES_PASSWORD=admin -p 5432:5432 -d postgres
Prisma Migrate
yarn prisma migrate dev
create product
create category
create product_category
Prisma Studio
yarn prisma studio

Prisma Relations


HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 150
ETag: W/"96-UrprlteTTnqfmSPc6+2Svgk22kw"
Date: Thu, 20 Jan 2022 17:45:34 GMT
Connection: close
{
"id": "70df8552-3b15-4532-ba10-084018283e17",
"id_product": "1d8da63e-c4dc-43e5-87b1-ddf1699dd7f1",
"id_category": "130b29d6-563b-4a73-8c2e-fe1c737ef99c"
}

Create a Product with Category
import { Request, Response } from "express";
import { prismaClient } from "../database/prismaClient";
export class CreateProductWithExistCategory {
async handle(request: Request, response: Response) {
const { name, price, bar_code, id_category } = request.body;
const product = await prismaClient.productCategory.create({
data: {
product: {
create: {
bar_code,
name,
price,
},
},
category: {
connect: {
id: id_category,
},
},
},
});
return response.json(product);
}
}
Demo Prisma Studio
[prisma_decode/Prisma-demo.gif at master · Data-Database/prisma_decode
Contribute to Data-Database/prisma_decode development by creating an account on GitHub.github.com](https://github.com/Data-Database/prisma_decode/blob/master/assets/Prisma-demo.gif "https://github.com/Data-Database/prisma_decode/blob/master/assets/Prisma-demo.gif")
Demo Prisma Studio

Demo Prisma API

3. Type ORM

4. Sequelize ORM

5. Micro ORM
[MikroORM: TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns…
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns.mikro-orm.io](https://mikro-orm.io/ "https://mikro-orm.io/")






