8000 get all elements that matches an interface · Issue #238 · asdine/storm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

get all elements that matches an interface #238

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

Open
tgirod opened this issue Oct 29, 2018 · 1 comment
Open

get all elements that matches an interface #238

tgirod opened this issue Oct 29, 2018 · 1 comment

Comments

@tgirod
Copy link
tgirod commented Oct 29, 2018

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

@asdine
Copy link
Owner
asdine commented Dec 22, 2018

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.

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

No branches or pull requests

2 participants
0