Save method
This commit is contained in:
@ -5,6 +5,8 @@ import (
|
||||
"gorm.io/gorm/schema"
|
||||
)
|
||||
|
||||
const DEFAULT_ID_FIELD = "id"
|
||||
|
||||
type MethodInitInterface[T schema.Tabler] interface {
|
||||
Init(repo *RepoBase[T])
|
||||
}
|
||||
@ -22,6 +24,7 @@ type RepoBase[T schema.Tabler] struct {
|
||||
ExistsMethod[T]
|
||||
CountMethod[T]
|
||||
SaveMethod[T]
|
||||
DeleteMethod[T]
|
||||
}
|
||||
|
||||
func (repo *RepoBase[T]) InitMethods(methods []MethodInitInterface[T]) {
|
||||
@ -35,7 +38,7 @@ func (m *RepoBase[T]) Init(dbConn *gorm.DB, options *RepoOptions) {
|
||||
|
||||
if options == nil {
|
||||
// no options provided? set defaults
|
||||
m.IdField = "id"
|
||||
m.IdField = DEFAULT_ID_FIELD
|
||||
} else {
|
||||
if len(options.IdField) > 0 {
|
||||
m.IdField = options.IdField
|
||||
@ -48,6 +51,7 @@ func (m *RepoBase[T]) Init(dbConn *gorm.DB, options *RepoOptions) {
|
||||
&m.ExistsMethod,
|
||||
&m.CountMethod,
|
||||
&m.SaveMethod,
|
||||
&m.DeleteMethod,
|
||||
}
|
||||
m.InitMethods(methods)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user