mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
docs: Move customization documentation to READMEs.
This commit is contained in:
parent
6c4a0ced0c
commit
ec461809ac
@ -55,4 +55,61 @@ const indexStorage = await CustomStorage()
|
||||
const db = await orbitdb.open('my-db', { entryStorage, headsStorage, indexStorage })
|
||||
```
|
||||
|
||||
## Custom Storage
|
||||
|
||||
Custom storage modules can be created for special use cases. A storage
|
||||
module must take the following form:
|
||||
|
||||
```js
|
||||
const CustomStorage = async (params) => { // Drop params if not required
|
||||
|
||||
const put = async (hash, data) => {
|
||||
// Puts the hash and data to the underlying storage. This is not required.
|
||||
// For example, the Events database uses add() to add a value without a
|
||||
// key.
|
||||
}
|
||||
|
||||
const get = async (hash) => {
|
||||
// Gets a record identified by hash from the underlying storage
|
||||
}
|
||||
|
||||
const del = async (hash) => {
|
||||
// Deletes a record identified by hash from the underlying storage
|
||||
}
|
||||
|
||||
const iterator = async function * () {
|
||||
// Iterates over the underlying storage's records
|
||||
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator
|
||||
}
|
||||
|
||||
const merge = async (other) => {
|
||||
// Merges the records from two storages
|
||||
}
|
||||
|
||||
const clear = async () => {
|
||||
// Clears all records from the underlying storage
|
||||
}
|
||||
|
||||
const close = async () => {
|
||||
// Closes the underlying storage
|
||||
}
|
||||
|
||||
return {
|
||||
put,
|
||||
del,
|
||||
get,
|
||||
iterator,
|
||||
merge,
|
||||
clear,
|
||||
close
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
It is recommended that all functions be defined for API consistency, but do not necessarily need to be implemented. For example, if the storage does not require closing, the close function can remain empty. For example:
|
||||
|
||||
```js
|
||||
const close = async () => {}
|
||||
```
|
||||
|
||||
See the [various storage implementations](../src/storage) to see how custom storage should be structured for compatibility with OrbitDB.
|
@ -2,58 +2,6 @@
|
||||
* @module Storage
|
||||
* @description
|
||||
* Various storage mechanisms with a common interface.
|
||||
*
|
||||
* ## Custom Storage
|
||||
* Custom storage modules can be created for special use cases. A storage
|
||||
* module must take the following form:
|
||||
* ```javascript
|
||||
* const CustomStorage = async (params) => { // drop params if not required
|
||||
* const put = async (hash, data) => {
|
||||
* // puts the hash and data to the underlying storage.
|
||||
* }
|
||||
*
|
||||
* const get = async (hash) => {
|
||||
* // gets a record identified by hash from the underlying storage
|
||||
* }
|
||||
*
|
||||
* const del = async (hash) => {
|
||||
* // deletes a record identified by hash from the underlying storage
|
||||
* }
|
||||
*
|
||||
* const iterator = async function * () {
|
||||
* // iterates over the underlying storage's records
|
||||
* // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator
|
||||
* }
|
||||
*
|
||||
* const merge = async (other) => {
|
||||
* // merges the records from two storages
|
||||
* }
|
||||
*
|
||||
* const clear = async () => {
|
||||
* // clears all records from the underlying storage
|
||||
* }
|
||||
*
|
||||
* const close = async () => {
|
||||
* // closes the underlying storage
|
||||
* }
|
||||
*
|
||||
* return {
|
||||
* put,
|
||||
* del,
|
||||
* get,
|
||||
* iterator,
|
||||
* merge,
|
||||
* clear,
|
||||
* close
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
* All functions must be defined but do not necessarily need to be implemented.
|
||||
* For example, if the storage does not require closing, the close function can
|
||||
* remain empty. For example:
|
||||
* ```JavaScript
|
||||
* const close = async () => {}
|
||||
* ```
|
||||
*/
|
||||
export { default as ComposedStorage } from './composed.js'
|
||||
export { default as IPFSBlockStorage } from './ipfs-block.js'
|
||||
|
Loading…
x
Reference in New Issue
Block a user