12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package model
- import (
- "time"
- "git.getensh.com/common/gopkgsv2/database"
- "gorm.io/gorm"
- )
- type ExportStyleTaskModel interface {
- Insert(db *gorm.DB, data interface{}) error
- Update(db *gorm.DB, values interface{}) error
- List(db *gorm.DB) ([]ExportStyleTask, error)
- Delete(db *gorm.DB) error
- Get(db *gorm.DB) (*ExportStyleTask, error)
- }
- type ExportStyleTask struct {
- ID int64 `gorm:"column:id" json:"id"`
- TaskName string `gorm:"column:task_name" json:"task_name"`
- Path string `gorm:"column:path" json:"path"`
- CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
- }
- type defaultExportStyleTaskModel struct {
- tableName string
- fields string
- }
- func NewExportStyleTaskModel() ExportStyleTaskModel {
- return &defaultExportStyleTaskModel{
- tableName: "db_adm_management.t_export_style_task",
- fields: "id, task_name, path, created_at",
- }
- }
- func (d *defaultExportStyleTaskModel) Insert(db *gorm.DB, data interface{}) error {
- return database.Create(db, data, database.Option{
- TableName: d.tableName,
- })
- }
- func (d *defaultExportStyleTaskModel) Update(db *gorm.DB, values interface{}) error {
- return database.Update(db, values, database.Option{
- TableName: d.tableName,
- })
- }
- func (d *defaultExportStyleTaskModel) List (db *gorm.DB) ([]ExportStyleTask, error) {
- var res []ExportStyleTask
- err := database.List(db, &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- OrderBy: "id DESC",
- })
- return res, err
- }
- func (d *defaultExportStyleTaskModel) Delete(db *gorm.DB) error {
- m := ExportStyleTask{}
- return db.Table(d.tableName).Delete(&m).Error
- }
- func (d *defaultExportStyleTaskModel) Get(db *gorm.DB) (*ExportStyleTask, error) {
- var res ExportStyleTask
- err := database.Get(db, &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- })
- return &res, err
- }
|