database

package
v2.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DriverMSSQL    = "mssql"
	DriverMySQL    = "mysql"
	DriverSQLLite  = "sqlite3"
	DriverPostgres = "postgres"

	DefaultMySQLCharset = "utf8mb4"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host       string
	Port       string
	Username   string
	Password   string
	Name       string
	DebugMode  bool
	Filename   string
	SSLEnabled bool
	Charset    string
}

type Database

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

func NewMySqlWithConfig added in v2.0.9

func NewMySqlWithConfig(my MySQLConfig) Database

func NewWithConfig

func NewWithConfig(cfg Config, driver string) Database

func (*Database) Close

func (db *Database) Close() error

func (*Database) Connect

func (db *Database) Connect() error

func (*Database) ConnectWithGormConfig

func (db *Database) ConnectWithGormConfig(gormCfg gorm.Config) error

func (*Database) Ctx

func (db *Database) Ctx() *gorm.DB

func (*Database) MigrateDatabase

func (db *Database) MigrateDatabase(tables []interface{}) error

func (*Database) Reconnect

func (db *Database) Reconnect() error

func (*Database) SqlDB

func (db *Database) SqlDB() *sql.DB

type KSModel added in v2.0.9

type KSModel struct {
	Uid       ksuid.KSUID    `json:"uid" gorm:"primary_key;type:varbinary(27);index"`
	CreatedAt time.Time      `json:"created_at" gorm:"index"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

KSModel is uid alternative

func (*KSModel) BeforeCreate added in v2.0.9

func (ks *KSModel) BeforeCreate(tx *gorm.DB) error

type Logger added in v2.0.9

type Logger struct {
	SlowThreshold         time.Duration
	SourceField           string
	SkipErrRecordNotFound bool
	Debug                 bool
}

func NewGormLog added in v2.0.9

func NewGormLog() *Logger

func NewGormLogWithConfig added in v2.0.9

func NewGormLogWithConfig(cfg Logger) *Logger

func (*Logger) Error added in v2.0.9

func (l *Logger) Error(ctx context.Context, s string, args ...interface{})

func (*Logger) Info added in v2.0.9

func (l *Logger) Info(ctx context.Context, s string, args ...interface{})

func (*Logger) LogMode added in v2.0.9

func (*Logger) Trace added in v2.0.9

func (l *Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (*Logger) Warn added in v2.0.9

func (l *Logger) Warn(ctx context.Context, s string, args ...interface{})

type Model

type Model struct {
	Seq       int64          `json:"seq" gorm:"primary_key;auto_increment:false;"`
	Uid       uuid.UUID      `json:"uid" gorm:"primary_key;index"`
	CreatedAt time.Time      `json:"created_at" gorm:"index"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

Model struct

func (*Model) BeforeCreate

func (m *Model) BeforeCreate(tx *gorm.DB) error

BeforeCreate hook table

type MySQLConfig added in v2.0.9

type MySQLConfig struct {
	Host         string
	Port         string
	Username     string
	Password     string
	DatabaseName string
	DebugMode    bool
}

Jump to

Keyboard shortcuts

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