https://github.com/icefiredb/icefiredb-ipfs-log
icefiredb-ipfs-log: distributed data storage and synchronization.
https://github.com/icefiredb/icefiredb-ipfs-log
Last synced: 10 months ago
JSON representation
icefiredb-ipfs-log: distributed data storage and synchronization.
- Host: GitHub
- URL: https://github.com/icefiredb/icefiredb-ipfs-log
- Owner: IceFireDB
- License: apache-2.0
- Created: 2022-08-25T06:26:13.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-06T10:34:26.000Z (over 1 year ago)
- Last Synced: 2025-04-12T08:04:49.443Z (10 months ago)
- Language: Go
- Homepage:
- Size: 170 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE-OF-CONDUCT.md
Awesome Lists containing this project
README
# icefiredb-ipfs-log
icefiredb-ipfs-log is a distributed immutable, operation-based conflict-free replication data structure that relies on ipfs to store data and merges each peer node data based on pubsub conflict-free.
You can easily implement custom data structures such as kv, event, nosql, etc. based on icefiredb-ipfs-log.
### Conflict-free log replication model
```shell
Log A Log B
| |
logA.append("one") logB.append("hello")
| |
v v
+-----+ +-------+
|"one"| |"hello"|
+-----+ +-------+
| |
logA.append("two") logB.append("world")
| |
v v
+-----------+ +---------------+
|"one","two"| |"hello","world"|
+-----------+ +---------------+
| |
| |
logA.join(logB) <----------+
|
v
+---------------------------+
|"one","hello","two","world"|
+---------------------------+
```
### Example of building a key-value database using icefiredb-ipfs-log
- memory key-value:[memory-kv](./stores/kv/db.go)
- leveldb kv :[leveldb-kv](./stores/levelkv/db.go)
### Use of key-value databases
[Detailed usage example reference](./example)
```go
func main() {
ctx := context.TODO()
// disk cache directory
rootPath := "./kvdb"
node, api, err := iflog.CreateNode(ctx, rootPath)
if err != nil {
panic(err)
}
hostAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/ipfs/%s", node.PeerHost.ID().Pretty()))
for _, a := range node.PeerHost.Addrs() {
fmt.Println(a.Encapsulate(hostAddr).String())
}
log := zap.NewNop()
dbname := "iflog-event-kv"
ev, err := iflog.NewIpfsLog(ctx, api, dbname, &iflog.EventOptions{
Directory: rootPath,
Logger: log,
})
if err != nil {
panic(err)
}
if err := ev.AnnounceConnect(ctx, node); err != nil {
panic(err)
}
kvdb, err := kv.NewKeyValueDB(ctx, ev, log)
if err != nil {
panic(err)
}
// Load old data from disk
if err := ev.LoadDisk(ctx); err != nil {
panic(err)
}
kvdb.Put(ctx, "one", "one")
kvdb.Get("one")
kvdb.Delete(ctx, "one")
}
```
### Some code reference sources
- [go-ipfs-log](https://github.com/berty/go-ipfs-log)
## License
icefiredb-ipfs-log is under the Apache 2.0 license. See the LICENSE directory for details.