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

Organizing/modeling Views #32

Closed
felixbecker opened this issue Sep 4, 2017 · 3 comments
Closed

Organizing/modeling Views #32

felixbecker opened this issue Sep 4, 2017 · 3 comments

Comments

@felixbecker
Copy link

Hi,

I have a question regarding the example-2 which pobpulates an rest api so one can access the number of clicks for a given user-id as key.
How would I implement a list of users with their number of clicks? ( basically a View.all() if this would even make sense ).
Or Would this be something I have to manage in a processor function? Like a slice of users with their id and clicks? Or is there a way to iterate over the keys? What would be the recommended way?

Any plans to extend the docs or examples for more advanced scenarios covering Lookup, Join, Loopback, etc?

Thanks for your feedback in advance.

@db7
Copy link
Collaborator

db7 commented Sep 5, 2017

Hi Felix,

to iterate over all key-value pairs of a table, we use View.Iterator() which should be pretty soon merged to the master.

And yes, we do have plans to extend the docs. Have you checked this blog post? We should probably link it in the README at some point.

@felixbecker
Copy link
Author

Hi, thanks for your reply. I think View.Iterator() interface would be a great fit.
I saw the blog post and I am looking forward to other posts in that series since it made me curious for more.

@SamiHiltunen
Copy link
Contributor

Hey @felixbecker, we just merged #33. This gives you access to an iterator that iterates over the whole view. Let me know if any issues arise. Example assuming string values:

state, err = view.Iterator()
if err != nil {
  log.Fatalf("error getting iterator: %v", err)
}
defer state.Release()

for state.Next() {
  key := state.Key()
  val, err := state.Value()
  if err != nil {
    log.Fatalf("error getting value from iterator: %v", err)
  }

  log.Printf("key: %s, value: %s", string(key), val.(string))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants