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

chore: upgrade the embedded-kv example #465

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/1.5.0/embedded/embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ The following example shows how to create or open a store, write some data and r

<WrappedSection>

<<< @/src/code-examples/go/embedded-kv/main.go
<<< @/src/code-examples/go/embedded-kv-v1.5.0/main.go

</WrappedSection>
2 changes: 1 addition & 1 deletion src/1.9DOM.0/embedded/embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ The following example shows how to create or open a store, write some data and r

<WrappedSection>

<<< @/src/code-examples/go/embedded-kv/main.go
<<< @/src/code-examples/go/embedded-kv-v1.5.0/main.go

</WrappedSection>
17 changes: 17 additions & 0 deletions src/code-examples/go/embedded-kv-v1.5.0/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/codenotary/hello-embedded-immutable-world

go 1.18

require github.com/codenotary/immudb v1.5.0

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
golang.org/x/sys v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
34 changes: 34 additions & 0 deletions src/code-examples/go/embedded-kv-v1.5.0/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/codenotary/immudb v1.5.0 h1:G5T+j/gOtzZ8Vb+Lww1e+FBaSHM1Rgm860StNaBWRTs=
github.com/codenotary/immudb v1.5.0/go.mod h1:UGvbgAuP8dScEbYRnldJiVXQfzTDiqeRo0F3I2jdiCw=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM=
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
52 changes: 52 additions & 0 deletions src/code-examples/go/embedded-kv-v1.5.0/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"context"
"fmt"
"log"

"github.com/codenotary/immudb/embedded/store"
)

func handleErr(err error) {
if err != nil {
log.Fatal(err)
}
}

func main() {
// create/open immudb store at specified path
st, err := store.Open("data", store.DefaultOptions())
handleErr(err)

// close the store to free resources
defer st.Close()

// create a transaction
tx, err := st.NewTx(context.Background(), &store.TxOptions{Mode: store.ReadWriteTx})
handleErr(err)

// ensure tx is closed (it won't affect committed tx)
defer tx.Cancel()

// write key-value pair into the tx context, no change will be applied yet
err = tx.Set([]byte("hello"), nil, []byte("immutable-world!"))
handleErr(err)

// transaction is committed and changes are applied
hdr, err := tx.Commit(context.Background())
handleErr(err)

fmt.Printf("tx %d successfully committed\n", hdr.ID)

// fetch the latest entry of a key
// dsue to performance considerations, only metadata, hash, and size are returned at first
valRef, err := st.Get([]byte("hello"))
handleErr(err)

// read the actual value
val, err := valRef.Resolve()
handleErr(err)

fmt.Printf("key '%s' = '%s' found at tx %d (%d key-updates)\n", []byte("hello"), val, valRef.Tx(), valRef.HC())
}
2 changes: 1 addition & 1 deletion src/master/embedded/embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ The following example shows how to create or open a store, write some data and r

<WrappedSection>

<<< @/src/code-examples/go/embedded-kv/main.go
<<< @/src/code-examples/go/embedded-kv-v1.5.0/main.go

</WrappedSection>
Loading