goqu icon indicating copy to clipboard operation
goqu copied to clipboard

Is there a tag ignore non-existing SQL column?

Open iredmail opened this issue 3 years ago • 0 comments

Dear all,

Is there a tag like omitempty in json package to ignore non-existing SQL columns and use zero value instead? For example

type MyTable struct {
	OTPEnabled bool   `db:"otp_enabled"`
}

var row MyTable
_,_,_ = goqu.From("my_table").Limit(1).ScanStruct(&row)

SQL column otp_enabled doesn't exist in old versions of our program, but it's used while login before user can apply the SQL structure changes.

Situation

With latest goqu release v9.18.0, it raises error message like Error 1054: Unknown column 'otp_enabled' in 'field list'.

Expected behaviour

I expect goqu to ignore this column and use a zero value (false) of the data type (bool) with a tag. e.g. goqu:"zeroifmissing".

Addtional

I found 3 tags supported by goqu, but none of them is suitable for my case.

  • goqu:"skipinsert"
  • goqu:"skipupdate"
  • goqu:"defaultifempty"

iredmail avatar Jan 11 '23 01:01 iredmail