This library provides an event processor for events of syncs schemas.
We don't provide a npm package yet for this library. To install it, simply copy the folder src/sequinEvents
to your working directory and import default from it.
import Sequin from "./sequinEvents";
You can initialize a global instance of the event handler for your database schema by calling the init
function with your database connection details.
const handler = Sequin.init({
connection: {
host: "YOUR_DATABASE_HOST",
user: "YOUR_DATABASE_USER",
password: "YOUR_DATABASE_PASSWORD",
database: "YOUR_DATABASE_NAME",
port: 5432,
},
schema: "public",
groupName: "default", // Optional - used to separate cursor position between contexts.
});
There can be only one handler instance per group name. It will be stored internally to be accessed from anywhere within the context of the module.
To retrieve an handler instance, use the function conn
specified by the desired group name which you want to get the handler:
const handler = Sequin.conn(); // Defaults to "default"
const handler = Sequin.conn("dashboard_app"); // Will return some other handler
If no processor was previously instantiated for the group name, an exception will be thrown.
To handle processed events, add a listener to the event
channel:
handler.on("event", (ev: SequinEvent<any>) => {
console.log(ev);
});