timshannon / badgerhold

BadgerHold is an embeddable NoSQL store for querying Go types built on Badger
MIT License
515 stars 52 forks source link

README.MD - data by value #27

Closed nicewook closed 4 years ago

nicewook commented 4 years ago

I don't get it. Do I have to pass data by value or data by reference?

If you want to know the value of the auto-incrementing Key that was generated using badgerhold.NextSequence(), then make sure to pass your data by value and that the badgerholdKey tagged field is of type uint64.

err := store.Insert(badgerhold.NextSequence(), &data)

More questions

  1. Do I need to set index tag for key, too? for example.

type TransactionLog struct { TransactionID uint64 json:"transactionID" badgerhold:"key" badgerhold:"index" }

  1. Can I use multiple badgerhold tags? for example

type TransactionLog struct { Timestamp time.Time json:"timestamp" badgerhold:"index,unique" }

timshannon commented 4 years ago

I don't get it. Do I have to pass data by value or data by reference?

Thanks, I corrected this in the README.

More questions

1. Do I need to set `index` tag for key, too? for example.

No. Key values are what the entire record is already ordered on, so it doesn't make sense to add an index for a Key value.