# wwebjs-mysql

> A MySQL plugin for whatsapp-web.js library

Latest version **0.1.4** (published 2023-09-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install wwebjs-mysql
pnpm add wwebjs-mysql
yarn add wwebjs-mysql
bun add wwebjs-mysql
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2023-09-02 |
| First published | 2023-08-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Paul Vidal |
| Maintainers | paulvl |
| Keywords | wwebjs, mysql, whatsapp-web.js |

## Links

- npm: https://www.npmjs.com/package/wwebjs-mysql
- Repository: https://github.com/paulvl/wwebjs-mysql
- Homepage: https://github.com/paulvl/wwebjs-mysql#readme
- Issues: https://github.com/paulvl/wwebjs-mysql/issues
- npm.io page: https://npm.io/package/wwebjs-mysql

## Recent versions

- 0.1.4 (latest) — 2023-09-02
- 0.1.3 — 2023-09-02
- 0.1.2 — 2023-09-02
- 0.1.1 — 2023-08-17
- 0.1.0 — 2023-08-17

## README

# wwebjs-mysql
A MySQL plugin for whatsapp-web.js! 

Use MysqlStore to save your WhatsApp MultiDevice session on a MySQL Database.

## Quick Links

* [Guide / Getting Started](https://wwebjs.dev/guide/authentication.html)
* [GitHub](https://github.com/paulvl/wwebjs-mysql)
* [npm](https://www.npmjs.com/package/wwebjs-mysql)

## Installation

The module is now available on npm! `npm i wwebjs-mysql`

## Example MySQL Table statement

```sql
CREATE TABLE `wsp_sessions` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `session_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `data` mediumblob,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `wsp_sessions_session_name_unique` (`session_name`)
) 
```

## Example usage

```js
const { Client, RemoteAuth } = require('whatsapp-web.js');
const { MysqlStore } = require('wwebjs-mysql');
const mysql = require('mysql2/promise');

const pool = mysql.createPool({
    host: process.env.DB_MYSQL_HOST,
    user: process.env.DB_MYSQL_USER,
    password: process.env.DB_MYSQL_PASSWORD,
    database: process.env.DB_MYSQL_DATABASE,
    waitForConnections: true,
    connectionLimit: 10,  // max number of concurrent conections
    queueLimit: 0         // max number of conections on queue (0 = limitless)
});

const tableInfo = {
    table: 'wsp_sessions',
    session_column: 'session_name',
    data_column: 'data',
    updated_at_column: 'updated_at'
}

const store = new MysqlStore({ pool: pool, tableInfo: tableInfo })

const client = new Client({
    authStrategy: new RemoteAuth({
        store: store,
        backupSyncIntervalMs: 300000,
        session: 'your-session-name'
    })
});

client.initialize();
```

## Delete Remote Session

How to force delete a specific remote session on the Database:

```js
await store.delete({session: 'your-session-name'});
```

---
_Source: https://npm.io/package/wwebjs-mysql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
