npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mysql-realtime-server

v1.1.1

Published

Realtime database layer for MySQL without binlog — application-level events and optional changelog triggers

Readme

mysql-realtime-server

Couche base de données temps réel pour MySQL sans binlog : événements au niveau application et option changelog (triggers + table).

  • Mode application : les écritures passent par l’API du package → émission d’événements (WebSocket).
  • Mode changelog (optionnel) : table _realtime_changelog + triggers sur vos tables → un poller lit les changements et les diffuse.

Installation depuis npm

npm install mysql-realtime-server

Installation en local (développement)

Si tu veux tester ou modifier le plugin localement :

1. Cloner et installer les dépendances

git clone https://github.com/Andtit4/mysql-realtime-server.git
cd mysql-realtime-server
npm install

2. Compiler le TypeScript

npm run build

Ceci génère les fichiers JS dans dist/.

3. Utiliser le plugin en local dans un autre projet

Option A : Lien symbolique (npm link)

Dans le dossier du plugin :

npm link

Dans ton projet :

npm link mysql-realtime-server

Option B : Chemin relatif

Dans ton projet :

npm install ../chemin/vers/mysql-realtime-server

4. Tester le plugin

Prérequis : MySQL en cours d'exécution avec une base de données.

# Créer une base de test
mysql -u root -p
CREATE DATABASE IF NOT EXISTS mydb;

Lancer le test complet :

# Mode simple (un cycle d'opérations)
npm run test:realtime

# Mode boucle (opérations toutes les 3 secondes)
npm run test:realtime:loop

# Mode changelog (détecte les INSERT/UPDATE/DELETE faits en SQL direct)
npm run test:realtime:changelog

Tester depuis le navigateur :

  1. Lance le serveur : npm run test:realtime ou npm run test:realtime:changelog
  2. Ouvre test/test-realtime.html dans ton navigateur
  3. Tu verras les événements en temps réel dans la page

Variables d'environnement (optionnel) :

export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=ton_password
export MYSQL_DATABASE=mydb
export REALTIME_PORT=3040

npm run test:realtime

Tester depuis le navigateur méthode api node :

  1. Lance le serveur : npm run example:node
  2. Ouvre http://localhost:3000/ dans ton navigateur
  3. Tu verras les événements en temps réel dans la page avec pour particularité l'utilisation d'une api node

Variables d'environnement (optionnel) :

export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=ton_password
export MYSQL_DATABASE=mydb
export REALTIME_PORT=3040

npm run example:node
Server start
  API :       http://localhost:3000/api/users
  Realtime :  ws://localhost:3040/realtime
  Page :      http://localhost:3000/

Utilisation

Configuration minimale (mode application)

const realtime = require('mysql-realtime-db');

const db = realtime.createConnection({
  host: 'localhost',
  user: 'myuser',
  password: 'mypassword',
  database: 'mydb',
  realtime: {
    port: 3040,              // Port du serveur WebSocket
    path: '/realtime'        // Chemin WebSocket (optionnel)
  }
});

await db.connect();
await db.startRealtimeServer();

Écouter les changements (côté serveur)

db.on('users:insert', (row) => console.log('Nouveau user:', row));
db.on('users:update', ({ previous, current }) => console.log('Modifié:', previous, '->', current));
db.on('users:delete', (row) => console.log('Supprimé:', row));
db.on('users:*', (event, data) => console.log(event, data));

Écritures qui émettent les événements

const id = await db.insert('users', { name: 'Alice', email: '[email protected]' });
await db.update('users', { id: 1 }, { name: 'Alice Updated' });
await db.delete('users', { id: 1 });

Requêtes en lecture seule

const rows = await db.query('SELECT * FROM users WHERE active = ?', [1]);

Client distant (navigateur ou autre service Node)

const client = realtime.createClient({
  url: 'http://localhost:3040',
  path: '/realtime'
});

await client.connect();

client.subscribe('users', (event, data) => {
  console.log(event, data);  // 'insert' | 'update' | 'delete', payload
});

client.subscribe('posts:*', (event, data) => {
  // Tous les événements sur la table posts
});

Mode changelog (capturer toutes les écritures)

Pour détecter les changements même hors de l’application (SQL direct, autre service), installez la table de changelog et les triggers (les tables doivent avoir une colonne id) :

const db = realtime.createConnection({
  host: 'localhost',
  user: 'app',
  password: '***',
  database: 'mydb',
  realtime: {
    port: 3040,
    enableChangelog: true,
    changelogPollIntervalMs: 500,
    tables: ['users', 'posts', 'comments']
  }
});

await db.connect();
await db.installChangelog();   // Crée _realtime_changelog + triggers
await db.startRealtimeServer();

API

| Méthode | Description | |--------|-------------| | createConnection(options) | Crée une connexion avec support realtime | | db.connect() | Connexion au pool MySQL | | db.startRealtimeServer() | Démarre le serveur WebSocket | | db.on('table:event', fn) | Écoute insert / update / delete | | db.insert(table, data) | INSERT + émission d’événement | | db.update(table, where, data) | UPDATE + émission d’événement | | db.delete(table, where) | DELETE + émission d’événement | | db.query(sql, params) | Requête arbitraire (pas d’événement) | | db.installChangelog() | Installe la table + triggers (mode changelog) | | createClient(options) | Client pour se connecter au serveur realtime | | client.subscribe(pattern, callback) | Abonnement à une table ou un pattern |

Licence

MIT