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

Range on user defined integer #253

Open
mentalmap opened this issue Sep 10, 2019 · 0 comments
Open

Range on user defined integer #253

mentalmap opened this issue Sep 10, 2019 · 0 comments

Comments

@mentalmap
Copy link

mentalmap commented Sep 10, 2019

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/asdine/storm"
	bolt "go.etcd.io/bbolt"
)

type Sequence uint32

type Data struct {
	ID    Sequence `storm:"id"`
	Value string
}

func main() {
	db, err := storm.Open("my.db", storm.BoltOptions(0600, &bolt.Options{Timeout: 1 * time.Second}))
	if err != nil {
		log.Panicln(err)
	}
	defer db.Close()

	for i := 1; i <= 10; i++ {
		d := Data{ID: Sequence(i), Value: fmt.Sprintf("value_%d", i)}
		_ = db.Save(&d)
	}

	var result []Data
	_ = db.Range("ID", Sequence(0), Sequence(10), &result)

	log.Println(result)
}

The output is:

[{1 value_1} {10 value_10}]

not

[{1 value_1} {2 value_2} {3 value_3} {4 value_4} {5 value_5} {6 value_6} {7 value_7} {8 value_8} {9 value_9} {10 value_10}]
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

1 participant