You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 30, 2023. It is now read-only.
*[Creating Custom Data Stores](#creating-custom-data-stores)
42
+
-[Contributing](#contributing)
43
+
-[License](#license)
23
44
24
-
Load the database using locally persisted state. Can specify how many entries to load with `amount` argument.
45
+
<!-- tocstop -->
25
46
26
-
##### `saveSnapshot()`
47
+
##API
27
48
28
-
Save the current state of the database locally. Returns a *Promise* that resolves to a IPFS Multihash as a Base58 encoded string. The the database can be loaded using this hash.
**ipfs** can be an [IPFS](https://github.com/ipfs/js-ipfs) instance or an [IPFS-API](https://github.com/ipfs/js-ipfs) instance. **peerId** is a string identifying the peer, usually the base58 string of the [PeerId](https://github.com/libp2p/js-peer-id#tob58string) of the IPFS instance. **address** is the OrbitDB address to be used for the store.
31
52
32
-
Load the state of the database from a snapshot. *hash*is the IPFS Multihash of the snapshot data. Returns a *Promise* that resolves when the database has been loaded.
53
+
`options`is an object with the following required properties:
33
54
34
-
##### `close()`
55
+
-`cache`: A [Cache](https://github.com/orbitdb/orbit-db-cache) instance to use for storing heads and snapshots.
56
+
-`Index` : By default it uses an instance of [Index](https://github.com/orbitdb/orbit-db-store/blob/master/src/Index.js).
57
+
-`keystore`: A [Keystore](https://github.com/orbitdb/orbit-db-keystore) instance to use for key management.
35
58
36
-
Uninitialize the store. Emits `close` after the store has been uninitialized.
59
+
the following properties are optional:
37
60
38
-
##### `drop()`
61
+
-`maxHistory` (Integer): The number of entries to load (Default: `-1`).
62
+
-`referenceCount` (Integer): The number of previous ipfs-log entries a new entry should reference (Default: `64`).
63
+
-`replicationConcurrency` (Integer): The number of concurrent replication processes (Default: `128`).
64
+
-`key`: A [KeyPair](https://github.com/indutny/elliptic/blob/master/lib/elliptic/ec/key.js#L8) instance. By default the provided keystore is used to find an existing KeyPair for the given `peerId`, otherwise a new KeyPair will be created using the given `peerId`.
65
+
-`accessController` (Object): By default only the owner will have write access.
66
+
-`onClose` (Function): A function to be called with a string of the OrbitDB address of the database that is closing.
39
67
40
-
Remove the database locally. This doesn't remove or delete the database from peers who have replicated the database.
68
+
### Public methods
41
69
42
-
##### `sync(heads)`
70
+
#### load([amount])
71
+
> Load the database using locally persisted state.
43
72
44
-
Sync this database with entries from *heads* where *heads* is an array of ipfs-log Entries. Usually, you don't need to call this method manually as OrbitDB takes care of this for you.
73
+
Returns a **Promise** that resolves once complete. Provide an `amount` argument to specify how many entries to load.
45
74
46
-
#### Properties
75
+
#### loadMoreFrom(amount, entries)
76
+
> TODO
47
77
48
-
##### `address`
78
+
```javascript
79
+
//TODO
80
+
db.loadMoreFrom()
81
+
```
82
+
83
+
#### saveSnapshot()
84
+
> Save the current state of the database locally.
85
+
86
+
Returns a **Promise** that resolves to an array containing an object with the following properties:
87
+
88
+
-`path` of the snapshot file
89
+
-`hash` representing the IPFS Multihash (as a Base58 encoded string) of the snapshot file
90
+
-`size` of the snapshot file
91
+
92
+
#### loadFromSnapshot()
93
+
> Load the state of the database from a snapshot.
94
+
95
+
Returns a **Promise** that resolves to a store instance once it has been loaded.
96
+
97
+
#### close()
98
+
> Uninitialize the store.
99
+
100
+
Returns a **promise** that resolves once complete. Emits `close` after the store has been uninitialized.
49
101
50
-
Get the address of this database. Returns an object `{ root: <manifestHash>, path: <path> }`. Convert to a string with `db.address.toString()`.
102
+
#### drop()
103
+
> Remove the database locally.
104
+
105
+
Returns a **promise** that resolves once complete. This doesn't remove or delete the database from peers who have replicated the database.
106
+
107
+
#### sync(heads)
108
+
> Sync this database with entries from **heads** where **heads** is an array of ipfs-log Entries.
109
+
110
+
Usually, you don't need to call this method manually as OrbitDB takes care of this for you.
111
+
112
+
### Properties
113
+
114
+
#### address
115
+
> Get the address of this database.
116
+
117
+
Returns an object `{ root: <manifestHash>, path: <path> }`. Convert to a string with `db.address.toString()`.
Store has an `events` ([EventEmitter](https://nodejs.org/api/events.html)) object that emits events that describe what's happening in the database.
86
165
87
-
-`load` - (dbname, hash)
166
+
-`load` - (address, heads)
88
167
89
-
Emitted before loading the database history. *hash* is the hash from which the history is loaded from.
168
+
Emitted before loading the database history. **address** is a string of the OrbitDB address that emitted the event. **heads**is an array of ipfs-log Entries.
90
169
91
170
```javascript
92
-
db.events.on('load', (id, hash) =>... )
171
+
db.events.on('load', (address, heads) =>... )
93
172
db.load()
94
173
```
95
174
96
-
-`ready`- (dbname)
175
+
-`ready`- (address, heads)
97
176
98
-
Emitted after fully loading the database history.
177
+
Emitted after fully loading the database history.**address** is a string of the OrbitDB address that emitted the event. **heads** is an array of ipfs-log Entries.
*Progress* is the current load count. *Total* is the maximum load count (ie. lengthof the full database). These are useful eg. for displaying a load progress percentage.
186
+
Emitted for each entry during load. **address** is a string of the OrbitDB address that emitted the event. **hash** is the multihash of the entry that was just loaded. **entry** is the ipfs-log Entry that was loaded. **Progress** is the current load count. **Total** is the maximum load count (ie. lengthof the full database). These are useful eg. for displaying a load progress percentage.
Emitted before replicating a part of the database. **address** is a string of the OrbitDB address that emitted the event. **entry** is the ipfs-log Entry that is being processed.
Emitted while replicating a database. **address** is a string of the OrbitDB address of the database that emitted the event. **hash** is the multihash of the entry that was just replicated. **entry** is the ipfs-log Entry that was replicated. **progress** is an integer representing the current progress. **total** is an integer representing the remaining operations.
Emitted after the database was synced with an update from a peer database. **address** is a string of the OrbitDB address that emitted the event. **logCount**...
Emitted after the databasewas synced withan update from a peer database.
219
+
Emitted after an entry was added locally to the database. **address** is a string of the OrbitDB address that emitted the event. **entry** is the Entry that was added. **heads** is an array of ipfs-log Entries.
Emitted after an entry was added locally to the database. *hash* is the IPFS hash of the latest state of the database. *entry* is the Entry that was added.
227
+
Emitted once the database has finished closing. **address** is a string of the OrbitDB address that emitted the event.
127
228
128
229
```javascript
129
-
db.events.on('write', (id, hash, entry) => ... )
230
+
db.events.on('closed', (address) => ... )
231
+
db.close()
130
232
```
131
233
132
-
#### Private methods
234
+
### Private methods
133
235
134
-
##### `_addOperation(data)`
236
+
#### _addOperation(data)
237
+
> Add an entry to the store.
135
238
136
-
Add an entry to the store. Takes`data` as a parameter which can be of any type.
239
+
Returns a **Promise** that resolves to the IPFS Multihash of the added entry. Takes`data` as a parameter which can be of any type.
137
240
138
241
```javascript
139
242
this._addOperation({
@@ -153,9 +256,9 @@ const Store = require('orbit-db-store');
0 commit comments