完成重构数据库操作代码
This commit is contained in:
26
server/repository/num.go
Normal file
26
server/repository/num.go
Normal file
@ -0,0 +1,26 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/server/model"
|
||||
)
|
||||
|
||||
type NumRepository struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewNumRepository(db *gorm.DB) *NumRepository {
|
||||
numRepository = &NumRepository{DB: db}
|
||||
return numRepository
|
||||
}
|
||||
|
||||
func (r NumRepository) FindAll() (o []model.Num, err error) {
|
||||
err = r.DB.Find(&o).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r NumRepository) Create(o *model.Num) (err error) {
|
||||
err = global.DB.Create(o).Error
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user