↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

TypeORM: Object-relational mapping with Node.js

The article presents ORM as a way to work with relational data through objects instead of writing SQL directly. It argues that ORMs can reduce boilerplate, improve separation of concerns, and support safer database access in application code.

It then introduces TypeORM as a popular open-source ORM for JavaScript and TypeScript, notes its support for multiple platforms and ORM patterns, and walks through a basic setup with package installation, project initialization, data-source configuration, and running a Node.js app with PostgreSQL.

Reading notes
#

  • ORM lets code interact with relational databases through objects mapped to tables.
  • An ORM can generate data access code from the data model and reduce development time.
  • Encapsulating data access can improve architecture, reusability, and testing.
  • An ORM can help filter data and reduce SQL injection risk.
  • TypeORM is described as an open-source ORM with many GitHub stars and weekly npm downloads.
  • TypeORM supports JavaScript features and runs on Node.js and several other platforms.
  • The article highlights Data Mapper and Active Record as supported ORM patterns.
  • TypeScript decorators make entity classes expressive and easy to read.
  • The setup uses typeorm, reflect-metadata, pg, typescript, @types/node, and ts-node.
  • The project scaffold uses typeorm init and a data-source.ts file for configuration.
  • The app is run after starting the database server, and it inserts and loads a user from the database.