我们能够在 Postgres SQL 数据库中选择数组类型列的第一个元素。但是我无法使用 knex 查询相同的内容。
我试过这个。
database('items')
.select({icon: 'images[0]})
.then(data => {
res.send(data)
}
期望项目表的图像列的第一个元素。
尝试使用该first()
功能。它返回表格中的第一行(以表格排序的任何顺序)。该.select('images')
会限制返回到刚才的列images
。
knex
.select('images')
.table('items')
.first()
.then((data) => {
// first row of 'images' is an array.
// return only the first item in array.
res.send(data[0]);
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句