-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
29 lines (24 loc) · 717 Bytes
/
test.js
File metadata and controls
29 lines (24 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const IPFS = require("ipfs");
const OrbitDB = require("orbit-db");
async function main() {
// Connect to IPFS
const ipfs = await IPFS.create();
// Connect to OrbitDB
const orbitdb = await OrbitDB.createInstance(ipfs);
// Open the database you want to modify
const db = await orbitdb.open("database-name");
// Replace the value
const newRecord = { id: 1, value: "new value" };
const hash = db.address.root;
const index = db.getIndex("id");
const existingRecord = index.get(1);
if (existingRecord) {
db.del(existingRecord.hash);
db.put(newRecord);
}
// Close the database and disconnect from IPFS
await db.close();
await orbitdb.disconnect();
await ipfs.stop();
}
main();