🚨 NOTICE:
@adiwajshing/baileyswhich is this project relied on, has been discontinued. Thus, this project will be archived and stopped receiving updates anymore. Thanks everyone who's been part of this❤️
Minimal Baileys data storage for your favorite DBMS built with Prisma. This library is a simple handler for Baileys event emitter that will listen and update your data in the database
- Prisma version 4.7.x or higher
- Baileys version 5.x.x or higher
- 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])
}- For MongoDB, you need to follow this convention and update the pkIdfield. Then follow the previous CockroachDB guide
- SQLite and SQL Server database are not supported since they didn't support Prisma's JSONscalar type
# Using npm
npm i @ookamiiixd/baileys-store
# Using yarn
yarn add @ookamiiixd/baileys-storeBefore 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/@ookamiiixd/baileys-store/.env.example). Rename it into.envand then update your connection url in theDATABASE_URLfield
- Copy the prismadirectory from this repository or from thenode_modulesdirectory (should be located atnode_modules/@ookamiiixd/baileys-store/prisma/). Additionaly, you may want to update yourproviderin theschema.prismafile if you're not using MySQL database
- Run your migration
import pino from 'pino';
import makeWASocket from '@adiwajshing/baileys';
import { PrismaClient } from '@prisma/client';
import { initStore, Store } from '@ookamiiixd/baileys-store';
const logger = pino();
const socket = makeWASocket();
const prisma = new PrismaClient();
// You only need to run this once
initStore({
  prisma, // Prisma 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 = prisma.message.findMany();PRs, issues, suggestions, etc are welcome. Please kindly open a new issue to discuss it