WIP: Refactor - delete dml
Go Tests / test (pull_request) Failing after 9s

This commit is contained in:
2026-05-11 00:12:41 +02:00
parent f50004d9b4
commit 7bd3c333fe
4 changed files with 138 additions and 9 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ package schema
type SchemaDescriptor interface {
getDDL() (string, error)
GetSelectDML() (string, error)
GetInsertDML() (string, error)
GetInsertDML(count int) (string, error)
GetUpdateDML() (string, error)
GetDeleteDML() (string, error)
GetDeleteDML(count int) (string, error)
}
+20 -6
View File
@@ -1,7 +1,6 @@
package schema
import (
"errors"
"reflect"
"strings"
@@ -104,7 +103,7 @@ func (t Table) GetInsertDML(count int) (string, error) {
return dml.String(), nil
}
func (t Table) GetUpdateDML(src any) (string, error) {
func (t Table) GetUpdateDML() (string, error) {
var dml strings.Builder
dml.WriteString("UPDATE " + util.CamelToSnake(t.Type.Name()) + " SET ")
@@ -145,18 +144,33 @@ func (t Table) GetUpdateDML(src any) (string, error) {
return dml.String(), nil
}
func (t Table) GetDeleteDML(src any) (string, error) {
func (t Table) GetDeleteDML(count int) (string, error) {
var dml strings.Builder
dml.WriteString("DELETE FROM " + t.Name + " WHERE ")
for _, col := range t.Columns {
modifiers := col.Modifiers
_, ok := modifiers["pk"]
if ok {
dml.WriteString(col.Name + " = ?")
return dml.String(), nil
if count > 1 {
dml.WriteString(col.Name + " IN (")
} else {
dml.WriteString(col.Name + " = ")
}
}
}
return "", errors.New("Failed to determine primar key column for delete dml.")
for i := range count {
if i != 0 {
dml.WriteString(", ")
}
dml.WriteString("?")
}
if count > 1 {
dml.WriteString(")")
}
return dml.String(), nil
}