MemoryDB is the simplest database adapter, storing conversation history in memory. It’s perfect for development, testing, and stateless bots.
All data is lost when the bot restarts. Use MemoryDB only for development or when persistence is not required.
Installation
MemoryDB is included in the core @builderbot/bot package - no additional installation needed.
npm install @builderbot/bot
Basic Usage
import { createBot , createFlow , createProvider } from '@builderbot/bot'
import { MemoryDB as Database } from '@builderbot/bot'
import { BaileysProvider as Provider } from '@builderbot/provider-baileys'
const main = async () => {
const adapterDB = new Database ()
await createBot ({
flow: createFlow ([]),
provider: createProvider ( Provider ),
database: adapterDB
})
}
main ()
How It Works
MemoryDB stores conversation history in a simple array:
packages/bot/src/db/index.ts
class MemoryDB {
public listHistory : any [] = []
async getPrevByNumber ( from : string ) : Promise < any > {
const history = this . listHistory
. slice ()
. reverse ()
. filter (( i ) => !! i . keyword )
return history . find (( a ) => a . from === from )
}
async save ( ctx : any ) : Promise < void > {
this . listHistory . push ( ctx )
}
}
Features
Zero configuration required
Fast read/write operations
Perfect for testing flows
Limitations
No persistence - data lost on restart
Not suitable for production
Cannot scale across multiple servers
When to Use MemoryDB
Good Use Cases
Local development : Quick iteration without database setup
Unit testing : Clean state for each test run
Proof of concepts : Validate ideas before adding infrastructure
Stateless bots : When you don’t need to remember user context
When NOT to Use
Production deployments
Multi-server setups
When conversation history is important
High-traffic applications
Migration to Persistent Storage
When you’re ready to move to production, switching to a persistent database is easy:
Before (Memory)
After (JSON)
After (MongoDB)
import { MemoryDB as Database } from '@builderbot/bot'
const adapterDB = new Database ()
TypeScript Support
Use MemoryDB with full type safety:
import { addKeyword } from '@builderbot/bot'
import { MemoryDB } from '@builderbot/bot'
import { BaileysProvider } from '@builderbot/provider-baileys'
const welcomeFlow = addKeyword < BaileysProvider , MemoryDB >([ 'hello' ])
. addAnswer ( 'Hi! How can I help you?' )
Debugging
Access the in-memory history for debugging:
const adapterDB = new Database ()
// Later in your code
console . log ( 'Current history:' , adapterDB . listHistory )
console . log ( 'Total entries:' , adapterDB . listHistory . length )
Next Steps
JSON Database Add simple file-based persistence
MongoDB Scale with a production database