如何在节点 JS 续集中编写此查询



这是Codeigniter代码。我尝试在 nodejs 中进行此查询

$this->db->where('feature', $feature);
$this->db->where(1);
for ($i = 0; $i < sizeof($payment12); $i++) {
$this->db->or_where("FIND_IN_SET('" . $payment12[$i] . "', payment)");
}
$this->db->where(1);
for ($i = 0; $i < sizeof($coin); $i++) {
$this->db->or_where("FIND_IN_SET('" . $coin[$i] . "', coin_id)");
}
$this->db->like('name', $website_name);
$this->db->where(1);
for ($i = 0; $i < sizeof($location); $i++) {
$this->db->or_where("FIND_IN_SET('" . $location[$i] . "', location)");
}

下面是示例 MySql 查询

SELECT *, (fees + privacy + speed + limits + trusted + easy_use) AS totalRank FROM `Websites` WHERE ( `feature` = '2' ) AND ( 1 IS NULL OR FIND_IN_SET('credit', payment) OR FIND_IN_SET('bank', payment) ) AND ( 1 IS NULL OR FIND_IN_SET('ZEC', coin_id) OR FIND_IN_SET('BTC', coin_id) ) AND ( `name` LIKE '%coin%' ESCAPE '!' ) AND ( 1 IS NULL OR FIND_IN_SET('USA', location) OR FIND_IN_SET('IND', location) ) AND `status` = 1 ORDER BY `totalRank` DESC

可以在 Node.js Sequelize 中转换吗?

你可以这样做。

sequelize.query(" SELECT *, (fees + privacy + speed + limits + trusted + easy_use) AS totalRank FROM `Websites` WHERE ( `feature` = '2' ) AND ( 1 IS NULL OR FIND_IN_SET('credit', payment) OR FIND_IN_SET('bank', payment) ) AND ( 1 IS NULL OR FIND_IN_SET('ZEC', coin_id) OR FIND_IN_SET('BTC', coin_id) ) AND ( `name` LIKE '%coin%' ESCAPE '!' ) AND ( 1 IS NULL OR FIND_IN_SET('USA', location) OR FIND_IN_SET('IND', location) ) AND `status` = 1 ORDER BY `totalRank` DESC", {
type: sequelize.QueryTypes.SELECT,
model: Websites
}).then(value => {
console.log(value);
})

相关内容

  • 没有找到相关文章

最新更新