{"_id":"advisory-lock","_rev":"8-ac207c79c1f291fd1c589141521e14ed","name":"advisory-lock","description":"Distributed locking using PostgreSQL advisory locks","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.1":{"name":"advisory-lock","version":"1.0.1","description":"Distributed locking using PostgreSQL advisory locks","main":"lib/index.js","scripts":{"pretest":"npm run lint","build":"babel ./src --out-dir ./lib --copy-files","lint":"eslint src/ test/","release":"npm run build && npm publish && git push && git push --tags","preversion":"npm test","postversion":"npm run build","test":"npm run test:quick","test:quick":"babel-tape-runner test/*.js","dev":"nodemon --exec npm -- run test:quick","docker":"docker-compose up dbcreate && docker-compose up -d db"},"repository":{"type":"git","url":"git://github.com/blockai/advisory-lock.git"},"homepage":"https://github.com/blockai/advisory-lock","keywords":["postgres","postgresql","lock","distributed lock","mutex","advisory lock"],"bugs":{"url":"https://github.com/blockai/advisory-lock/issues"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com"},"license":"MIT","devDependencies":{"babel-cli":"^6.7.7","babel-eslint":"^6.0.4","babel-plugin-transform-object-rest-spread":"^6.6.5","babel-preset-es2015":"^6.6.0","babel-tape-runner":"^2.0.1","blue-tape":"^0.2.0","eslint":"^2.8.0","eslint-config-airbnb":"^8.0.0","eslint-plugin-import":"^1.6.1","nodemon":"^1.9.2"},"dependencies":{"debug":"^2.2.0","pg":"^4.5.5"},"gitHead":"3baf18841fe7e9d99332d618e39c06b917f1562c","_id":"advisory-lock@1.0.1","_shasum":"2dfe87f61572bb691403af374e96f63aafaf6adb","_from":".","_npmVersion":"3.8.6","_nodeVersion":"6.0.0","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"dist":{"shasum":"2dfe87f61572bb691403af374e96f63aafaf6adb","tarball":"https://registry.npmjs.org/advisory-lock/-/advisory-lock-1.0.1.tgz","integrity":"sha512-RIJzwkKQ0imS1JVdRDRLqC6SpE4RteUPl27ai4wQoWzMcQ/1BHijHcqwl2UL+FX5CBmeas4yXXRmpEzVrQwVbw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF7mxN9Dm921SA8vwY+nQVIK3iv4mcPJ2i5XEtOY1nowAiEA1szx9XZ/L3bvXhwruj2/15Try7jhkGpPHhqaMMDtWMY="}]},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/advisory-lock-1.0.1.tgz_1463036403210_0.8257112104911357"},"directories":{}},"1.0.2":{"name":"advisory-lock","version":"1.0.2","description":"Distributed locking using PostgreSQL advisory locks","main":"lib/index.js","scripts":{"pretest":"npm run lint","build":"babel ./src --out-dir ./lib --copy-files","lint":"eslint src/ test/","release":"npm run build && npm publish && git push && git push --tags","preversion":"npm test","postversion":"npm run build","test":"npm run test:quick","test:quick":"babel-tape-runner test/*.test.js","dev":"nodemon --exec npm -- run test:quick","docker":"blockai-dc && docker-compose up dbcreate"},"repository":{"type":"git","url":"git://github.com/blockai/advisory-lock.git"},"homepage":"https://github.com/blockai/advisory-lock","keywords":["postgres","postgresql","lock","distributed lock","mutex","advisory lock"],"bugs":{"url":"https://github.com/blockai/advisory-lock/issues"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com"},"license":"MIT","devDependencies":{"babel-cli":"^6.7.7","babel-eslint":"^6.0.4","babel-plugin-transform-object-rest-spread":"^6.6.5","babel-preset-es2015":"^6.6.0","babel-tape-runner":"^2.0.1","blockai-dc":"^1.0.0","eslint":"^2.8.0","eslint-config-airbnb":"^8.0.0","eslint-plugin-import":"^1.6.1","nodemon":"^1.9.2","tape":"^4.5.1"},"dependencies":{"debug":"^2.2.0","pg":"^4.5.5"},"gitHead":"ea25790b6dddc69c1e3b6f48b40c2675a2f60204","_id":"advisory-lock@1.0.2","_shasum":"4194bdfb9ef254431c2bd8bf7ea2d7708a4f40ea","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"dist":{"shasum":"4194bdfb9ef254431c2bd8bf7ea2d7708a4f40ea","tarball":"https://registry.npmjs.org/advisory-lock/-/advisory-lock-1.0.2.tgz","integrity":"sha512-Rt7FlJ3Im3ZCUSTyfCt1PkYtpl9OJkP6ZGaU/7MOpe2QnyApadjK9OdoEiIMmZHQ+GtopnZnuf81YMjNMqDCXg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGwmH1CIgoi9P/GyGrpxPyAssBM6r3FKJ1MjLlsPux0aAiBCyj2l/vAkGTRdMRKC9EXlCPVcXQ4PpBqw+nSL/fDFMg=="}]},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/advisory-lock-1.0.2.tgz_1476915197116_0.5735189917031676"},"directories":{}},"1.1.0":{"name":"advisory-lock","version":"1.1.0","description":"Distributed locking using PostgreSQL advisory locks","main":"lib/index.js","bin":{"withlock":"./lib/bin/withlock.js"},"scripts":{"pretest":"npm run lint","build":"babel ./src --out-dir ./lib --copy-files","lint":"eslint src/ test/","release":"npm run build && npm publish && git push && git push --tags","preversion":"npm test","postversion":"npm run build","test":"npm run test:quick","test:quick":"babel-tape-runner test/*.test.js","dev":"nodemon --exec npm -- run test:quick","docker":"blockai-dc && docker-compose up dbcreate"},"repository":{"type":"git","url":"git://github.com/blockai/advisory-lock.git"},"homepage":"https://github.com/blockai/advisory-lock","keywords":["postgres","postgresql","lock","distributed lock","mutex","advisory lock"],"bugs":{"url":"https://github.com/blockai/advisory-lock/issues"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com"},"license":"MIT","devDependencies":{"babel-cli":"^6.7.7","babel-eslint":"^6.0.4","babel-plugin-transform-object-rest-spread":"^6.6.5","babel-preset-es2015":"^6.6.0","babel-tape-runner":"^2.0.1","blockai-dc":"^1.0.0","eslint":"^2.8.0","eslint-config-airbnb":"^8.0.0","eslint-plugin-import":"^1.6.1","nodemon":"^1.9.2","tape":"^4.5.1"},"dependencies":{"debug":"^2.2.0","minimist":"^1.2.0","pg":"^4.5.5"},"gitHead":"e768202aa4d1377c2a88ab571a4d3833a35c8d37","_id":"advisory-lock@1.1.0","_shasum":"f2bb79687046ac1157aef344346c37df10669545","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"dist":{"shasum":"f2bb79687046ac1157aef344346c37df10669545","tarball":"https://registry.npmjs.org/advisory-lock/-/advisory-lock-1.1.0.tgz","integrity":"sha512-oMcI9Dz3DzuP5aEbdWODG1CKtqIXp9N61+VTmmLxMJ4xHRPSuLV9JW/uj+xGydI3h6RrbHm3uaFy4Pw3/+qLsQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEg2OylBjH/gD5iiGmN8li0LBf/+W/1l66Lw0f/SUTf6AiBiUHtptvLm7+2FOZsZ3H7FQZzY/LvdHCYIl4wkghqJXA=="}]},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/advisory-lock-1.1.0.tgz_1476921733766_0.624362199800089"},"directories":{}},"1.1.1":{"name":"advisory-lock","version":"1.1.1","description":"Distributed locking using PostgreSQL advisory locks","main":"lib/index.js","bin":{"withlock":"./lib/bin/withlock.js"},"scripts":{"pretest":"npm run lint","build":"babel ./src --out-dir ./lib --copy-files","lint":"eslint src/ test/","release":"npm run build && npm publish && git push && git push --tags","preversion":"npm test","postversion":"npm run build","test":"npm run test:quick","test:quick":"babel-tape-runner test/*.test.js","dev":"nodemon --exec npm -- run test:quick","docker":"blockai-dc && docker-compose up dbcreate"},"repository":{"type":"git","url":"git://github.com/blockai/advisory-lock.git"},"homepage":"https://github.com/blockai/advisory-lock","keywords":["postgres","postgresql","lock","distributed lock","mutex","advisory lock"],"bugs":{"url":"https://github.com/blockai/advisory-lock/issues"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com"},"license":"MIT","devDependencies":{"babel-cli":"^6.7.7","babel-eslint":"^6.0.4","babel-plugin-transform-object-rest-spread":"^6.6.5","babel-preset-es2015":"^6.6.0","babel-tape-runner":"^2.0.1","blockai-dc":"^1.0.0","eslint":"^2.8.0","eslint-config-airbnb":"^8.0.0","eslint-plugin-import":"^1.6.1","nodemon":"^1.9.2","tape":"^4.5.1"},"dependencies":{"debug":"^2.2.0","minimist":"^1.2.0","pg":"^4.5.5"},"gitHead":"2c08c9be34a997a130f1c57b962ca6a7cb45c662","_id":"advisory-lock@1.1.1","_shasum":"f2433c458a506a1e9aaa77c2b81f1d9c793abe4a","_from":".","_npmVersion":"4.0.5","_nodeVersion":"6.6.0","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"dist":{"shasum":"f2433c458a506a1e9aaa77c2b81f1d9c793abe4a","tarball":"https://registry.npmjs.org/advisory-lock/-/advisory-lock-1.1.1.tgz","integrity":"sha512-wVcjzxkBTKK5sdrf0WMnsfZpq1SdSVlBVwkhbEYUmF0w+eh82/h7XEsxbJAAwrMl4V0UbOEiLTPmgaclvOcLEw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCoyXIupOrzirj8N0F1L0YuowVgndyxmMJo59qzhurvCgIhAONF2pDlzV2n+V25y94jRXvn0YaZ5ufMqu9HInsv07ON"}]},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/advisory-lock-1.1.1.tgz_1486427963230_0.7079820926301181"},"directories":{}},"1.2.0":{"name":"advisory-lock","version":"1.2.0","description":"Distributed locking using PostgreSQL advisory locks","main":"build/index.js","types":"build/index.d.ts","bin":{"withlock":"build/bin/withlock.js"},"scripts":{"test:createTestDatabase":"createdb test-advisorylock || true","lint":"prettier -c src/","build":"tsc","release":"npm run build && npm publish && git push && git push --tags","preversion":"npm test","prepublishOnly":"npm run build && npm run test","pretest":"npm run lint && npm run build && npm run test:createTestDatabase","test":"npm run test:only","test:only":"tape build/test/*.test.js","dev":"nodemon --exec npm -- run test:only"},"repository":{"type":"git","url":"git://github.com/olalonde/advisory-lock.git"},"homepage":"https://github.com/olalonde/advisory-lock","keywords":["postgres","postgresql","lock","distributed lock","mutex","advisory lock"],"bugs":{"url":"https://github.com/olalonde/advisory-lock/issues"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com"},"license":"MIT","devDependencies":{"@types/debug":"^4.1.7","@types/pg":"^8.6.6","nodemon":"^1.9.2","prettier":"^2.8.4","tape":"^4.5.1","typescript":"^4.9.5"},"dependencies":{"debug":"^4.3.4","minimist":"^1.2.8","pg":"^8.9.0"},"gitHead":"f19c81a0a77608a2d84d3cc4c310c26aa10823df","_id":"advisory-lock@1.2.0","_nodeVersion":"10.24.1","_npmVersion":"6.14.12","dist":{"integrity":"sha512-tptt1W7ymX7u5mWknVV/y6A6EQ8Z09BFxwC4XgHulXZj8yW5dVDC4+CiQmlHXvkmRLQAtiSPFx9P4JVttL4ACQ==","shasum":"26198bdd29e055af7926e63bb163c71c599cb726","tarball":"https://registry.npmjs.org/advisory-lock/-/advisory-lock-1.2.0.tgz","fileCount":28,"unpackedSize":178992,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC//BbRe4gOgAbqY3MIxY/hOd6HPmdEhf8UnCMwS8UbUAIhAIlEgHPtCGPja9wU/COytCM/YXIQvS1Z4FWcnUo4zv4B"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj+l9EACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqiyQ/+OuxHsXpDYA1DM6D7jVT8PP+M0tnGGMhmBA0YQccmY1yAZhhU\r\n2c7iS1f6LG9uUSfgV5vYLpO6nxwNH8VZOcEdMFax2irwvs3L0JBdGmE5b2AA\r\nSS9rPnPHSMasOUwvKbSZ/06IX/h1eRwQyEe9JpqXgs9R/77l0xBnZvBKGbyt\r\n1jBj3Mx4KaLtfkjk7sMX2BkRR7U+Osk28QlG3D4ZT/sAwNOt6yADS4TVRjAg\r\nu5gP7x7yUsznLJsMbDth9Y3+3WaCRcwRqEgu5am0O6xgn5XfOHWDJiAdALOY\r\nICc/0WzzUYLTGupskxw8Wip+p2mzhKOKQ0OCTsA3QLPoNnldiRSiy3M+bIcg\r\nxzciTUpbz70RSsd1xzYTMQ9H4Gk12zCuxvyr4f0Dq6HB0rfHrp6NXMZiCTMh\r\nvj4mPOB7muFZrQRLAlAWMTuv+EHKacupJlru9zCxYzJjH8asnVYSNS3sWF/L\r\nt4K6pEI0tiEcptBzUmXAWX+oq/Lh2xy9ctpGzxU++dCATeCqg8+51Ir3u7Uv\r\nH5820IySVAMtLfbSMmhrGoAxyJBw1QdCX6ZdiY0JhlR2YeyZi3pVv6MEhqdw\r\ntvLzQZ0vP/0u1RcIipowClz/8w8uyt/INLMjkcCcW0k8mXOBEqIKbTSZeH/5\r\ncl+jNkBMjOzRy1BswSfe7qBfy77iDAPr1I8=\r\n=u+z0\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"directories":{},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/advisory-lock_1.2.0_1677352772083_0.5071004687124796"},"_hasShrinkwrap":false},"2.0.0":{"name":"advisory-lock","version":"2.0.0","description":"Distributed locking using PostgreSQL advisory locks","main":"build/index.js","types":"build/index.d.ts","bin":{"withlock":"build/bin/withlock.js"},"scripts":{"test:createTestDatabase":"createdb test-advisorylock || true","lint":"prettier -c src/","lint:fix":"prettier --write src/","build":"tsc","release":"npm run build && npm publish && git push && git push --tags","preversion":"npm test","prepublishOnly":"npm run build && npm run test","pretest":"npm run lint && npm run build && npm run test:createTestDatabase","test":"npm run test:only","test:only":"tape build/test/*.test.js","dev":"nodemon --exec npm -- run test:only"},"repository":{"type":"git","url":"git://github.com/olalonde/advisory-lock.git"},"homepage":"https://github.com/olalonde/advisory-lock","keywords":["postgres","postgresql","lock","distributed lock","mutex","advisory lock"],"bugs":{"url":"https://github.com/olalonde/advisory-lock/issues"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com"},"license":"MIT","devDependencies":{"@types/debug":"^4.1.7","@types/pg":"^8.6.6","nodemon":"^1.9.2","prettier":"^2.8.4","tape":"^5.6.3","typescript":"^4.9.5"},"dependencies":{"debug":"^4.3.4","minimist":"^1.2.8","pg":"^8.9.0"},"gitHead":"36fb810258415244365b9cb8ba069c90136dcee1","_id":"advisory-lock@2.0.0","_nodeVersion":"10.24.1","_npmVersion":"6.14.12","dist":{"integrity":"sha512-MzH2qiLvczT0fkdb+4v6lFKgZF1yKLUQ6JudqtxD4GEyaNiRJCFB32UV9V4cPTYlbtUH7E8hkEcV7B1pPEAFBA==","shasum":"9aa7fb9b4657e83a506ac08609cc66b9efb8c43b","tarball":"https://registry.npmjs.org/advisory-lock/-/advisory-lock-2.0.0.tgz","fileCount":28,"unpackedSize":188573,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHl/vy14ROVxBpSlul2JUadwx4Z+3nj+zmbBDKmFYbVwAiB5KPwL/1kddP4akFhl7ZPdjiAhKj0EbGVeS2rviWjfPQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj+pGWACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr6yw//dq0tuC3q1WWQ0LPi3mXUXlQwgQRKqKot9HX6iFJIzevLo9c6\r\nRggUpUTNm2nuECEah33gEOIG45zFpVdfc5HycETiMmOI7IQZe6QKI12uKb/U\r\nLxwvA5FGkUoN70suYzHf9g3coRLeiEYLcQbnkYn/rNbTLU25sjWlPu+cJi5Z\r\nDvb9ZtgTHwEjroBHaXh79IEYzZgjD7TEGtXPfxhZzVYLLhlTIBhU32l9voLo\r\nuZ5we0D+eqoDUWfMY/ISGrYaR4u8gkZL682We2/L1EcjTEPACWLPCoJ+unZ+\r\ndObnHixtvU08Y7zuYUVldmloWfOEXK2sl7ODvJDys9Xszk4EOLSgWETycdMo\r\nPzOL9G99Q3bvYlJdp1rIr3rVFYWIIDLvs86RInbWVDBZPSUl8pxKJp8Ox3oP\r\nDC+8vjoENGX0xR0LAXd0nVUA/tCrEofO0PHGwTmQXvFTkVe3YN+LDXiaOhyD\r\nlb7FtSKew9M9vzzqq+iS61KojVquQFRR8za240+rTCSO1qoHBWaczm/FFIAZ\r\naxHtzQz/UXLMHsPze04mUaVfTKbm12+QoyLwA4KOhleJekWaZLFVschsyjE0\r\niQa/sLCGY8j5cYk2WTWXUlZgxcxFzlpaOelSCUliQWgqGwmDX/2FqzE67/4o\r\n9pQS68u0TgQcHJaaBDBQQYX+wOpwTsdWx1U=\r\n=CWx6\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"directories":{},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/advisory-lock_2.0.0_1677365654592_0.6326970410061132"},"_hasShrinkwrap":false}},"readme":"# advisory-lock\n\n[![Build\nStatus](https://github.com/olalonde/advisory-lock/actions/workflows/nodejs.yml/badge.svg)](https://github.com/olalonde/advisory-lock/actions/workflows/nodejs.yml)\n\nDistributed\\* locking using [PostgreSQL advisory locks](http://www.postgresql.org/docs/current/static/explicit-locking.html#ADVISORY-LOCKS).\n\nSome use cases:\n\n- You have a [clock process](https://devcenter.heroku.com/articles/scheduled-jobs-custom-clock-processes)\n  and want to make absolutely sure there will never be more than one\n  process active at any given time.\n\n  This sort of situation can otherwise arise if the clock process is\n  scaled up by accident or during a deployment which keeps the old\n  version running until the new version responds to a health check.\n\n- Running a database migration at server startup. If your app is scaled,\n  multiple processes will simultaneously try to run the database\n  migration which can lead to problems.\n\n- Leader election. Let's say you have a web app and want to post a\n  message to Slack every 30 mins containing some statistic (e.g. new\n  registrations in the last 30 mins). You might have 10 processes\n  running but don't want to get 10 identical messages in Slack.\n  You can use this library to elect a \"master\" process which\n  is responsible for sending the message.\n\n- [etc.](https://www.google.com/?q=distributed+lock#newwindow=1&q=distributed+lock)\n\n\\* Your PostgreSQL database being a central point of failure. For\na high available distributed lock, have a look at\n[ZooKeeper](https://zookeeper.apache.org).\n\n## Install\n\n```console\nnpm install --save advisory-lock\n```\n\n## Example\n\n```javascript\nimport advisoryLock from \"advisory-lock\";\nconst mutex = advisoryLock(\"postgres://user:pass@localhost:3475/dbname\")(\n  \"some-lock-name\"\n);\n\n// waits and blocks indefinitely for the lock before executing the function\nawait mutex.withLock(async () => {\n  // do something exclusive\n  // releases lock when promise resolves or rejects\n});\n\n// doesn't \"block\", just tells us if the lock is available\nconst unlock = await mutex.tryLock();\nif (unlock) {\n  // we are now responsible for manually releasing the lock\n  // do something...\n  await unlock();\n} else {\n  throw new Error(\"could not acquire lock\");\n}\n```\n\nSee [./test](./test) for more usage examples.\n\n## CLI Usage\n\nA `withlock` command line utility is provided to make to facilitate the\ncommon use case of ensuring only one instance of a process is running at any\ntime.\n\n![withlock demo](./withlock-demo.gif)\n\n```bash\nwithlock <lockName> [--db <connectionString>] -- <command>\n```\n\nWhere `<lockName>` is the name of the lock, `<command>` (everything after\n`--`) is the command to run exclusively, once the lock is acquired.\n`--db <connectionString>` is optional and if not specified, the\n`PG_CONNECTION_STRING` environment variable will be used.\n\nExample:\n\n```bash\nexport PG_CONNECTION_STRING=\"postgres://postgres@127.0.0.1/mydb\"\nwithlock dbmigration -- npm run knex migrate:latest\n```\n\n## Usage\n\n### advisoryLock(connectionString)\n\n- `connectionString` must be a Postgres connection string\n\nReturns a `createMutex` function.\n\n### createMutex(lockName)\n\n- `lockName` must be a unique identifier for the lock\n\nReturns a **mutex** object containing the functions listed below. All\n**object** methods are really just functions attached to the object and\nare not bound to _this_ so they can be safely destructured,\ne.g. `const { withLock } = createMutext(lockName)`.\n\nFor a better understanding of what each functions does,\nsee [PosgtreSQL's manual](http://www.postgresql.org/docs/current/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS).\n\n#### mutex.withLock(fn)\n\n- `fn` Function to be executed once the lock is acquired.\n\nLike `lock()` but automatically release the lock after `fn()` is executed.\n\nReturns the value returned by `fn()`.\n\n#### mutex.tryLock(): UnlockFunction\n\nReturns an `unlock()` function if the lock was acquired and `undefined` otherwise.\n\n#### mutex.lock(): UnlockFunction\n\nBlocks and waits for lock acquisition and returns an `unlock()` function.\n","maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"time":{"modified":"2023-02-25T22:54:14.826Z","created":"2016-05-12T07:00:06.299Z","1.0.1":"2016-05-12T07:00:06.299Z","1.0.2":"2016-10-19T22:13:18.870Z","1.1.0":"2016-10-20T00:02:15.818Z","1.1.1":"2017-02-07T00:39:25.413Z","1.2.0":"2023-02-25T19:19:32.419Z","2.0.0":"2023-02-25T22:54:14.752Z"},"homepage":"https://github.com/olalonde/advisory-lock","keywords":["postgres","postgresql","lock","distributed lock","mutex","advisory lock"],"repository":{"type":"git","url":"git://github.com/olalonde/advisory-lock.git"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com"},"bugs":{"url":"https://github.com/olalonde/advisory-lock/issues"},"license":"MIT","readmeFilename":"README.md"}