Javascript 如何从Mysql脚本中提取查询结果后添加更多属性的函数?
作为标题,我想重新组织我从Mysql服务器为GraphQL客户端查询的数据Javascript 如何从Mysql脚本中提取查询结果后添加更多属性的函数?,javascript,node.js,refactoring,Javascript,Node.js,Refactoring,作为标题,我想重新组织我从Mysql服务器为GraphQL客户端查询的数据 resolve: (root, { name }) => { const weekday = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']; return findCafeshopByName(name).reduce((record, row, i) => { record.openingHours = record.o
resolve: (root, { name }) => {
const weekday = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
return findCafeshopByName(name).reduce((record, row, i) => {
record.openingHours = record.openingHours || { [weekday[0]]: record.openingHour };
record.openingHours = Object.assign(
record.openingHours,
{ [weekday[i]]: row.openingHour },
)
return record;
});
}
如您所见,我对Mysql的原始结果做了两件事:
openingHours
装饰器
谢谢
p、 美国。
findCafeshopByName
调用knex查询API 那么你想知道如何将回调移动到另一个文件中?我想知道如何命名我移动回调的文件。以及如何命名该目录。我只是想知道是否有一个惯例。这可能是主观的。我会在QueryResultModifiers
的行中将该文件命名为某物,并将所有回调放在其中,就像您在这里看到的一样。听起来不错@MaazSyedAdeeb