package mysql

import (
	"gitea.party/public-messag-service/config/app_ser/component"
	"gorm.io/gorm"
)

var (
	MSGLog = component.MySQLClient{}
)

type Model interface {
	TableName() string
	DB() *gorm.DB
}

func getDB() *gorm.DB {
	return MSGLog.DB
}

func GetById(m Model, id int) error {
	tx := m.DB().Where("id=?", id).Take(m)
	return tx.Error
}

func Add(m Model) error {
	tx := m.DB().Create(m)
	return tx.Error
}

func Save(m Model, id int, columns []string) error {
	tx := m.DB().Select(columns).Where("id=?", id).Updates(m)
	return tx.Error
}