mysql

package
v1.6.65 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Index

Constants

View Source
const ORG_TABLE = "org"

Variables

This section is empty.

Functions

func CheckIfORGTableExists

func CheckIfORGTableExists() (bool, error)

func CheckORGNumberAndLog

func CheckORGNumberAndLog() ([]int, error)

func GetColumnNameFromTag

func GetColumnNameFromTag(tag string) string

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 GetDeletedORGIDs() ([]int, error)

func GetNonDefaultORGIDs

func GetNonDefaultORGIDs() ([]int, error)

GetNonDefaultORGIDs returns a slice of organization IDs, not including the default organization ID and the soft deleted organization IDs.

func GetORGIDs

func GetORGIDs() ([]int, error)

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

func SyncDefaultOrgData[T any](data []T, excludeFields []string) error

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
)

func GetDB

func GetDB(orgID int) (*DB, error)

func NewDB

func NewDB(cfg config.MySqlConfig, orgID int) (*DB, error)

func (*DB) GetGORMDB

func (d *DB) GetGORMDB() *gorm.DB

func (*DB) GetName

func (d *DB) GetName() string

func (*DB) GetORGID

func (d *DB) GetORGID() int

type DBNameLogPrefix

type DBNameLogPrefix struct {
	Name string
}

func NewDBNameLogPrefix

func NewDBNameLogPrefix(name string) *DBNameLogPrefix

func (*DBNameLogPrefix) Prefix

func (n *DBNameLogPrefix) Prefix() string

type DBs

type DBs struct {
	// contains filtered or unexported fields
}

func GetDBs

func GetDBs() *DBs

func (*DBs) All

func (c *DBs) All() []*DB

func (*DBs) Create

func (c *DBs) Create(orgID int)

func (*DBs) Delete

func (c *DBs) Delete(orgID int)

func (*DBs) DoOnAllDBs

func (c *DBs) DoOnAllDBs(execFunc func(db *DB) error) error

func (*DBs) GetConfig

func (c *DBs) GetConfig() config.MySqlConfig

func (*DBs) Init

func (c *DBs) Init(cfg config.MySqlConfig) error

func (*DBs) NewDBIfNotExists

func (c *DBs) NewDBIfNotExists(orgID int) (*DB, error)

Directories

Path Synopsis
schema/rawsql
DO NOT DELETE for go list to grab directory
DO NOT DELETE for go list to grab directory
edition Module
table Module
*
*

Jump to

Keyboard shortcuts

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