|
@@ -33,9 +33,13 @@ func InsertEntity[T any](executor Executor, tableName string, e T) error {
|
|
|
return errors.New("没有传递实体")
|
|
|
}
|
|
|
|
|
|
- tableRows := sql_tpl.NewTableRows()
|
|
|
+ sqlMapping, err := ParseSqlMappingTag(e)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
|
|
|
- err := formInsertTableRow(e, tableRows)
|
|
|
+ tableRows := sql_tpl.NewTableRows()
|
|
|
+ err = formInsertTableRow(sqlMapping, tableRows)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -60,18 +64,13 @@ func InsertEntity[T any](executor Executor, tableName string, e T) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func formInsertTableRow(e any, tableRows *sql_tpl.TableRows) error {
|
|
|
- sqlMapping, err := ParseSqlMappingTag(e)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
+func formInsertTableRow(sqlMapping *Mapping, tableRows *sql_tpl.TableRows) error {
|
|
|
now := time.Now()
|
|
|
|
|
|
for fieldName, mappingElement := range sqlMapping.MappingElement {
|
|
|
switch element := mappingElement.(type) {
|
|
|
- case *MappingStruct:
|
|
|
- err := formInsertTableRow(element.FieldValueElem.Interface(), tableRows)
|
|
|
+ case *Mapping:
|
|
|
+ err := formInsertTableRow(element, tableRows)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -139,9 +138,13 @@ func DeleteEntity[T any](executor Executor, tableName string, e T) error {
|
|
|
return errors.New("没有传递实体")
|
|
|
}
|
|
|
|
|
|
- conditions := sql_tpl.NewConditions()
|
|
|
+ sqlMapping, err := ParseSqlMappingTag(e)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
|
|
|
- err := formDeleteConditions(e, conditions)
|
|
|
+ conditions := sql_tpl.NewConditions()
|
|
|
+ err = formDeleteConditions(sqlMapping, conditions)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -162,16 +165,11 @@ func DeleteEntity[T any](executor Executor, tableName string, e T) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func formDeleteConditions(e any, conditions *sql_tpl.Conditions) error {
|
|
|
- sqlMapping, err := ParseSqlMappingTag(e)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
+func formDeleteConditions(sqlMapping *Mapping, conditions *sql_tpl.Conditions) error {
|
|
|
for _, mappingElement := range sqlMapping.MappingElement {
|
|
|
switch element := mappingElement.(type) {
|
|
|
- case *MappingStruct:
|
|
|
- err := formDeleteConditions(element.FieldValueElem.Interface(), conditions)
|
|
|
+ case *Mapping:
|
|
|
+ err := formDeleteConditions(element, conditions)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -213,10 +211,14 @@ func UpdateEntity[T any](executor Executor, tableName string, e T) error {
|
|
|
return errors.New("没有传递实体")
|
|
|
}
|
|
|
|
|
|
+ sqlMapping, err := ParseSqlMappingTag(e)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
tableRows := sql_tpl.NewTableRows()
|
|
|
conditions := sql_tpl.NewConditions()
|
|
|
-
|
|
|
- err := formUpdateTableRowsAndConditions(e, tableRows, conditions)
|
|
|
+ err = formUpdateTableRowsAndConditions(sqlMapping, tableRows, conditions)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -238,18 +240,13 @@ func UpdateEntity[T any](executor Executor, tableName string, e T) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func formUpdateTableRowsAndConditions(e any, tableRows *sql_tpl.TableRows, conditions *sql_tpl.Conditions) error {
|
|
|
- sqlMapping, err := ParseSqlMappingTag(e)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
+func formUpdateTableRowsAndConditions(sqlMapping *Mapping, tableRows *sql_tpl.TableRows, conditions *sql_tpl.Conditions) error {
|
|
|
now := time.Now()
|
|
|
|
|
|
for fieldName, mappingElement := range sqlMapping.MappingElement {
|
|
|
switch element := mappingElement.(type) {
|
|
|
- case *MappingStruct:
|
|
|
- err := formUpdateTableRowsAndConditions(element.FieldValueElem.Interface(), tableRows, conditions)
|
|
|
+ case *Mapping:
|
|
|
+ err := formUpdateTableRowsAndConditions(element, tableRows, conditions)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|