WIP: Refactor parse

This commit is contained in:
2026-06-05 15:54:47 +02:00
parent d20184a6f0
commit 146f07fa02
10 changed files with 255 additions and 180 deletions
+12 -13
View File
@@ -157,11 +157,6 @@ type Exec[T any] interface {
execute(conn *simpleorm.DBConnection, tx *sql.Tx) error
}
type OrderBy struct {
Column string
Direction string
}
type Count[T any] struct {
target schema.Table
whereStmt string
@@ -425,9 +420,10 @@ func (d *Delete[T]) execute(conn *simpleorm.DBConnection, tx *sql.Tx) error {
}
func createSelectResultContainer(t schema.Table) []any {
vals := make([]any, t.Type.NumField())
typ := t.Type()
vals := make([]any, typ.NumField())
for i := range vals {
switch t.Type.Field(i).Type.Kind().String() {
switch typ.Field(i).Type.Kind().String() {
case "string":
var fieldContainer string
vals[i] = &fieldContainer
@@ -443,13 +439,14 @@ func createSelectResultContainer(t schema.Table) []any {
}
func prepareParams(src any, t schema.Table) []any {
typ := t.Type()
var params []any
for _, col := range t.Columns {
for _, col := range t.Columns() {
_, ok := col.Modifiers["pk"]
if ok && t.IsPkAuto() {
continue
}
field, ok := t.Type.FieldByName(col.FieldName)
field, ok := typ.FieldByName(col.FieldName)
if !ok {
continue
}
@@ -461,11 +458,12 @@ func prepareParams(src any, t schema.Table) []any {
}
func getPk(src any, t schema.Table) ([]any, error) {
typ := t.Type()
var values []any
for _, constraint := range t.Constraints {
for _, constraint := range t.Constraints() {
if constraint.Type == "pk" {
for _, col := range constraint.Columns {
field, ok := t.Type.FieldByName(col.FieldName)
field, ok := typ.FieldByName(col.FieldName)
if !ok {
continue
@@ -493,10 +491,11 @@ func readRows[T any](table schema.Table, rows *sql.Rows) ([]T, error) {
return nil, err
}
targetType := table.Type
targetType := table.Type()
cols := table.Columns()
parsedResult := reflect.New(targetType)
for i, fieldVal := range rowContainer {
col := table.Columns[i]
col := cols[i]
targetField := parsedResult.Elem().Field(i)
rawValue := reflect.Indirect(reflect.ValueOf(fieldVal))