Skip to content

how to use bob's ORM correctly without code generation? #318

Answered by stephenafamo
asv asked this question in Q&A
Discussion options

You must be logged in to vote

There are other methods in orm.Setter[*Docket, *dialect.InsertQuery, *dialect.UpdateQuery] that need to be implemented.

table.Insert is calling one of those methods (Apply) and you get a panic because it is nil.

It is similar to this code:

type DocketSetter struct {
	DocketID   omit.Val[string]    `db:"docket_id,pk"`
	CreateTime omit.Val[time.Time] `db:"create_time"`

	Setter any // orm.Setter is an interface, so when by default, the value is nil
}

You should properly implement the setter interface. For example, if the code was generated, it will look something like this:

func (s DocketSetter) SetColumns() []string {
	vals := make([]string, 0, 2)
	if !s.DocketID.IsUnset() {
		vals = append(

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@stephenafamo
Comment options

Answer selected by stephenafamo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants