You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
1.2 KiB
Smarty
24 lines
1.2 KiB
Smarty
|
|
func (m *default{{.upperStartCamelObject}}Model) Insert(ctx context.Context, tx *gorm.DB, data *{{.upperStartCamelObject}}) error {
|
|
{{if .withCache}}{{.keys}}
|
|
err := m.ExecCtx(ctx, func(conn *gorm.DB) error {
|
|
return gormx.WithTx(ctx, conn, tx).Create(&data).Error
|
|
}, {{.keyValues}}){{else}}err:=gormx.WithTx(ctx, m.DB, tx).Create(&data).Error{{end}}
|
|
return err
|
|
}
|
|
|
|
func (m *default{{.upperStartCamelObject}}Model) InsertBatch(ctx context.Context, tx *gorm.DB, data []{{.upperStartCamelObject}}, batchSize int) error {
|
|
{{if .withCache}}
|
|
err := m.ExecCtx(ctx, func(conn *gorm.DB) error {
|
|
return gormx.WithTx(ctx, conn, tx).CreateInBatches(data, batchSize).Error
|
|
}){{else}}err:=gormx.WithTx(ctx, m.DB, tx).CreateInBatches(data, batchSize).Error{{end}}
|
|
return err
|
|
}
|
|
|
|
func (m *default{{.upperStartCamelObject}}Model) Upsert(ctx context.Context, tx *gorm.DB, data *{{.upperStartCamelObject}}) error {
|
|
{{if .withCache}}{{.keys}}
|
|
err := m.ExecCtx(ctx, func(conn *gorm.DB) error {
|
|
return gormx.WithTx(ctx, conn, tx).Clauses(gormx.BuildUpsertOnConflict(nil, nil, nil)).Create(&data).Error
|
|
}, {{.keyValues}}){{else}}err:=gormx.WithTx(ctx, m.DB, tx).Clauses(gormx.BuildUpsertOnConflict(nil, nil, nil)).Create(&data).Error{{end}}
|
|
return err
|
|
} |