Given two structs User and Profile linked with a foreign key:
type User struct {
ID uuid.UUID
Name string
CreatedAt time.Time
UpdatedAt time.Time
}
type Profile struct {
ID uuid.UUID
UserID uuid.UUID
CreatedAt time.Time
UpdatedAt time.Time
}
It would be good to be able to query as follows:
type UserWithProfile struct {
User User `db:",inline"`
Profile Profile `db:",inline"`
}
res := []*UserWithProfile{}
err := db.
SelectFrom("users").
Join("profiles AS p").On("users.id = p.user_id").
All(res)
Right now, this is impossible due to conflicting field names with multiple inline structs. The user's ID, CreatedAt and UpdatedAt columns are all unset, while only the joined Profile's fields are set.
Given two structs User and Profile linked with a foreign key:
It would be good to be able to query as follows:
Right now, this is impossible due to conflicting field names with multiple inline structs. The user's
ID
,CreatedAt
andUpdatedAt
columns are all unset, while only the joined Profile's fields are set.This could be solvable via:
This assumes that the struct field's ordering is the same as the order in the database query.
We could also dynamically rename fields on the fly so that we can match regardless of order, though this is much more work.