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

Having trouble getting q.In to work #249

Open
u89012 opened this issue May 12, 2019 · 1 comment
Open

Having trouble getting q.In to work #249

u89012 opened this issue May 12, 2019 · 1 comment

Comments

@u89012
Copy link

u89012 commented May 12, 2019

Hello everyone! Love the package! But stuck with a weird problem -- can't get q.In to work, perhaps I'm doing something wrong, or perhaps I've hit a bug in the library, can someone please help?

package main

import (
	"fmt"
	"log"

	"github.com/asdine/storm"
	"github.com/asdine/storm/q"
)

type Foo struct {
	Id    int64    `storm:"id,increment"`
	Title string   `storm:"index"`
	Tags  []string `storm:"index"`
}

func main() {
	if db, e := storm.Open("db/test.db"); e != nil {
		log.Fatal("Couldn't open database")
	} else {
		defer db.Close()

		db.Save(&Foo{Title: "Lorem", Tags: []string{"foo", "bar"}})
		db.Save(&Foo{Title: "Ipsum", Tags: []string{"foo", "bax"}})
		db.Save(&Foo{Title: "Doler", Tags: []string{"quux", "baz"}})

		{
			var a []Foo
			if e := db.Select().Find(&a); e != nil {
				panic(e)
			} else {
				fmt.Println(a)
			}
		}

		{
			var a Foo
			if e := db.One("Title", "Lorem", &a); e != nil {
				panic(e)
			}
		}

		{ 
			var a []Foo
			if e := db.Select(q.In("Tags", []string{"quux"})).Find(&a); e != nil {
				panic(e) // yikes
			}
		}
	}
}
@mwmahlberg
Copy link

As far as I understood it, q.In is for comparing wether a single value field (not a slice) matches one of the given values in the slice.

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

2 participants