objectbox / objectbox-go

Embedded Go Database, the fast alternative to SQLite, gorm, etc.
https://objectbox.io
Apache License 2.0
1.07k stars 46 forks source link

Multiple struct tags not working #24

Closed delaneyj closed 3 years ago

delaneyj commented 4 years ago

It's not mentioned in the docs if unique cause an index to be generated so I added to the tagged literal but this doesn't seem to be support at this time.

type Foo struct {
    ID   uint64 `objectbox:"id"`
    Name string `objectbox:"index,unique"`
}

Generation give can't prepare bindings for feeds.go: unknown annotation index,unique on property Name found in Foo

vaind commented 4 years ago

Annotations are space separated, so a working example would look like this:

type Foo struct {
    ID   uint64 `objectbox:"id"`
    Name string `objectbox:"index unique"`
}

Also note there's no point in combining index and unique unless you specify a non-default index type (https://golang.objectbox.io/entity-annotations#index-types-string). Unique annotation implies index automatically and uses the default index type based on the variable type ("hash" for strings).

greenrobot commented 4 years ago

Would you see be any disadvantage in being more tolerant here, e.g. using comma OR space?

delaneyj commented 4 years ago

json,bson,etc use the comma. Iirc its not defined in the go spec. @vaind, didn't know if the unique cause effected .Put calls or created an index. Thought it might but far as I saw it wasn't documented.

greenrobot commented 4 years ago

So we should also support commas...

vaind commented 3 years ago

released in https://github.com/objectbox/objectbox-go/releases/tag/v1.2.0