This example demonstrates how to use the @loro-extended/adapter-postgres storage adapter with @loro-extended/repo.
- Docker and Docker Compose (for running PostgreSQL)
- Node.js 18+
- pnpm
- Start PostgreSQL:
pnpm db:upThis starts a PostgreSQL container with:
- User:
loro - Password:
loro - Database:
loro_example - Port:
5432
- Install dependencies:
pnpm install- Run the example:
pnpm start- Creates a PostgreSQL connection pool
- Creates a
PostgresStorageAdapterwith the pool - Creates a
Repowith the storage adapter - Creates a document and makes changes
- Queries the database directly to show stored chunks
- Makes additional changes and shows how chunks accumulate
🐘 PostgreSQL Storage Adapter Example
📦 Creating storage adapter...
🔧 Creating repo with storage...
📝 Creating document...
✅ Document created: my-doc
📄 Content: {
"root": {
"message": "Hello from PostgreSQL!",
"timestamp": 1234567890123
}
}
⏳ Waiting for storage to persist...
🔍 Querying database directly...
📊 Stored chunks:
- my-doc::update::1234567890123-0000: 42 bytes
📝 Making another change...
📄 Updated content: {
"root": {
"message": "Hello from PostgreSQL!",
"timestamp": 1234567890123,
"updated": true,
"updateTime": 1234567890456
}
}
🔍 Querying database again...
📊 All stored chunks:
- my-doc::update::1234567890123-0000: 42 bytes
- my-doc::update::1234567890456-0000: 28 bytes
🧹 Cleaning up...
✅ Done!
To stop and remove the PostgreSQL container:
pnpm db:downTo also remove the data volume:
docker-compose down -v