我有以下使用Sequelize 4.27.0的Node.JS TS查询(为方便起见而简化):
return db.models.SalesLedger.findAll(Object.assign(
{},
{
include: [{
model: db.models.BankReceiptLedgerToSalesLedger
}]
},
{
where: Object.assign(
// Filter #1
// Filter #2
// ...
)
},
{
order: [
['id', 'ASC'],
],
}
))
这很好,直截了当,并产生如下的原生MySQL查询(为方便起见,简化):
SELECT
<A_BUNCH_OF_COLUMNS>
FROM `sales_ledger` AS `salesLedger`
LEFT OUTER JOIN `bank_receipt_ledger_to_sales_ledger`
AS `bankReceiptLedgerToSalesLedgers` ON
`salesLedger`.`id` =
`bankReceiptLedgerToSalesLedgers`.`sales_ledger_id`
WHERE
`salesLedger`.`organisation_id` = <A_GIVEN_ID>
ORDER BY `salesLedger`.`id` ASC
这也很好,很直接,并产生如下记录集:
+=======+=======+=======+=======+
| C1 | C2 | ... | CN |
+=======+=======+=======+=======+
| x1 | y1 | ... | z1 |
+-------+-------+-------+-------+
| x2 | y2 | ... | z2 |
+-------+-------+-------+-------+
| ... | ... | ... | ... |
+-------+-------+-------+-------+
| xm | ym | ... | zm |
+-------+-------+-------+-------+
我想要找到的是(轻松)更改原始Node.JS TS查询的方法,以便还检索动态生成的行号。像这样:
+=======+=======+=======+=======+=======+
| ROW # | C1 | C2 | ... | CN |
+=======+=======+=======+=======+=======+
| 1 | x1 | y1 | ... | z1 |
+-------+-------+-------+-------+-------+
| 2 | x2 | y2 | ... | z2 |
+-------+-------+-------+-------+-------+
| ... | ... | ... | ... | ... |
+-------+-------+-------+-------+-------+
| m | xm | ym | ... | zm |
+-------+-------+-------+-------+-------+
请注意:我已经知道如何使用原始的本机MySQL查询来完成它。我只想知道是否可以使用SEQUELIZE
获得相同的结果