【发布时间】:2020-03-28 05:46:13
【问题描述】:
我有一个如下所示的表格:
create table if not exists gameTemplate00.construction (
player uuid constraint "[construction] Player foreign key"
references gameTemplate00.player(id),
colony uuid constraint "[construction] Colony foreign key"
references gameTemplate00.colony(id),
location text, -- All subcolonies at this location contribute to production
investment uint8 default 0 not null,
cost uint8 not null,
history uint8[3] default '{null,null,null}' not null,
priority uint2,
allocation allocation not null,
repeat boolean default false not null,
dispatch text, -- what to do with the vessel once complete
project text, -- free form name for player, can be null
constraint "[construction] Priority must be unique for a given subcolony"
unique(colony, location, priority)
);
当我查询它并从 Knex 获取结果时:
db('construction')
.withSchema('gametemplate00')
.where('colony', payload.colony)
.where('location', payload.location)
.then((constructionListResult: any) => {
ws.send(JSON.stringify(constructionListResult));
console.log(constructionListResult);
})
它返回这个:
{
player: '5f43f33b-dba6-43ca-bc0c-0516e5d29968',
investment: '0',
cost: '1000',
history: '{NULL,NULL,NULL}',
priority: '4',
allocation: { kind: 'percent', amount: 0.35 },
repeat: false,
dispatch: null,
project: 'whenever'
}
Allocation 是一个 jsonb 域,它可以正确识别它并为其构建 json 对象。但是该数组很无聊并显示为字符串。
这是因为我的 Knex 配置错误,还是它根本无法识别 postgresql 数组列?这对我来说是问题最少的例子,但对于其他人来说,必须自己解析这些内容将变得非常痛苦。
【问题讨论】:
标签: arrays postgresql knex.js