Skip to content

ESnark/typeorm-mapped-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b342379 · Jan 13, 2025

History

16 Commits
Jul 14, 2024
Jan 13, 2025
Feb 12, 2024
Feb 3, 2024
Feb 3, 2024
Jan 13, 2025
Feb 3, 2024
Feb 12, 2024
Jul 14, 2024
Jan 13, 2025
Jul 14, 2024
Jul 14, 2024

Repository files navigation

typeorm-mapped-types presents a new way to manage TypeORM entities. You can prototype entities that reflect actual database tables and create new entities appropriate for your domain as needed.

This module is based on @nestjs/mapped-types. However, unlike @nestjs/mapped-types, it does not support @nestjs/swagger but only the typeorm decorator. Future versions may include support for @nestjs/swagger.

Available mapped types:

  • PickType - constructs a new type (class) by picking a set of properties from an input type
  • OmitType - constructs a type by picking all properties from an input type and then removing a particular set of keys
  • IntersectionType - (Not implemented) combines two types into one new type

How to use

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

export class UserModel {
  @PrimaryColumn()
  id: number;

  @Column()
  email: string;

  /** no need for most cases */
  @Column()
  privacyData: string;
}
import { PickType } from '@esnark/typeorm-mapped-types';
import { UserModel } from './user-model';

@Entity('user')
export class QueriedUser extends PickType(UserModel, ['id', 'email'] as const) {}