Persistence & Chat History
Store messages in a database and retrieve history from the client.
Persistence & Chat History
By default, ravex keeps all state in memory. For production use, you should implement a PersistenceAdapter.
Implementing a Persistence Adapter
const myAdapter = {
async saveMessage(message) {
// insert into your database
},
async getMessages(roomId, limit = 50, before) {
// query messages with pagination
return [];
},
async updateMessage(messageId, updates) {
// handle edits
},
async deleteMessage(messageId) {
// soft or hard delete
},
};
const engine = new ChatEngine(httpServer, {
persistence: myAdapter,
});Client-Side History
Once persistence is enabled on the server, clients can fetch history:
const messages = await client.getHistory("room-abc", 50);Recommended Databases
- PostgreSQL
- MongoDB
- Redis (for high-throughput)
- Any database you already use
The adapter interface is intentionally minimal so you can implement it with your ORM or query builder of choice.