{"library":"ssb-db2","title":"SSB-DB2","type":"library","description":"SSB-DB2 is a new database for secure-scuttlebutt, designed as a replacement for the older `ssb-db`. Currently at version 8.1.0, it offers significant architectural changes aimed at improving performance and flexibility. Key differentiators include using `bipf` for data storage, replacing `flume` with `jitdb` for specialized indexes, supporting browser environments via `ssb-browser-core`, and enabling efficient partial replication. It has expanded capabilities beyond `ssb-db`, featuring deletion and compaction, support for customizable feed and encryption formats (defaulting to `ssb-classic`), and a powerful query language based on composable JavaScript functions. SSB-DB2 operates as a `secret-stack` plugin, registering within the `db` namespace, and is optimized for modern Node.js environments (>=16).","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install ssb-db2"],"cli":null},"imports":["import SecretStack from 'secret-stack'","import ssbdb2 from 'ssb-db2'","import { where, and, type, author, toCallback } from 'ssb-db2/operators'"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/ssb-ngi-pointer/ssb-db2","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/ssb-db2","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"const SecretStack = require('secret-stack')\nconst caps = require('ssb-caps')\nconst fs = require('fs')\nconst path = require('path')\n\nconst testPath = './temp-ssb-db2-quickstart'\n\n// Ensure a clean state for the quickstart\nif (fs.existsSync(testPath)) {\n  fs.rmSync(testPath, { recursive: true, force: true });\n}\nfs.mkdirSync(testPath, { recursive: true });\n\nconst sbot = SecretStack({ caps })\n  .use(require('ssb-db2'))\n  .call(null, { path: testPath })\n\nsbot.db.create({ content: { type: 'post', text: 'hello from ssb-db2!' } }, (err, msg) => {\n  if (err) {\n    console.error('Error publishing message:', err);\n    sbot.close()\n    return;\n  }\n  console.log('Published message:', msg.value.content);\n\n  const { where, type, toCallback } = require('ssb-db2/operators');\n  sbot.db.query(\n    where(type('post')),\n    toCallback((err, msgs) => {\n      if (err) {\n        console.error('Error querying messages:', err);\n      } else {\n        console.log('Found ' + msgs.length + ' post messages:');\n        msgs.forEach(m => console.log('- ' + m.value.content.text));\n      }\n      sbot.close();\n      fs.rmSync(testPath, { recursive: true, force: true }); // Clean up\n    })\n  );\n});","lang":"javascript","description":"This quickstart demonstrates how to set up an SSB peer with ssb-db2, publish a message, and then query for 'post' messages using the new query operators.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}