WIP: Insert sets PK

This commit is contained in:
2026-05-23 20:19:25 +02:00
parent 890151b490
commit 5d892a15ef
6 changed files with 59 additions and 54 deletions
+21
View File
@@ -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
}