waseqelize-store
v0.1.5
Published
Minimal Baileys data storage for your favorite DBMS built with Sequelize
Readme
Baileys Store
Minimal Baileys data storage for your favorite DBMS built with Sequelize. This library is a simple handler for Baileys event emitter that will listen and update your data in the database
Requirements
- sequelize version 6.7.x or higher
- Baileys version 6.2.x or higher
Supported Databases
- MySQL and PostgreSQL database should support the default schema out of the box
- For CockroachDB, you need to do this small change in the schema file
model Session {
pkId BigInt @id @default(autoincrement())
sessionId String
id String
- data String @db.Text
+ data String
@@unique([sessionId, id], map: "unique_id_per_session_id_session")
@@index([sessionId])
}- SQLite and SQL Server database are not supported since they didn't support Sequelize's
JSONscalar type
Installation
# Using npm
npm i waseq-store
# Using yarn
yarn add waseq-storeSetup
Before you can actually use this library, you have to setup your database first
- Copy the
.env.examplefile from this repository or from thenode_modulesdirectory (should be located atnode_modules/waseq-store/.env.example). Rename it into.envand then update your connection url in theDATABASE_URLfield
Usage
import pino from 'pino';
import makeWASocket from '@whiskeysockets/baileys';
import { sequelizeClient } from 'sequelize';
import { initStore, Store } from 'waseq-store';
const logger = pino();
const socket = makeWASocket();
const sequelize = new sequelizeClient();
// You only need to run this once
initStore({
sequelize, // Sequelize client instance
logger, // Pino logger (Optional)
});
// Create a store and start listening to the events
const store = new Store('unique-session-id-here', socket.ev);
// That's it, you can now query from the prisma client without having to worry about handling the events
const messages = sequelize.message.findAll();Contributing
PRs, issues, suggestions, etc are welcome. Please kindly open a new issue to discuss it
