如何在nodejs中使用object数组选择行

46scxncf  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(386)

我有game square数据库(称为game):

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] ...

但问题是,我不知道如何用对象创建select。我可以把我的数组转换成任何东西,我怎样才能对这个问题进行查询?

ubbxdtey

ubbxdtey1#

如果您使用mysqljs/mysql npm包,请尝试以下方法:

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

看看医生https://github.com/mysqljs/mysql#performing-查询
数组转换为列表,例如,.['a','b']转换为'a','b'嵌套数组转换为分组列表(用于批量插入),例如,.['a','b'],['c','d']]转换为('a','b'),('c','d')

相关问题