storm icon indicating copy to clipboard operation
storm copied to clipboard

get all elements that matches an interface

Open tgirod opened this issue 6 years ago • 1 comments

It would be convenient to be able to do that:

type ExoA struct {
	ID  int `storm:"increment"`
	Foo int
}

type ExoB struct {
	ID  int `storm:"increment"`
	Bar string
}

type Exercice interface {
	// something here
}

func main() {
	db, _ := storm.Open("test.db")
	a := ExoA{1, 42}
	b := ExoB{1, "yeah"}
	db.Save(&a)
	db.Save(&b)

	ex := []Exercice{}
	db.All(&ex)
	fmt.Println(ex)
}

Currently, ex will be empty. It would make sense for it to contain elements a and b

tgirod avatar Oct 29 '18 08:10 tgirod

I'm afraid that's not possible because interfaces express behaviours not fields and Storm only cares about fields. There's no information about the type used to encode data in Storm, only raw data. Also, Storm uses the name of the struct to identify the right bucket to query.

asdine avatar Dec 22 '18 20:12 asdine