gpt4 book ai didi

postgresql - Apollo /GraphQL : Field Type to Use for Timestamp?

转载 作者:行者123 更新时间:2023-12-05 05:22:13 26 4
gpt4 key购买 nike

我正在将一个值存储到类型为 timestamp with time zone 的 postgres 字段中。我在我的 Apollo 模式中将该字段定义为一个 int,但我在解析器中收到此错误消息:

column "apptDateTime" is of type timestamp with time zone but expression is of type integer

正在查找 GraphQL data types ,我还没有看到任何被引用为对应于时间戳类型字段的类型。

对于数据库中时间戳类型的字段,在 Apollo 模式中使用的正确字段类型是什么?

最佳答案

我发现这种方式可以处理表单中的输入,需要从客户端(输入表单)转换到服务器,以及从服务器到客户端(输入表单)

Graphql:

    updatedAt: String

续集:

    updatedAt: {  type: Sequelize.DATE },

PostgreSQL:

    "createdAt" timestamp(6) with time zone DEFAULT now(),

到服务器的值转换:

  value  = dateToISO(value);

到客户端的值(value)转换:

  if ( isNil(value) ) {
value = '';
} else {
value = value.toLocaleDateString() +' '+ value.toLocaleTimeString();
}

帮助者:

let dateToISO = function (dateString) {
if (!dateString) {
return null;
}
let p = dateString.split(/\D/g);
/* It's up your date on input in this case come from DD-MM-YYYY
for MM-DD-YYY use: return [p[1], p[2], p[0]].join('-'); */
return [p[2], p[1], p[0]].join('-');

};

关于postgresql - Apollo /GraphQL : Field Type to Use for Timestamp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41090200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com