WIP: Insert sets PK
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
@@ -186,3 +187,23 @@ func (t Table) IsPkAuto() bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (t Table) GetPkColumns() ([]Column, error) {
|
||||
var values []Column
|
||||
for _, constraint := range t.Constraints {
|
||||
if constraint.Type == "pk" {
|
||||
for _, col := range constraint.Columns {
|
||||
_, ok := t.Type.FieldByName(col.FieldName)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
values = append(values, col)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(values) == 0 {
|
||||
return nil, errors.New("Could not determine pk column!")
|
||||
}
|
||||
|
||||
return values, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user