database

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const APPROVAL_STATUS_APPROVED int8 = 3
View Source
const APPROVAL_STATUS_DRAFT int8 = 0
View Source
const APPROVAL_STATUS_PENDING int8 = 1
View Source
const APPROVAL_STATUS_REJECTED int8 = 4
View Source
const COMPACT_UNIQUE_ID = "id"
View Source
const MODEL_STATUS_ACTIVE int8 = 1
View Source
const MODEL_STATUS_CANCELED int8 = 2
View Source
const MODEL_STATUS_DRAFT int8 = 0
View Source
const MODEL_STATUS_INACTIVE int8 = 4
View Source
const MODEL_STATUS_PENDING int8 = 3
View Source
const OPERAION_LOG_UNIQUE_ID = COMPACT_UNIQUE_ID
View Source
const OPERATION_EVENT_CREATE = 1
View Source
const OPERATION_EVENT_DELETE = 3
View Source
const OPERATION_EVENT_UPDATE = 2
View Source
const OPERATION_RESULT_CANCEL = 3
View Source
const OPERATION_RESULT_FAILED = 2
View Source
const OPERATION_RESULT_SUCCESS = 1
View Source
const PAGE_DEFAULT_SIZE = 20
View Source
const TABLE_NAME_OPERATION_LOG = "power_operation_log"
View Source
const UNIQUE_ID = "uuid"

Variables

View Source
var ArrayModelFields *object.HashMap = &object.HashMap{}
View Source
var TABLE_PREFIX string

Functions

func AppendMorphPivots

func AppendMorphPivots(db *gorm.DB, pivots []PivotInterface) (err error)

func AppendPivots

func AppendPivots(db *gorm.DB, pivots []PivotInterface) (err error)

--------------------------------------------------------------------

func AssociationRelationship

func AssociationRelationship(db *gorm.DB, conditions *map[string]interface{}, mdl interface{}, relationship string, withClauseAssociations bool) *gorm.Association

*

  • Association Pivot

func ClearAssociations

func ClearAssociations(db *gorm.DB, object ModelInterface, foreignKey string, pivot PivotInterface) error

func ClearPivots

func ClearPivots(db *gorm.DB, pivot PivotInterface, byForeignKey bool, byJoinKey bool) (err error)

clear all pivots with foreign key and value

func FormatJsonBArrayToWhereInSQL

func FormatJsonBArrayToWhereInSQL(fields string, arrayValues []string) (sqlWhere string)

---------------------------------------------------------------------------------------------------------------------

func GetAllList

func GetAllList(db *gorm.DB, conditions *map[string]interface{},
	items interface{}, preloads []string) (err error)

func GetFirst

func GetFirst(db *gorm.DB, conditions *map[string]interface{}, model interface{}, preloads []string) (err error)

func GetModelFieldValues

func GetModelFieldValues(model interface{}) (mapFields *object.HashMap, err error)

func GetModelFields

func GetModelFields(model interface{}) (fields []string)

func GetTableFullName

func GetTableFullName(schema string, prefix string, tableName string) (fullName string)

func InsertModelsOnUniqueID

func InsertModelsOnUniqueID(db *gorm.DB, mdl interface{}, uniqueName string, models interface{}) error

func IsPowerModelLoaded

func IsPowerModelLoaded(mdl ModelInterface) bool

func IsPowerPivotLoaded

func IsPowerPivotLoaded(mdl ModelInterface) bool

func Paginate

func Paginate(page int, pageSize int) func(db *gorm.DB) *gorm.DB

*

  • Pagination

func SavePivot

func SavePivot(db *gorm.DB, pivot PivotInterface) error

func SelectMorphPivot

func SelectMorphPivot(db *gorm.DB, pivot PivotInterface) (result *gorm.DB)

select one pivot with foreign key and join key

func SelectMorphPivots

func SelectMorphPivots(db *gorm.DB, pivot PivotInterface, byForeignKey bool, byJoinKey bool) (result *gorm.DB)

select many pivots with foreign key

func SelectPivot

func SelectPivot(db *gorm.DB, pivot PivotInterface) (result *gorm.DB)

func SelectPivots

func SelectPivots(db *gorm.DB, pivot PivotInterface, byForeignKey bool, byJoinKey bool) (result *gorm.DB)

func SyncMorphPivots

func SyncMorphPivots(db *gorm.DB, pivots []PivotInterface) (err error)

func SyncPivots

func SyncPivots(db *gorm.DB, pivots []PivotInterface) (err error)

func UpdatePivot

func UpdatePivot(db *gorm.DB, pivot PivotInterface) error

func UpsertModelsOnUniqueID

func UpsertModelsOnUniqueID(db *gorm.DB, mdl interface{}, uniqueName string,
	models interface{}, fieldsToUpdate []string) error

func UpsertPivots

func UpsertPivots(db *gorm.DB, uniqueName string, pivots []PivotInterface, fieldsToUpdate []string) error

func WhereAccountUUID

func WhereAccountUUID(uuid string) func(db *gorm.DB) *gorm.DB

func WhereCampaignUUID

func WhereCampaignUUID(uuid string) func(db *gorm.DB) *gorm.DB

func WhereUUID

func WhereUUID(uuid string) func(db *gorm.DB) *gorm.DB

*

  • Scope Where Conditions

Types

type ModelInterface

type ModelInterface interface {
	GetTableName(needFull bool) string
	GetPowerModel() ModelInterface
	GetID() int32
	GetUUID() string
	GetPrimaryKey() string
	GetForeignRefer() string
	GetForeignReferValue() string
}

type Pagination

type Pagination struct {
	Limit      int         `json:"limit"`
	Page       int         `json:"page"`
	Sort       string      `json:"sort"`
	TotalRows  int64       `json:"totalRows"`
	TotalPages int         `json:"totalPages"`
	Data       interface{} `json:"data"`
}

func GetList

func GetList(db *gorm.DB, conditions *map[string]interface{},
	models interface{}, preloads []string,
	page int, pageSize int) (paginator *Pagination, err error)

func NewPagination

func NewPagination(page int, limit int, sort string) *Pagination

func (*Pagination) GetLimit

func (p *Pagination) GetLimit() int

func (*Pagination) GetOffset

func (p *Pagination) GetOffset() int

func (*Pagination) GetPage

func (p *Pagination) GetPage() int

func (*Pagination) GetSort

func (p *Pagination) GetSort() string

func (*Pagination) SetLimit

func (p *Pagination) SetLimit(limit int) *Pagination

func (*Pagination) SetPage

func (p *Pagination) SetPage(page int) *Pagination

func (*Pagination) SetSort

func (p *Pagination) SetSort(sort string) *Pagination

type PivotInterface

type PivotInterface interface {
	ModelInterface
	GetForeignKey() string
	GetForeignValue() string
	GetJoinKey() string
	GetJoinValue() string
	GetOwnerKey() string
	GetOwnerValue() string
	GetPivotComposedUniqueID() string
}

type PowerCompactModel

type PowerCompactModel struct {
	ID int32 `gorm:"primaryKey;autoIncrement:true;unique; column:id; ->;<-:create" json:"-"`

	CreatedAt time.Time `gorm:"column:created_at; ->;<-:create " json:"createdAt"`
	UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
}

func NewPowerCompactModel

func NewPowerCompactModel() *PowerCompactModel

func (*PowerCompactModel) GetForeignRefer

func (mdl *PowerCompactModel) GetForeignRefer() string

func (*PowerCompactModel) GetForeignReferValue

func (mdl *PowerCompactModel) GetForeignReferValue() string

func (*PowerCompactModel) GetID

func (mdl *PowerCompactModel) GetID() int32

func (*PowerCompactModel) GetPowerModel

func (mdl *PowerCompactModel) GetPowerModel() ModelInterface

func (*PowerCompactModel) GetPrimaryKey

func (mdl *PowerCompactModel) GetPrimaryKey() string

func (*PowerCompactModel) GetTableName

func (mdl *PowerCompactModel) GetTableName(needFull bool) string

func (*PowerCompactModel) GetUUID

func (mdl *PowerCompactModel) GetUUID() string

type PowerModel

type PowerModel struct {
	ID   int32  `gorm:"autoIncrement:true;unique; column:id; ->;<-:create" json:"-"`
	UUID string `gorm:"primaryKey;autoIncrement:false;unique; column:uuid; ->;<-:create " json:"uuid" sql:"index"`

	CreatedAt time.Time `gorm:"column:created_at; ->;<-:create " json:"createdAt"`
	UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
}

func NewPowerModel

func NewPowerModel() *PowerModel

func (*PowerModel) GetForeignRefer

func (mdl *PowerModel) GetForeignRefer() string

func (*PowerModel) GetForeignReferValue

func (mdl *PowerModel) GetForeignReferValue() string

func (*PowerModel) GetID

func (mdl *PowerModel) GetID() int32

func (*PowerModel) GetPowerModel

func (mdl *PowerModel) GetPowerModel() ModelInterface

func (*PowerModel) GetPrimaryKey

func (mdl *PowerModel) GetPrimaryKey() string

func (*PowerModel) GetTableName

func (mdl *PowerModel) GetTableName(needFull bool) string

func (*PowerModel) GetUUID

func (mdl *PowerModel) GetUUID() string

type PowerOperationLog

type PowerOperationLog struct {
	*PowerCompactModel

	OperatorName  *string `gorm:"column:operatorName" json:"operatorName"`
	OperatorTable *string `gorm:"column:operatorTable" json:"operatorTable"`
	OperatorID    *int32  `gorm:"column:operatorID;index" json:"operatorID"`
	Module        *int16  `gorm:"column:module" json:"module"`
	Operate       *string `gorm:"column:operate" json:"operate"`
	Event         *int8   `gorm:"column:event" json:"event"`
	ObjectName    *string `gorm:"column:objectName" json:"objectName"`
	ObjectTable   *string `gorm:"column:objectTable" json:"objectTable"`
	ObjectID      *int32  `gorm:"column:objectID;index" json:"objectID"`
	Result        *int8   `gorm:"column:result" json:"result"`
}

PowerOperationLog 数据表结构

func NewPowerOperationLog

func NewPowerOperationLog(mapObject *object.Collection) *PowerOperationLog

func (*PowerOperationLog) GetTableName

func (mdl *PowerOperationLog) GetTableName(needFull bool) string

获取当前 Model 的数据库表名称

func (*PowerOperationLog) SaveOps

func (mdl *PowerOperationLog) SaveOps(db *gorm.DB,
	operatorName string, operator ModelInterface,
	module int16, operate string, event int8,
	objectName string, object ModelInterface,
	result int8,
) error

func (*PowerOperationLog) TableName

func (mdl *PowerOperationLog) TableName() string

TableName overrides the table name used by price_book to `profiles`

type PowerPivot

type PowerPivot struct {
	ID        int32     `gorm:"AUTO_INCREMENT;PRIMARY_KEY;not null" json:"id"`
	CreatedAt time.Time `gorm:"column:created_at; ->;<-:create " json:"createdAt"`
	UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
}

func NewPowerPivot

func NewPowerPivot() *PowerPivot

func (*PowerPivot) GetForeignKey

func (mdl *PowerPivot) GetForeignKey() string

func (*PowerPivot) GetForeignRefer

func (mdl *PowerPivot) GetForeignRefer() string

func (*PowerPivot) GetForeignReferValue

func (mdl *PowerPivot) GetForeignReferValue() string

func (*PowerPivot) GetForeignValue

func (mdl *PowerPivot) GetForeignValue() string

func (*PowerPivot) GetID

func (mdl *PowerPivot) GetID() int32

func (*PowerPivot) GetJoinKey

func (mdl *PowerPivot) GetJoinKey() string

func (*PowerPivot) GetJoinValue

func (mdl *PowerPivot) GetJoinValue() string

func (*PowerPivot) GetOwnerKey

func (mdl *PowerPivot) GetOwnerKey() string

func (*PowerPivot) GetOwnerValue

func (mdl *PowerPivot) GetOwnerValue() string

func (*PowerPivot) GetPivotComposedUniqueID

func (mdl *PowerPivot) GetPivotComposedUniqueID() string

func (*PowerPivot) GetPowerModel

func (mdl *PowerPivot) GetPowerModel() ModelInterface

func (*PowerPivot) GetPrimaryKey

func (mdl *PowerPivot) GetPrimaryKey() string

func (*PowerPivot) GetTableName

func (mdl *PowerPivot) GetTableName(needFull bool) string

--------------------------------------------------------------------

func (*PowerPivot) GetUUID

func (mdl *PowerPivot) GetUUID() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL