실험 환경
- DB: postgreSQL
- ORM: typeorm (GraphQL)
코드
- 타입 변경전
import { ObjectType, Field } from '@nestjs/graphql';
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from 'typeorm';
@ObjectType()
@Entity('user')
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 32 })
@Field()
username: string;
@Column({ unique: true })
@Field()
email: string;
@Column()
@Field()
password: string;
@Column({ default: '' })
@Field()
imageLink: string;
}
- 타입 변경 후
import { ObjectType, Field } from '@nestjs/graphql';
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from 'typeorm';
@ObjectType()
@Entity('user')
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 32 })
@Field()
username: string;
@Column({ unique: true })
@Field()
email: string;
@Column({ default: 7 })
@Field()
password: number;
@Column({ default: '' })
@Field()
imageLink: string;
}
실험 결과
Data는 유지됐다. Column이 삭제되고 새로 추가됐으며, default 값인 7로 초기화 된 것을 볼 수 있다. default 값의 중요성을 느낀 실험이었다.
728x90
'Laboratory' 카테고리의 다른 글
[React] PureComponent (0) | 2021.07.20 |
---|---|
new Date()는 메모리 해제를 하지않아도 괜찮을까? (0) | 2021.07.08 |
댓글