storm
storm copied to clipboard
get all elements that matches an interface
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
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.