New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pake/baileys-store

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pake/baileys-store

Minimal Baileys data storage for your favorite DBMS built with Prisma

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-80%
Maintainers
2
Weekly downloads
 
Created
Source

Baileys Store

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

Requirements

  • Prisma version 4.7.x or higher
  • Baileys version 5.x.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])
}
  • For MongoDB, you need to follow this convention and update the pkId field. Then follow the previous CockroachDB guide
  • SQLite and SQL Server database are not supported since they didn't support Prisma's JSON scalar type

Installation

# Using npm
npm i @pake/baileys-store

# Using yarn
yarn add @pake/baileys-store

Setup

Before you can actually use this library, you have to setup your database first

  1. Copy the .env.example file from this repository or from the node_modules directory (should be located at node_modules/@pake/baileys-store/.env.example). Rename it into .env and then update your connection url in the DATABASE_URL field
  2. Copy the prisma directory from this repository or from the node_modules directory (should be located at node_modules/@pake/baileys-store/prisma/). Additionaly, you may want to update your provider in the schema.prisma file if you're not using MySQL database
  3. Run your migration

Usage

import pino from 'pino';
import makeWASocket from '@whiskeysockets/baileys';
import { PrismaClient } from '@prisma/client';
import { initStore, Store } from '@pake/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();

Contributing

PRs, issues, suggestions, etc are welcome. Please kindly open a new issue to discuss it

FAQs

Package last updated on 18 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc