Socket
Socket
Sign inDemoInstall

@nestjs/typeorm

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestjs/typeorm

Nest - modern, fast, powerful node.js web framework (@typeorm)


Version published
Weekly downloads
882K
decreased by-2.05%
Maintainers
2
Weekly downloads
 
Created

What is @nestjs/typeorm?

@nestjs/typeorm is an integration package for NestJS that provides seamless integration with TypeORM, a popular ORM (Object-Relational Mapper) for TypeScript and JavaScript. It allows developers to easily manage database connections, entities, repositories, and perform database operations in a structured and efficient manner.

What are @nestjs/typeorm's main functionalities?

Database Connection

This feature allows you to establish a connection to a database using TypeORM's `createConnection` method. You can specify the database type, host, port, username, password, and other connection options.

const connection = await createConnection({
  type: 'mysql',
  host: 'localhost',
  port: 3306,
  username: 'test',
  password: 'test',
  database: 'test',
  entities: [__dirname + '/**/*.entity{.ts,.js}'],
  synchronize: true,
});

Entity Definition

Entities in TypeORM are classes that map to database tables. This feature allows you to define entities using decorators like `@Entity`, `@Column`, and `@PrimaryGeneratedColumn`.

import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column()
  age: number;
}

Repository Pattern

The repository pattern in TypeORM allows you to interact with the database using repositories. This feature demonstrates how to use the `@InjectRepository` decorator to inject a repository and perform CRUD operations.

import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { User } from './user.entity';

@Injectable()
export class UserService {
  constructor(
    @InjectRepository(User)
    private userRepository: Repository<User>,
  ) {}

  findAll(): Promise<User[]> {
    return this.userRepository.find();
  }

  findOne(id: string): Promise<User> {
    return this.userRepository.findOne(id);
  }

  async remove(id: string): Promise<void> {
    await this.userRepository.delete(id);
  }
}

Other packages similar to @nestjs/typeorm

FAQs

Package last updated on 07 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc