我有一个带有nodejs和php的聊天系统,当用户单击一个房间时,聊天是从sqlite数据库的nodejs中提取的
const query = db.prepare("SELECT * FROM Chats Where chatRoom = '" + req.body.ll.toString() + "' ORDER BY `timee` DESC limit 10").all()
此处req.body.ll.toString()
是具有固定限制的聊天室的ID。因此,当用户滚动到聊天顶部时,会从nodejs中的完整新请求中加载更多聊天,该限制以数字的形式保存在客户端,从该限制中知道最后一个聊天,并获取时间戳最后一次聊天,然后提取该时间之前的所有聊天。
const more = db.prepare("SELECT * FROM Chats Where chatRoom = '" + req.body.ll.toString() + "' ORDER BY `timee` DESC limit "+ limit +"").all()
var timestamp = more[more.length-1].timee; // last chat's time
var itsid = more[more.length-1].id; // last chat's id
limit = limit + 1; // limit is increased to one for testing
const morechats = db.prepare("SELECT * FROM Chats Where chatRoom = '" + req.body.ll.toString() + "' and timee < '"+ timestamp +"' ORDER BY `timee` DESC limit "+ limit +"").all()
但是,如果用户滚动两次以上,则聊天会再次加载并重复,因此有一种方法可以跟踪聊天以检查聊天数是否等于数据库中的聊天数,然后聊天不会成功。再次加载sqlite吗?我正在使用better-sqlite作为与数据库进行通信的库