如何使用NodeJs中的对象数组选择行

问题描述 投票:0回答:1

我有游戏广场的数据库(称为游戏):

id | x | y | isGold

我编程我有这样的一系列坐标:

var test = [
 {x:1, y:2},
 {x:2, y:4}
]

我想从游戏桌中选择所有行,如下所示:

Select * from game where x and y in (?) where isGold = true, [test] ...

但问题是,我不知道如何用对象创建选择。我可以将我的数组转换为任何内容,如何查询此问题?

mysql node.js select
1个回答
0
投票

如果你使用mysqljs / mysql npm包试试这个:

Select * from game where (x, y) IN (?) where isGold = true, [[[1, 2], [2, 4]]

看看doc https://github.com/mysqljs/mysql#performing-queries

数组被转换成列表,例如['a','b']变成'a','b'嵌套数组变成分组列表(对于批量插入),例如[['a','b'],['c','d']变成('a','b'),('c','d')

© www.soinside.com 2019 - 2024. All rights reserved.