1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2025-10-31 00:17:48 +02:00

сделал RETURNING "id"

This commit is contained in:
Nikitin Aleksandr
2025-08-18 11:45:03 +03:00
parent 7ae52e470f
commit 957ba3b76b
2 changed files with 13 additions and 3 deletions

View File

@@ -45,7 +45,9 @@ func Create_ctx(ctx context.Context, db postgres_pgx.IConnectionTransaction, m *
}
//
TextSQL := TextSQL_Create_WithoutID
TextSQL := TextSQL_Create_WithoutID + `
RETURNING ReplaceColumnNamesPK;
`
//массив, в котором значения всех полей и ИД
MassValues := make([]interface{}, 0)
@@ -59,13 +61,12 @@ func Create_ctx(ctx context.Context, db postgres_pgx.IConnectionTransaction, m *
//
_, err = db.Exec(ctx, TextSQL, MassValues...)
err = db.QueryRow(ctx, TextSQL, MassValues...).Scan(ReplacePKFieldsWithAmpersandComma)
if err != nil {
err = fmt.Errorf(m.TableNameDB()+" Create_ctx() ReplacePKFieldNamesFormat error: %w", ReplacePKFieldsWithComma, err)
return err
}
return err
}

View File

@@ -110,18 +110,22 @@ func CreateFiles_Create1(Text string, Table1 *types.Table) string {
ReplaceTextSQLCreateWithoutID_values_id := ""
ColumnsPK := create_files.Find_PrimaryKeyColumns(Table1)
ReplacePKFieldsWithComma := ""
ReplacePKFieldsWithAmpersandComma := ""
ReplacePKFieldNamesFormat := ""
ReplaceColumnNamesPK := ""
ReplaceIDNot0 := ""
Comma := ""
NewLineTT := ""
TextAnd := ""
TextOR := ""
//CommaNewLineIf := ""
CommaNewLine := ""
NumberID := len(MassAllColumns) - len(ColumnsPK)
for _, Column1 := range ColumnsPK {
NumberID = NumberID + 1
sNumberID := strconv.Itoa(NumberID)
ReplacePKFieldsWithComma = ReplacePKFieldsWithComma + Comma + "m." + Column1.NameGo
ReplacePKFieldsWithAmpersandComma = ReplacePKFieldsWithAmpersandComma + Comma + "&m." + Column1.NameGo
ReplacePKFieldNamesFormat = ReplacePKFieldNamesFormat + Comma + Column1.NameGo + ": %v"
TextEmpty := create_files.FindText_NotEqualEmpty(Column1, "m."+Column1.NameGo)
ReplaceIDNot0 = ReplaceIDNot0 + TextAnd + TextEmpty
@@ -136,17 +140,22 @@ func CreateFiles_Create1(Text string, Table1 *types.Table) string {
}
ReplaceMassValuesIDAppend = ReplaceMassValuesIDAppend + NewLineTT + "MassValues = append(MassValues, " + TextValue + ")"
ReplaceColumnNamesPK = ReplaceColumnNamesPK + CommaNewLine + `"` + Column1.Name + `"`
Comma = ", "
TextAnd = " && "
NewLineTT = "\n\t\t"
TextOR = " || "
//CommaNewLineIf = ",\n"
CommaNewLine = ",\n\t"
}
Otvet = strings.ReplaceAll(Otvet, "ReplacePKFieldsWithComma", ReplacePKFieldsWithComma)
Otvet = strings.ReplaceAll(Otvet, "ReplacePKFieldNamesFormat", ReplacePKFieldNamesFormat)
Otvet = strings.ReplaceAll(Otvet, "ReplaceIDNot0", ReplaceIDNot0)
Otvet = strings.ReplaceAll(Otvet, "ReplaceMassValuesIDAppend", ReplaceMassValuesIDAppend)
Otvet = strings.ReplaceAll(Otvet, "ReplacePKNotEqual0", ReplacePKNotEqual0)
Otvet = strings.ReplaceAll(Otvet, "ReplaceColumnNamesPK", ReplaceColumnNamesPK)
Otvet = strings.ReplaceAll(Otvet, "ReplacePKFieldsWithAmpersandComma", ReplacePKFieldsWithAmpersandComma)
//все колонки
ReplaceMassValuesAppend := ""