|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- type SuggestedFeedbackDb struct {
- Db *xorm.Engine `json:"db"`
- }
-
- func (suggestedFeedbackDb *SuggestedFeedbackDb) Set() { // set方法
- suggestedFeedbackDb.Db = Db
- }
-
- func (suggestedFeedbackDb *SuggestedFeedbackDb) GetSuggestedFeedback(id int) (m *model.SuggestedFeedback, err error) {
- m = new(model.SuggestedFeedback)
- has, err := suggestedFeedbackDb.Db.Where("id =?", id).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (suggestedFeedbackDb *SuggestedFeedbackDb) FindSuggestedFeedbackById(ids interface{}) (*[]model.SuggestedFeedback, error) {
- var m []model.SuggestedFeedback
- if err := suggestedFeedbackDb.Db.In("id", ids).Desc("sort").Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (suggestedFeedbackDb *SuggestedFeedbackDb) FindSuggestedFeedback(limit, start int) (*[]model.SuggestedFeedback, error) {
- var m []model.SuggestedFeedback
- if limit == 0 || start == 0 {
- if err := suggestedFeedbackDb.Db.Asc("sort").Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- } else {
- if err := suggestedFeedbackDb.Db.Asc("sort").Limit(limit, start).Find(m); err != nil {
- return nil, logx.Error(err)
- }
- }
- return &m, nil
- }
-
- func (suggestedFeedbackDb *SuggestedFeedbackDb) GetSuggestedFeedbackByName(name string) (m *model.SuggestedFeedback, err error) {
- m = new(model.SuggestedFeedback)
- has, err := suggestedFeedbackDb.Db.Where("name =?", name).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackInsert(m *model.SuggestedFeedback) (int, error) {
- _, err := suggestedFeedbackDb.Db.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
-
- func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackUpdate(m *model.SuggestedFeedback, columns ...string) (int64, error) {
- affected, err := suggestedFeedbackDb.Db.Where("id =?", m.Id).Cols(columns...).Update(m)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackDelete(id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return Db.In("id", id).Delete(model.SuggestedFeedback{})
- } else {
- return Db.Where("id = ?", id).Delete(model.SuggestedFeedback{})
- }
- }
-
- type SuggestedFeedbackWithUserIdentity struct {
- model.SuggestedFeedback `xorm:"extends"`
- model.UserIdentity `xorm:"extends"`
- model.Enterprise `xorm:"extends"`
- model.User `xorm:"extends"`
- }
-
- func (SuggestedFeedbackWithUserIdentity) TableName() string {
- return "suggested_feedback"
- }
|