我有游戏广场的数据库(称为游戏):
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。我可以将我的数组转换为任何内容,如何查询此问题?
答案 0 :(得分:0)
如果你使用mysqljs / mysql npm包试试这个:
Select * from game where (x, y) IN (?) where isGold = true, [[[1, 2], [2, 4]]
看看文档 https://github.com/mysqljs/mysql#performing-queries
将数组转换为列表,例如[' a',' b']变成' a'' b' 嵌套数组被转换为分组列表(对于批量插入),例如, [[' a',' b'],[' c'' d']]变成了(' a&# 39;,' b'),(' c',' d')