I have database structure need to declare the variable into varchar
, int
, and enum
using TypeORM in TypeScript. But in TypeScript doesn't have data type varchar and int. How do I declare it?
Database structure
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
account_id: varchar;
@Column()
email: varchar;
@Column()
phone_number: varchar;
@Column()
address: varchar;
@Column()
status: enum;
@Column()
current_id: varchar;
}
Column types in the database are inferred from the property types you used, e.g. number will be converted into integer, string into varchar, boolean into bool, etc. But you can use any column type your database supports by implicitly specifying a column type into the @Column decorator.
import {Entity, Column, PrimaryGeneratedColumn} from "typeorm";
@Entity()
export class Photo {
@PrimaryGeneratedColumn()
id: number;
@Column({
length: 100
})
name: string;
@Column("text")
description: string;
@Column()
filename: string;
@Column("double")
views: number;
@Column()
isPublished: boolean;
}
Since you are already using typeorm you can use types defined here: https://github.com/typeorm/typeorm/blob/master/docs/entities.md#column-types
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With