You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Guys,
Just messing around with objectbox-go for use as data storage for my app, and I came across the idea
of lazy loading related objects. I found that If I create a struct with more than 1 lazy loaded relation,
the generator breaks badly, to the point that if I remove all but 1 of the lazy defines on a relation, it works fine.
As I'm new to golang, I don't think I'm in the right headspace yet to fix it myself, but that being said, I can
point you in the direction I think needs the fix...
internal/generator/go/templates/binding.go
seems to be the first part to have issues, as with multiple lazy loaded relations, the templated code at line
165 misses a new line in the template, and causes errors in the code.
But then it totally dies somewhere in the templated code after line 193.
Granted those line numbers are from looking at the current source of the repo.
Below is my model.go file for the generator to have fun with.
`package model
//go:generate go run github.com/objectbox/objectbox-go/cmd/objectbox-gogen
type Token struct {
Id uint64
Token string
ExpiryDate uint64 objectbox:"date"
}
type Track struct {
Id uint64
path string objectbox:"index:hash64"
artistName string objectbox:"index:hash64"
songName string objectbox:"index:hash64"
albumName string objectbox:"index:hash64"
albumTrackNumber int
}
type Playlist struct {
Id uint64
CurrentTrackId uint16
Elapsed int
Tracks []*Track
}
type Friend struct {
Id uint64
friendId uint64
}
type User struct {
Id uint64 // going to be an internal objectBoxId
FirstName string
LastName string
EmailAddress string objectbox:"index:hash64"
Password string
Enabled bool
Tokens []*Token objectbox:"lazy"
Tracks []*Track objectbox:"lazy"
Playlists []*Playlist objectbox:"lazy"
SharedPlaylists []*Playlist objectbox:"lazy"
Friends []*Friend objectbox:"lazy"
}`
output of command: go generate ./...
Generating ObjectBox bindings for model.go failed to format generated binding file model.obx.go: 1632:8: expected ';', found 'if' (and 3 more errors) exit status 2 internal/model/model.go:3: running "go": exit status 1
The text was updated successfully, but these errors were encountered:
nick-dijkshoorn
added a commit
to nick-dijkshoorn/objectbox-generator
that referenced
this issue
Aug 24, 2023
Hi Guys,
Just messing around with objectbox-go for use as data storage for my app, and I came across the idea
of lazy loading related objects. I found that If I create a struct with more than 1 lazy loaded relation,
the generator breaks badly, to the point that if I remove all but 1 of the lazy defines on a relation, it works fine.
As I'm new to golang, I don't think I'm in the right headspace yet to fix it myself, but that being said, I can
point you in the direction I think needs the fix...
internal/generator/go/templates/binding.go
seems to be the first part to have issues, as with multiple lazy loaded relations, the templated code at line
165 misses a new line in the template, and causes errors in the code.
But then it totally dies somewhere in the templated code after line 193.
Granted those line numbers are from looking at the current source of the repo.
Modules involved:
github.com/objectbox/objectbox-generator v0.13.0
github.com/objectbox/objectbox-go v1.6.1
Golang version:
go version go1.17.9 linux/amd64
Below is my model.go file for the generator to have fun with.
`package model
//go:generate go run github.com/objectbox/objectbox-go/cmd/objectbox-gogen
type Token struct {
Id uint64
Token string
ExpiryDate uint64
objectbox:"date"
}
type Track struct {
Id uint64
path string
objectbox:"index:hash64"
artistName string
objectbox:"index:hash64"
songName string
objectbox:"index:hash64"
albumName string
objectbox:"index:hash64"
albumTrackNumber int
}
type Playlist struct {
Id uint64
CurrentTrackId uint16
Elapsed int
Tracks []*Track
}
type Friend struct {
Id uint64
friendId uint64
}
type User struct {
Id uint64 // going to be an internal objectBoxId
FirstName string
LastName string
EmailAddress string
objectbox:"index:hash64"
Password string
Enabled bool
Tokens []*Token
objectbox:"lazy"
Tracks []*Track
objectbox:"lazy"
Playlists []*Playlist
objectbox:"lazy"
SharedPlaylists []*Playlist
objectbox:"lazy"
Friends []*Friend
objectbox:"lazy"
}`
output of command: go generate ./...
Generating ObjectBox bindings for model.go failed to format generated binding file model.obx.go: 1632:8: expected ';', found 'if' (and 3 more errors) exit status 2 internal/model/model.go:3: running "go": exit status 1
The text was updated successfully, but these errors were encountered: