12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package model
- import (
- "git.getensh.com/common/gopkgsv2/database"
- "gorm.io/gorm"
- )
- type KeyListModel interface {
- List(db *gorm.DB, pagination *Pagination) ([]AdmKeyList, error)
- Count(db *gorm.DB) (int64, error)
- Update(db *gorm.DB, values interface{}) error
- Get(db *gorm.DB) (*AdmKeyList, error)
- }
- type AdmKeyList struct {
- Id int64 `gorm:"column:id" json:"id" form:"id"`
- Key string `gorm:"column:key" json:"key" form:"key"`
- Desc string `gorm:"column:desc" json:"desc" form:"desc"`
- CreatedAt int64 `gorm:"column:created_at" json:"created_at" form:"created_at"`
- UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at" form:"updated_at"`
- }
- type defaultKeyList struct {
- tableName string
- fields string
- }
- func NewKeyList() KeyListModel {
- return &defaultKeyList{
- tableName: "t_adm_key_management",
- fields: "`id`, `key`, `desc`, `created_at`, `updated_at`",
- }
- }
- func (d *defaultKeyList) List(db *gorm.DB, pagination *Pagination) ([]AdmKeyList, error) {
- var res []AdmKeyList
- err := database.List(db, &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- Limit: pagination.Limit,
- OffSet: pagination.Offset,
- })
- return res, err
- }
- func (d *defaultKeyList) Count(db *gorm.DB) (int64, error) {
- return database.Count(db, database.Option{
- TableName: d.tableName,
- })
- }
- func (d *defaultKeyList) Update(db *gorm.DB, values interface{}) error {
- return database.Update(db, values, database.Option{
- TableName: d.tableName,
- })
- }
- func (d *defaultKeyList) Get(db *gorm.DB) (*AdmKeyList, error) {
- var res AdmKeyList
- err := database.Get(db, &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- })
- return &res, err
- }
|