Documentation ¶
Index ¶
- Constants
- func CheckIfORGTableExists() (bool, error)
- func CheckORGNumberAndLog() ([]int, error)
- func GetColumnNameFromTag(tag string) string
- func GetConfig() config.MySqlConfig
- func GetDeletedORGIDs() ([]int, error)
- func GetNonDefaultORGIDs() ([]int, error)
- func GetORGIDs() ([]int, error)
- func InitDefaultDB(cfg config.MySqlConfig) error
- func SyncDefaultOrgData[T any](data []T, excludeFields []string) error
- type DB
- type DBNameLogPrefix
- type DBs
Constants ¶
const ORG_TABLE = "org"
Variables ¶
This section is empty.
Functions ¶
func CheckIfORGTableExists ¶
func CheckORGNumberAndLog ¶
func GetColumnNameFromTag ¶
GetColumnNameFromTag extracts the column name from a struct field's "gorm" tag. Parameters: - tag: The "gorm" tag string from a struct field. Returns:
- The extracted column name if the "column" prefix is present in the tag. If the "column" prefix is not found, or if there's no value for the "column" prefix, an empty string is returned.
Example: If the tag is `gorm:"column:ip;unique"`, the function returns "ip".
func GetConfig ¶
func GetConfig() config.MySqlConfig
func GetDeletedORGIDs ¶
func GetNonDefaultORGIDs ¶
GetNonDefaultORGIDs returns a slice of organization IDs, not including the default organization ID and the soft deleted organization IDs.
func GetORGIDs ¶
GetORGIDs returns a slice of organization IDs, including the default organization ID, but not including the soft deleted organization IDs.
func InitDefaultDB ¶
func InitDefaultDB(cfg config.MySqlConfig) error
func SyncDefaultOrgData ¶
SyncDefaultOrgData synchronizes a slice of data items of any type T to all organization databases except the default one. It assumes each data item has an "ID" field (with a json tag "ID") serving as the primary key. During upsertion, fields are updated based on their "gorm" tags, and empty string values are converted to null in the database.
Parameters: - data: A slice of data items of any type T to be synchronized. The type T must have an "ID" field tagged as the primary key.
Types ¶
type DB ¶
type DB struct { *gorm.DB ORGID int Name string LogPrefixORGID logger.Prefix LogPrefixName logger.Prefix Config config.MySqlConfig }
var (
DefaultDB *DB
)
type DBNameLogPrefix ¶
type DBNameLogPrefix struct {
Name string
}
func NewDBNameLogPrefix ¶
func NewDBNameLogPrefix(name string) *DBNameLogPrefix
func (*DBNameLogPrefix) Prefix ¶
func (n *DBNameLogPrefix) Prefix() string