Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example, and link it from the README #5

Open
moul opened this issue Aug 8, 2019 · 7 comments
Open

Add an example, and link it from the README #5

moul opened this issue Aug 8, 2019 · 7 comments

Comments

@moul
Copy link
Member

moul commented Aug 8, 2019

No description provided.

@jryebread
Copy link

+1, just came across this awesome package and would be great to see an example with how joins work.

@diyism
Copy link

diyism commented May 19, 2022

A complete but not so simple example: https://github.com/mrusme/superhighway84/blob/master/database/database.go

GitHub
USENET-inspired, uncensorable, decentralized internet discussion system running on IPFS & OrbitDB - superhighway84/database.go at master · mrusme/superhighway84

@diyism
Copy link

diyism commented May 19, 2022

I'm trying to figure out a simplest go-orbit-db example code (test.go):

package main

import
(	"context"
	"time"
	"fmt"
	goOrbitDb "berty.tech/go-orbit-db"
	ifGoIpfsCore "github.com/ipfs/interface-go-ipfs-core"
	//"go.uber.org/zap"
	"berty.tech/go-orbit-db/stores/documentstore"
	"berty.tech/go-orbit-db/accesscontroller"
	"berty.tech/go-orbit-db/iface"
	"github.com/ipfs/go-ipfs/core"
	"github.com/ipfs/go-ipfs/repo/fsrepo"
	"github.com/ipfs/go-ipfs/core/node/libp2p"
	"github.com/ipfs/go-ipfs/core/coreapi"
)

func main()
{	CachePath:="./db_cache"
	storetype:="docstore"
	ac:=&accesscontroller.CreateAccessControllerOptions{Access: map[string][]string{"write": {"*"}}}

	//var Logger *zap.Logger
	var ConnectionString string="/orbitdb/bafyreifdpagppa7ve45odxuvudz5snbzcybwyfer777huckl4li4zbc5k4/superhighway84"

	ctx,cancel := context.WithTimeout(context.Background(), 600*time.Second)
	defer cancel()


	_,ifIpfs,err := createNode(ctx, "./")

	//Logger.Debug("initializing NewOrbitDB ...")
	OrbitDB,err := goOrbitDb.NewOrbitDB(	ctx,
											ifIpfs,
											&goOrbitDb.NewOrbitDBOptions{	Directory:&CachePath},
										)
	if err!=nil {	fmt.Printf("%+v", err); return}

	//Logger.Debug("initializing OrbitDB.Docs ...")
	Store,err := OrbitDB.Docs(	ctx,
								ConnectionString,
								&goOrbitDb.CreateDBOptions{	AccessController: ac,
															StoreType: &storetype,
															StoreSpecificOpts: documentstore.DefaultStoreOptsForMap("id"),
															Timeout: time.Second*600,
														},
							)
	if err != nil {	fmt.Printf("%+v", err); return}

	doc1 := map[string]interface{}{"_id": "doc1", "hello": "world"}
	_, err = Store.Put(ctx, doc1)
	fmt.Printf("%+v", "jack")

	docs, err := Store.Get(ctx, "doc1", &iface.DocumentStoreGetOptions{CaseInsensitive: false})
	fmt.Printf("%+v", docs)
}


func createNode(ctx context.Context, repoPath string) (*core.IpfsNode, ifGoIpfsCore.CoreAPI, error) {
  repo, err := fsrepo.Open(repoPath)
  if err != nil {
    return nil, nil, err
  }

  nodeOptions := &core.BuildCfg{
    Online:  true,
    Routing: libp2p.DHTClientOption, // DHTOption
    Repo: repo,
    ExtraOpts: map[string]bool{
      "pubsub": true,
    },
  }

  node, err := core.NewNode(ctx, nodeOptions)
  if err != nil {
    return nil, nil, err
  }

  coreAPI, err := coreapi.NewCoreAPI(node)
  if err != nil {
    return nil, nil, err
  }

  return node, coreAPI, nil
}

// the go.mod file:

module test
go 1.18
require (
	github.com/ipfs/interface-go-ipfs-core v0.5.2
)
require (
	github.com/lucas-clemente/quic-go v0.26.0 // indirect
)

// must lock the interface-go-ipfs-core version, or else show error ""undefined: blockstore.ErrNotFound""
$ go mod tidy
$ export IPFS_PATH=./
$ ipfs init
$ go run test.go

No luck , it shows:

unknown datastore type: flatfs

@mp-netis
Copy link

mp-netis commented Jun 8, 2022

@diyism I had the same issue until I added IPFS Plugins. It seems flatfs is implemented as a builtin plugin, so you need to include plugin support. Any luck creating a working example?

@flowpoint
Copy link

flowpoint commented Nov 8, 2022

based on the above, i bolted together a dirty example. no guarantees.
https://gist.github.com/flowpoint/0643f7239920387e0de8e335fdbd18dd

Gist
dirty example to use go-orbitdb eventlog. GitHub Gist: instantly share code, notes, and snippets.

@jefft0
Copy link
Collaborator

jefft0 commented Nov 29, 2023

When I run the example in the gist, it prints:

Computed default go-libp2p Resource Manager limits based on:
    - 'Swarm.ResourceMgr.MaxMemory': "8.6 GB"
    - 'Swarm.ResourceMgr.MaxFileDescriptors': 30720

Theses can be inspected with 'ipfs swarm resources'.

bafyreigotslg6nydukp3eqhybnhnkottgtjgrhqyd6hklz23j6qdn4w5cu&{Key:<nil> Op:ADD Value:[1 2] Docs:[] Entry:0x1400210c780}%

@jefft0
Copy link
Collaborator

jefft0 commented Feb 16, 2024

Keep this open as a tracking issue for adding examples. Put in backlog until we have more time to work on it.

@jefft0 jefft0 added the backlog label Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants