【发布时间】:2019-12-26 01:25:50
【问题描述】:
我正在做一个 GraphQL 教程,我需要保存用户的生日。我正在使用 TypeORM、Apollo-server-express 和 PostgreSQL。
这些是我当前的用户实体和架构文件。我不知道如何保存/输入生日,所以我现在设置为nullable。
// user.entity.ts
@Entity()
export class User extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column('text')
first_name: string;
@Column('text')
last_name: string;
@Column({
unique: true
})
@Length(5, 100)
@IsEmail()
email: string;
@Column()
password: string;
@Column({
nullable: true
})
birthday: Date;
}
// user.schmea.ts
type User {
id: ID!
first_name: String
last_name: String!
email: String!
birthday: Date
created_at: Date @date(format: "HH:MM mmmm d, yyyy")
updated_at: Date @date(format: "HH:MM mmmm d, yyyy")
}
input CreateUserInput {
first_name: String
last_name: String!
email: String!
password: String!
birthday: Date
}
这是我的示例 mutation 输入 createUser:
mutation {
createUser(data: {
first_name: "Some",
last_name: "One",
email: "some@one.com",
password: "hashThisPlease1"
}) {
id
first_name
last_name
email
}
}
我应该输入birthday 作为string 像"1990-12-30" 吗?这是在PostgreSQL中保存birthday列的标准方法吗?
请帮忙。
【问题讨论】:
-
保存为时间戳有什么问题?
-
在数据库中使用
date列
标签: node.js postgresql graphql apollo typeorm