Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@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)

  • 8.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
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 02 Jun 2022

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc