Database Change Listener
Overview
This Rust library provides an event-based mechanism to monitor changes in database tables or collections and notify backend services, eliminating the need for polling. It supports PostgreSQL and MongoDB, allowing developers to register listeners and receive real-time updates on specified tables, columns, or collections.
Features
- Database-Agnostic: Designed to support multiple databases, starting with PostgreSQL and MongoDB.
- Event-Driven: Notifies backend services of table or collection changes via event-based channels.
- Customizable: Users can specify the database type, connection URL, table or collection name, and columns to monitor.
- Efficient: Eliminates the need for polling, reducing unnecessary database load.
- Automatic Pool Management: The library handles connection pooling internally, so users don't need to manage database connections manually, ensuring efficient resource usage.
Installation
Add the following to your Cargo.toml
:
[]
= "latest-version"
Quick Start
To get started with the library, you can use the following example:
use ;
let database_config = Postgres ;
let events = vec!; // Events to monitor: updates, inserts, and deletes
let db_listener = new.await?; // Create a new database listener
db_listener
.listen
.await?;
Example Usage for MongoDB
Here's how you can set up a listener for MongoDB:
let database_config = MongoDB ;
let events = vec!; // Events to monitor: updates, inserts, and deletes
let db_listener = new.await?; // Create a new database listener
db_listener
.listen
.await?;
Supported Databases
- PostgreSQL
- MongoDB
Configuration
Users can specify the database type, connection URL, table name or collection name, and columns when initializing a listener instance. The library provides a flexible configuration to accommodate various use cases.
Use Cases
- Real-time Data Synchronization: Keep your application data in sync with database changes.
- Event-Driven Microservices: Build microservices that react to database events.
- Change Tracking for Analytics: Monitor changes for analytics and reporting purposes.
License
This project is licensed under the MIT License.