{"_id":"@bitfinex/bfx-facs-db-mysql","name":"@bitfinex/bfx-facs-db-mysql","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@bitfinex/bfx-facs-db-mysql","version":"1.0.0","private":false,"description":"Bitfinex DB MySQL Facility","author":{"name":"prdn","email":"paolo@bitfinex.com"},"scripts":{"lint":"standard","format":"standard --fix","test":"npm run lint && npm run unit","unit":"NODE_ENV=test mocha ./test"},"main":"index.js","keywords":["bitfinex"],"dependencies":{"@bitfinex/lib-js-util-promise":"git+https://github.com/bitfinexcom/lib-js-util-promise.git","@bitfinex/bfx-facs-base":"git+https://github.com/bitfinexcom/bfx-facs-base.git","async":"^3.2.1","lodash":"^4.17.21","mysql":"^2.18.1"},"engines":{"node":">=16.0"},"license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/bitfinexcom/bfx-facs-db-mysql.git"},"maintainers":[{"name":"vigan-abd","email":"vigan.abd@gmail.com"},{"name":"bitfinexorg","email":"paolo@bitfinex.com"},{"name":"prdn","email":"paolo.ardoino@gmail.com"},{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"devDependencies":{"mocha":"^10.0.0","sinon":"^15.2.0","standard":"^17.0.0"},"_id":"@bitfinex/bfx-facs-db-mysql@1.0.0","gitHead":"3076f6510fd553852d2571c0ba75a0664c11b8c9","bugs":{"url":"https://github.com/bitfinexcom/bfx-facs-db-mysql/issues"},"homepage":"https://github.com/bitfinexcom/bfx-facs-db-mysql#readme","_nodeVersion":"18.20.4","_npmVersion":"10.7.0","dist":{"integrity":"sha512-NembVxppCQJFczqJ05k2zynNHZkyd8BcmI35IDL8CJA52JG4mXN6QpvABJQwdrJ5HfQ+CeIqxNzjqtG6EobGow==","shasum":"f8eadb7988ae9d1d0e79fdc0245e6faa368607b2","tarball":"https://registry.npmjs.org/@bitfinex/bfx-facs-db-mysql/-/bfx-facs-db-mysql-1.0.0.tgz","fileCount":8,"unpackedSize":38987,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIC+yyGOvMbfVnHSy4ZRipA0E5yy98Q5Y+EhsMsrIrIzjAiEAo36b7pQM/4Fk18Mec1XPnrPLg+cbyeE8Vap8sjIeG/w="}]},"_npmUser":{"name":"vigan-abd","email":"vigan.abd@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/bfx-facs-db-mysql_1.0.0_1765397012480_0.6263782597562273"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-10T20:03:32.367Z","1.0.0":"2025-12-10T20:03:32.637Z","modified":"2025-12-10T20:03:33.015Z"},"maintainers":[{"name":"vigan-abd","email":"vigan.abd@gmail.com"},{"name":"bitfinexorg","email":"paolo@bitfinex.com"},{"name":"prdn","email":"paolo.ardoino@gmail.com"},{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"description":"Bitfinex DB MySQL Facility","homepage":"https://github.com/bitfinexcom/bfx-facs-db-mysql#readme","keywords":["bitfinex"],"repository":{"type":"git","url":"git+https://github.com/bitfinexcom/bfx-facs-db-mysql.git"},"author":{"name":"prdn","email":"paolo@bitfinex.com"},"bugs":{"url":"https://github.com/bitfinexcom/bfx-facs-db-mysql/issues"},"license":"Apache-2.0","readme":"# bfx-facs-db-mysql\n\nA facility that represents mysql database adapter/client.\n\n## Usage\n\n```js\n// initialization\nconst fac = new DbFacility(caller, { ns: 'm0' }, { env: 'development' })\nfac.start((err) => {\n  if (err) console.log('an error occurred', err)\n})\n\n// callback usage\nfac.cli.query(\n  'INSERT INTO sampleTestTable (name, age) VALUES (?, ?)',\n  ['jane doe', 25],\n  (err, res) => {\n    if (err) {\n      console.log('an error occurred', err)\n      return\n    }\n\n    console.log('result', res)\n  }\n)\n\n// promise usage\ntry {\n  const res = await fac.queryAsync(\n    'INSERT INTO sampleTestTable (name, age) VALUES (?, ?)',\n    ['jane doe', 25]\n  )\n  console.log('result', res)\n} catch (err) {\n  console.log('an error occurred', err)\n}\n\n// event usage\nfac.cli.query(\n  {\n    sql: 'SELECT * FROM sampleTestTable WHERE age >= ?',\n    values: [25]\n  }\n)\n  .on('error', (err) => {\n    done(err)\n  })\n  .on('result', (res) => {\n    assert.strictEqual(typeof res, 'object')\n    assert.strictEqual(res.affectedRows, 1)\n    done()\n  })\n\n// async iterator stream usage\nconst stream = fac.queryStream('SELECT * FROM sampleTestTable WHERE age >= ?', [25])\nfor await (const row of stream) {\n  console.log(row)\n}\n\n// closing resources\nfac.stop((err) => {\n  if (err) console.log('an error occurred', err)\n})\n\n// callback transactions\nfac.runTransaction((conn, txFuncCb) => {\n  async.series([\n    (nextStmt) => conn.cli.query(\n      'INSERT INTO sampleTestTable (name, age) VALUES (?, ?)',\n      ['john doe', 27],\n      nextStmt\n    ),\n    (nextStmt) => conn.cli.query(\n      {\n        sql: 'INSERT INTO sampleTestTable (name, age) VALUES (?, ?)',\n        values: ['jane doe', 25]\n      },\n      nextStmt\n    )\n  ], txFuncCb)\n}, (err) => {\n  if (err) {\n    console.log('transaction failed')\n  } else {\n    console.log('transcation succeeded')\n  }\n})\n\n// promise transactions\nawait fac.runTransactionAsync(async (conn) => {\n  await conn.queryAsync(\n    'INSERT INTO sampleTestTable (name, age) VALUES (?, ?)',\n    ['john doe', 27]\n  )\n\n  await conn.queryAsync({\n    sql: 'INSERT INTO sampleTestTable (name, age) VALUES (?, ?)',\n    values: ['jane doe', 25]\n  })\n\n  await new Promise((resolve, reject) => conn.cli.query(\n    'INSERT INTO sampleTestTable (name, age) VALUES (?, ?)',\n    [conn.cli.escape('james doe'), 23],\n    (err) => err ? reject(err) : resolve()\n  ))\n})\n\n// error handling in transactions\ntry {\n  await fac.runTransactionAsync(async (conn) => {\n    await conn.queryAsync(\n      'INSERT INTO sampleTestTable (name, age) VALUES (?, ?)',\n      ['john doe', 27]\n    )\n\n    throw new Error('ERR_SIMULATE')\n  })\n} catch (err) {\n  console.log(err)\n  // DbTransactionError: ERR_TX_FLOW_FAILURE\n  //     at DbFacility.runTransactionAsync (/home/someuser/somepath/bfx-facs-db-mysql/index.js:214:13)\n  //     at processTicksAndRejections (internal/process/task_queues.js:95:5)\n  //     at async waitForActual (assert.js:788:5)\n  //     at async Function.rejects (assert.js:909:25)\n  //     at async Context.<anonymous> (/home/someuser/somepath/bfx-facs-db-mysql/test/unit.js:373:7) {\n  //   originalError: Error: ERR_SIMULATE\n  //       at /home/someuser/somepath/bfx-facs-db-mysql/test/unit.js:370:15\n  //       at processTicksAndRejections (internal/process/task_queues.js:95:5)\n  //       at async DbFacility.runTransactionAsync (/home/someuser/somepath/bfx-facs-db-mysql/index.js:191:7)\n  //       at async waitForActual (assert.js:788:5)\n  //       at async Function.rejects (assert.js:909:25)\n  //       at async Context.<anonymous> (/home/someuser/somepath/bfx-facs-db-mysql/test/unit.js:373:7),\n  //   txState: { started: true, commited: false, reverted: true }\n  // }\n}\n```\n\n**!NOTE: nested transactions are not supported through method runTransaction and runTransactionAsync methods**\n\n## Testing\n\nExport these environment variables:\n```console\nexport DB_FAC_HOST='localhost' # default host 127.0.0.1\nexport DB_FAC_PORT=33060 # default 3306\nexport DB_FAC_USER='some_user' # default ''\nexport DB_FAC_PWD='some_pwd' # default ''\nexport DB_FAC_DB='some_db' # default ''\n```\n\nThen simply run:\n```console\nnpm test\n```\n","readmeFilename":"README.md","_rev":"1-aa4c103e5d1aad0860ad7005bb298b4f"}