简体   繁体   English

如何使用 MySQL 语法创建 knex 请求?

[英]How to create knex request using MySQL syntax?

In MySQL Workbench I have this:在 MySQL Workbench 中,我有这个:

USE my_db;
SELECT 
    transactions.created_at, price
FROM
    transactions
        JOIN
    transactions_items ON transactions.id = transactions_items.transaction_id
        JOIN
    store_items ON store_items.id = transactions_items.store_item_id;

As a result in workbench I get created_at: price .结果在工作台中我得到了created_at: price How can I create request to DB using knex syntax to get object {created_at: price} ?如何使用 knex 语法创建对数据库的请求以获取对象{created_at: price}

I was trying to use knex.raw() , but it does not seem to be working.我试图使用knex.raw() ,但它似乎不起作用。

const response = await knex('transactions')
        .join('transactions_items', 'transactions.id', '=', 'transactions_items.transaction_id')
        .join('store_items', 'store_items.id', '=', 'transactions_items.store_item_id')
        .select('transactions.created_at', 'price')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM