{"_id":"@bitfinex/bfx-facs-db-sqlite","name":"@bitfinex/bfx-facs-db-sqlite","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@bitfinex/bfx-facs-db-sqlite","version":"1.0.0","description":"Bitfinex DB Sqlite Facility","author":{"name":"prdn","email":"paolo@bitfinex.com"},"main":"index.js","keywords":["bitfinex"],"scripts":{"test":"npm run lint && npm run unit","unit":"mocha","lint":"standard","lint:fix":"standard --fix"},"dependencies":{"@bitfinex/bfx-facs-base":"git+https://github.com/bitfinexcom/bfx-facs-base.git","async":"^3.2.4","lodash":"^4.17.15","sqlite3":"5.1.7"},"engine":{"node":">=16.0"},"license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/bitfinexcom/bfx-facs-db-sqlite.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":{"mkdirp":"^3.0.1","mocha":"^10.2.0","chance":"^1.1.11","rimraf":"^5.0.1","standard":"^17.1.0"},"overrides":{"tar":">=7.5.4"},"_id":"@bitfinex/bfx-facs-db-sqlite@1.0.0","gitHead":"9fde6a35b1367fa4717972623446e4c4c304c453","bugs":{"url":"https://github.com/bitfinexcom/bfx-facs-db-sqlite/issues"},"homepage":"https://github.com/bitfinexcom/bfx-facs-db-sqlite#readme","_nodeVersion":"18.20.4","_npmVersion":"10.7.0","dist":{"integrity":"sha512-4l0bfyuuQ/iMywKvkMcKsXjueGcXoFYOyh6GlFBLndhGk8r9BeCbMfzeSznUXnSUY8ZUGlkxAJN9F1YbzUFR4Q==","shasum":"d58705cc4f8bdcb5af39cf845637a078f89d2b58","tarball":"https://registry.npmjs.org/@bitfinex/bfx-facs-db-sqlite/-/bfx-facs-db-sqlite-1.0.0.tgz","fileCount":11,"unpackedSize":38837,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICfB4wDP3FR6QN1dcMGGaqi2aaQw4RHLV9lY6addL5BWAiAsHjT6KhUYotsGbjoS3GGFDI49JdY939vsGkGnqcZ/8w=="}]},"_npmUser":{"name":"vigan-abd","email":"vigan.abd@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/bfx-facs-db-sqlite_1.0.0_1769100883154_0.2867292533850967"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-22T16:54:43.034Z","1.0.0":"2026-01-22T16:54:43.298Z","modified":"2026-01-22T16:54:44.136Z"},"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 Sqlite Facility","homepage":"https://github.com/bitfinexcom/bfx-facs-db-sqlite#readme","keywords":["bitfinex"],"repository":{"type":"git","url":"git+https://github.com/bitfinexcom/bfx-facs-db-sqlite.git"},"author":{"name":"prdn","email":"paolo@bitfinex.com"},"bugs":{"url":"https://github.com/bitfinexcom/bfx-facs-db-sqlite/issues"},"license":"Apache-2.0","readme":"# bfx-facs-db-sqlite\n\n## API\n\n\n### fac.upsert\n\nReturns `{ lastID: <lastID> }` in the result\n\nExample:\n\n```js\nfac.upsert({\n  table: 'Employees',\n  selectKey: 'id',\n  selectValue: '1',\n  data: { id: 1, name: 'paolo', surname: 'ardoino' }\n}, cb)\n\n// runs:\nd.run(\n  \"INSERT OR REPLACE INTO Employees (id, name, surname) VALUES ((SELECT id FROM Employees WHERE id = $id),  $name,  $surname)\",\n  { '$id': '1', '$name': 'peter', '$surname': 'bitcoin' }\n)\n```\n\n### fac.cupsert\n\nProvides a simple way to check and process data before an upsert.\n\nExample:\n\n```js\nfac.cupsert({\n  table: 'Employees',\n  selectKey: 'id',\n  selectValue: '1',\n  process: (data, cb) => {\n    data[0].surname = 'diaz'\n    cb(null, data[0])\n  }\n}, cb)\n```\n\n### fac.runMigrations\n  - `migrations`: &lt;Array&gt;\n    - `inex 0..x`: &lt;Function&gt;\n  - `cb`: &lt;Function&gt;\n\nRuns an array of functions (migrations).\n\n  Each function in the migrations array is passed the faculty instance and a callback.\n\nAssumptions:\n 1.  `PRAGMA user_version` will be used to track migrations.  It is assumed to unused and will increment as an id for the index of the migrations array\n 1.  New migrations will always be added to the end of the migrations array and old migrations shall never be deleted from the array.  The `PRAGMA user_version` will track which migrations in the migration array which have run and only run new migrations.\n 1.  Each migration is automatically wrapped in a TRANSACTION.   Migrations will stop running on any error.\n\n#### Example Migrations\n\n```js\n// api.my.wrk.js\n  init () {\n    super.init()\n\n    this.setInitFacs([\n      ['fac', 'bfx-facs-db-sqlite', 'main', 'main', {\n        name: this.prefix,\n        persist: true\n      }]\n    ])\n\n  }\n\n  _start (cb) {\n    const migrations = [\n      (dsm, cb) => {\n        dsm.db.run('ALTER TABLE token_sales ADD COLUMN listed INTEGER;', cb)\n      }\n    ]\n\n    async.series([\n      next => { super._start(next) },\n      next => { this.dbSqlite_main.runMigrations(migrations, next) }\n    ], cb)\n  }\n```\n\n## Config\n\n### name\n\nUsed to construct the database name: sqlite_$NAME_$LABEL.db\n\n### label\n\nUsed to construct the database name: sqlite_$NAME_$LABEL.db\n\n### runSqlAtStart\n\nRuns SQLite commands at start of the service.\nUseful to create a table if it does not exist.\nTakes an array commands to run.\n\n**Example fields:**\n\n```\n{\n  \"runSqlAtStart\": [\n    'CREATE TABLE IF NOT EXISTS vegetables (id INTEGER PRIMARY KEY ASC, sold, price)',\n    'CREATE TABLE IF NOT EXISTS meat (id INTEGER PRIMARY KEY ASC, sold, price)'\n  ]\n}\n```\n","readmeFilename":"README.md","_rev":"1-d84112457bea60e961772493e0930d8f"}