{"name":"hyperdb","version":"4.0.2","author":{"name":"Holepunch Inc"},"license":"Apache-2.0","_id":"hyperdb@4.0.2","homepage":"https://github.com/holepunchto/hyperdb","bugs":{"url":"https://github.com/holepunchto/hyperdb/issues"},"dist":{"shasum":"f3447b930888f46d057b80a7e64caf93f0d50f70","tarball":"http://registry-npm.ywwl.com/hyperdb/download/hyperdb-4.0.2.tgz","fileCount":11,"integrity":"sha512-02A0HBjV1eeQw10CmTzps0WCrz1J0UN3VJjtJ7vzhyjJ3U+qK42jJxWx87gk/FFbhdKh5HsH97yCq17Q5GYwEw==","signatures":[{"sig":"MEYCIQDvoYTYzxLUE+WfdBa/5ZZEdtjAckRbPJp11JE9LSEuxQIhAKnY8G96EuSvwFEi60qPlXVO31cHtZ6TBH48sjpkHbyN","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":65817,"size":17337,"noattachment":false,"key":"/hyperdb/-/hyperdb-4.0.2.tgz"},"main":"index.js","gitHead":"aabf324ab6e7adf3474c87e57b1058d8701fa375","imports":{"fs":{"bare":"bare-fs","default":"fs"},"path":{"bare":"bare-path","default":"path"}},"scripts":{"test":"standard && brittle test/*.js","generate":"rm -rf test/fixtures/generated && node test/fixtures/generate.js"},"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"repository":{"url":"git+https://github.com/holepunchto/hyperdb.git","type":"git"},"_npmVersion":"10.7.0","description":"P2P Indexable Database","directories":{},"_nodeVersion":"20.11.1","dependencies":{"b4a":"^1.6.6","streamx":"^2.20.0","hyperbee":"^2.20.4","hyperschema":"^1.0.0","index-encoder":"^3.2.0","rocksdb-native":"^2.3.1","generate-string":"^1.0.1","compact-encoding":"^2.15.0","generate-object-property":"^2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"brittle":"^3.7.0","standard":"^17.1.0","test-tmp":"^1.2.1","hypercore":"^10.37.22"},"_npmOperationalInternal":{"tmp":"tmp/hyperdb_4.0.2_1731333996159_0.5683016019104701","host":"s3://npm-registry-packages"},"readme":"# hyperdb\n\nDatabase built for P2P and local indexing\n\n```\nnpm install hyperdb\n```\n\n## Usage\n\nFirst generate your definition with the builder.\nThe definition defines the schemas and collections you wanna use.\n\n```js\n// TODO (see ./example here for now)\n```\n\nThen boot your db. You can use the same definition for a fully local db and a P2P one.\n\n``` js\nconst HyperDB = require('hyperdb')\n\n// first choose your engine\nconst db = HyperDB.rocks('./my-rocks.db', require('./my-definition'))\n```\n\nIt is that simple.\n\n## API\n\n#### `db = Hyperdb.bee(hypercore, definition, [options])`\n\nMake a db backed by Hyperbee. P2P!\n\n#### `db = Hyperdb.rocks(path, definition, [options])`\n\nMake a db backed by RocksDB. Local only!\n\n#### `queryStream = db.find(collectionOrIndex, query, [options])`\n\nQuery the database. `collectionOrIndex` is the identifier you defined in your builder.\n\nThe query looks like this\n\n``` js\n{\n  gt: { ... },\n  gte: { ... },\n  lt: { ...},\n  lte: { ...}\n}\n```\n\nAnd options include\n\n```js\n{\n  limit, // how many max?\n  reverse // reverse stream?\n}\n```\n\nSee the basic tests for an easy example on how queries look like.\n\nThe `queryStream` is a streamx readable stream that yields the documents you search for.\n\nA query is always running on a snapshot, meaning any inserts/deletes you do while this is running\nwill not impact the query stream itself.\n\n#### `all = await queryStream.toArray()`\n\nStream helper to simply get all the remaining entries in the stream.\n\n#### `one = await queryStream.one()`\n\nStream helper to simply get the last entry in the stream.\n\n#### `doc = await db.findOne(collectionOrIndex, query, [options])`\n\nAlias for `await find(...).one()`\n\n#### `doc = await db.get(collection, query)`\n\nGet a document from a collection\n\n#### `{ count } = await db.stats(collectionOrIndex)`\n\nGet stats, about a collection or index with stats enabled.\n\n#### `await db.insert(collection, doc)`\n\nInsert a document into a collection. NOTE: you have to flush the db later for this to be persisted.\n\n#### `await db.delete(collection, query)`\n\nDelete a document from a collection. NOTE: you have to flush the db later for this to be persisted.\n\n#### `bool = db.updated([collection], [query])`\n\nReturns a boolean indicating if this database was updated. Pass a collection and doc query to know if\na specific record was updated.\n\n#### `await db.flush()`\n\nFlush all changes to the db\n\n#### `db.reload()`\n\nReload the internal snapshot. Clears the memory state.\n\n#### `db = db.snapshot()`\n\nMake a readonly snapshot of the database. All reads/streams are locked in time on a snapshot from the time you call the snapshot method.\n\n#### `db = db.transaction()`\n\nMake a writable snapshot of the database. All reads/streams are locked in time on a snapshot from the time you call the snapshot method.\nWhen you flush this one, it updates the main instance also.\n\n#### `await db.close()`\n\nClose the database. You have to close any snapshots you use also.\n\n## Builder API\n\nSee [example](./builder/example.js).\n\nEach field in the builder file is an object:\n```\n{\n  name: 'field-name',\n  type: 'uint', // a compact-encoding type, or a reference to another encoding defined in the builder file\n  required: true, // false for optional\n  array: false // Store an array of 'type', instead of just one (default false)\n}\n```\n\n## License\n\nApache-2.0\n","publish_time":1731333996333,"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"andrewosh","email":"andrewosh@gmail.com"}],"_cnpm_publish_time":1731333996333,"dist-tags":{"latest":"6.11.1","tmp":"4.22.3"}}