Registry / database / mr-potato-head

mr-potato-head

JSON →
library5.0.0jsnpmunverified

Distributed locking via MySQL or PostgreSQL advisory locks. Current stable version 5.0.0, released regularly on npm. Uses GET_LOCK() / pg_try_advisory_lock() to provide mutually exclusive locks across processes. Lightweight, dependency-agnostic (bring your own mysql2 or pg driver).

npm install mr-potato-head
INSTALL
IMPORT
SIG · MR-POTATO-HEAD
M
mr-potato-head
databasejavascriptv5.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import mrPotatoHead from 'mr-potato-head';
const mrPotatoHead = require('mr-potato-head');
ESM import since v5; requires Node ESM or bundler support.
default
const mrPotatoHead = require('mr-potato-head');
CommonJS require works for all versions.

Demonstrates acquiring and releasing an advisory lock using async/await with mysql2.

import mrPotatoHead from 'mr-potato-head'; import mysql from 'mysql2/promise'; const lock = mrPotatoHead({ dialect: 'mysql', host: process.env.DB_HOST ?? 'localhost', username: process.env.DB_USER ?? 'root', password: process.env.DB_PASS ?? '', database: process.env.DB_NAME ?? 'test' }); await lock.lock(); try { console.log('Lock acquired'); } finally { await lock.unlock(); }
Debug
Known issues
breakingv5 switched to ESM-only; require() no longer works without bundler or ESM config.
fix
Use import or enable ESM in package.json.
affects: >=5.0.0
gotchaLock names are arbitrary but must be unique per resource. Reusing same name across different resources causes false conflicts.
fix
Use distinct lock names per critical section.
affects: all
deprecatedv4 callback API removed in v5. Code using .lock(callback) will break.
fix
Use async/await or .lock().then().
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: mrPotatoHead(...).lock is not a function
Using ESM import with older CommonJS-only version (<5).
fix
Update to v5 and use import syntax, or stay on <5 and use require().
Error: No dialect specified
Missing 'dialect' option in configuration.
fix
Add dialect: 'mysql' or 'postgres' in options object.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
mysql2optionalMySQL driver required when using MySQL dialect
pgoptionalPostgreSQL driver required when using Postgres dialect
Agent activity
2 hits · last 30 days
node
2
Resources
mr-potato-head — npm install mr-potato-head · libregistry