WIP: OrderBy implementation
Go Tests / test (pull_request) Successful in 1m4s

This commit is contained in:
2026-06-05 17:19:11 +02:00
parent 146f07fa02
commit cd1f61fb87
3 changed files with 98 additions and 23 deletions
+26
View File
@@ -1,6 +1,7 @@
package schema
import (
"errors"
"reflect"
"strings"
@@ -218,6 +219,31 @@ func (t Table) GetDeleteDML(count int) (string, error) {
return dml.String(), nil
}
func (t Table) GetOrderByDML(ordering ...OrderBy) (string, error) {
var dml strings.Builder
dml.WriteString(" ORDER BY")
for _, orderBy := range ordering {
col, err := t.getColumnByField(orderBy.Field)
if err != nil {
return "", err
}
dml.WriteString(" ")
dml.WriteString(col.Name)
dml.WriteString(" ")
dml.WriteString(orderBy.Direction)
}
return dml.String(), nil
}
func (t Table) getColumnByField(fieldName string) (Column, error) {
for _, col := range t.columns {
if col.FieldName == fieldName {
return col, nil
}
}
return Column{}, errors.New("No column for field " + fieldName + " in table " + t.name)
}
func (t Table) IsPkAuto() bool {
for _, constr := range t.constraints {
if constr.Type != "pk" {