是否有可能在SQL
应用程序中使用knex.js
编写类似于此Node
的联接?
INNER JOIN member_staff ON members.id = member_staff.member_id AND staff.id = member_staff.staff_id
我认为它看起来像这样(尽管这不起作用,并且我找不到任何文档来解释如何做我想做的事):
.innerJoin('member_staff', 'members.id', 'member_staff.member_id').onAnd('staff.id', 'member_staff.staff_id')
答案 0 :(得分:0)
您是说onIn
吗?
.onIn('contacts.id', [7, 15, 23, 41])
OnAnd不存在。
您也可以使用onExists
knex.select('*').from('users').join('contacts', function() {
this.on('users.id', '=', 'contacts.id').onExists(function() {
this.select('*').from('accounts').whereRaw('users.account_id = accounts.id');
})
})
答案 1 :(得分:0)
这就是我想要的:
.innerJoin('member_staff', function() {
this.on('member.id', 'member_staff.member_id')
.andOn('staff.id', 'member_staff.staff_id');
})