node js 채팅방 개설 이후 채팅만 보이기
static async private_messages(private_mb_id) {
//select *, `mb_level`, `mb_point` from `g5_chat_messages` inner join `g5_member` on `ch_mb_id` = `mb_id` where `ch_room_id` = 'admin' and `ch_last_modified` > '2022-05-23 12:47:08' order by `ch_last_modified` desc limit 10
let synctime = await db(cfg.tables.member).where('mb_id','=',private_mb_id).select("mb_11");
let synckey = synctime[0]['mb_11'];
let result = await db(cfg.tables.messages).select('*', 'mb_level','mb_point').innerJoin(cfg.tables.member,'ch_mb_id', 'mb_id').where({ 'ch_room_id': private_mb_id }).andWhere('ch_last_modified','>',synckey).orderBy('ch_last_modified', 'desc').limit(10);
result = result.reverse();
let final_result = [];
for (let row of result) {
final_result.push({
ch_id: row.ch_id,
ch_mb_level: row.mb_level,
ch_mb_point: row.mb_point,
ch_mb_id: row.ch_mb_id,
ch_mb_nick: row.mb_nick,
ch_room_id:row.ch_room_id,
ch_msg: row.ch_msg,
ch_date: row.ch_date,
ch_last_modified: row.ch_last_modified
});
}
//console.log(final_result);
return final_result;
}
knex. innerjoin 에서 조건 사용하기
where 조건 추가 할때 andWhere
주의할 것들. await db(<=knex임) 로 돌렵다는 값은 구조가
[{mb_11,2000-02-01 14:12:11}] 형태여서
synctime[0][mb_11]로 접근.