Skip to content

Commit

Permalink
Support for readonly transient field go-gorp#394
Browse files Browse the repository at this point in the history
  • Loading branch information
Illia Ovchynnikov committed Jun 17, 2019
1 parent f3677d4 commit 1b37300
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ func (m *DbMap) readStructColumns(t reflect.Type) (cols []*ColumnMap, primaryKey
var isAuto bool
var isPK bool
var isNotNull bool
var isReadOnly bool
for _, argString := range cArguments[1:] {
argString = strings.TrimSpace(argString)
arg := strings.SplitN(argString, ":", 2)
Expand Down Expand Up @@ -349,6 +350,8 @@ func (m *DbMap) readStructColumns(t reflect.Type) (cols []*ColumnMap, primaryKey
isAuto = true
case "notnull":
isNotNull = true
case "readonly":
isReadOnly = true
default:
panic(fmt.Sprintf("Unrecognized tag option for field %v: %v", f.Name, arg))
}
Expand Down Expand Up @@ -390,7 +393,7 @@ func (m *DbMap) readStructColumns(t reflect.Type) (cols []*ColumnMap, primaryKey
cm := &ColumnMap{
ColumnName: columnName,
DefaultValue: defaultValue,
Transient: columnName == "-",
Transient: columnName == "-" || isReadOnly,
fieldName: f.Name,
gotype: gotype,
isPK: isPK,
Expand Down

0 comments on commit 1b37300

Please sign in to comment.