db

package
v0.0.0-...-389bc3b Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NowFunc = func() time.Time {
	return time.Now()
}

NowFunc returns current time, this function is exported in order to be able to give the flexibility to the developer to customize it according to their needs, e.g:

NowFunc = func() time.Time {
  return time.Now().UTC()
}

Functions

func CustomQueryWithRows

func CustomQueryWithRows(database *gorm.DB, sql string, ret interface{}) (err error)

CustomQueryWithRows 自定义查询,返回 rows, 并解析 rows 数据到传入的 []struct

func GenReqID

func GenReqID() string

GenReqID is a random generate string func

func Get

func Get(xReqID ...string) *gorm.DB

Get default database or use logger with xReqID

func GetJSON

func GetJSON(obj interface{}) interface{}

GetJSON return obj json string

func GetWithAlias

func GetWithAlias(alias string, xReqID ...string) *gorm.DB

GetWithAlias return DB from database cache with alias

func RegisterDatabase

func RegisterDatabase(drivers ...Driver)

RegisterDatabase register database

Types

type Array

type Array []interface{}

Array MySQL json/array type usage eg.

type User struct {
	ID   uint
	Name string
	Tags db.Array `gorm:"type:json"`
}

func IntArray

func IntArray(array []int) Array

IntArray int array to db array

func StringArray

func StringArray(arr []string) Array

StringArray string array to db Array

func (Array) IntArray

func (a Array) IntArray() []int

IntArray convert db array to int array

func (*Array) Scan

func (a *Array) Scan(value interface{}) error

Scan is custom overwrite func

func (Array) StringArray

func (a Array) StringArray() []string

StringArray convert db Array to string array

func (Array) UintArray

func (a Array) UintArray() []uint

UintArray convert db Array to uint array

func (Array) Value

func (a Array) Value() (driver.Value, error)

Value is custom overwrite func

type Driver

type Driver struct {
	Driver     string `json:"driver"      mapstructure:"driver"`
	User       string `json:"user"        mapstructure:"user"`
	Password   string `json:"password"    mapstructure:"password"`
	Host       string `json:"host"        mapstructure:"host"`
	SSLMode    string `json:"ssl_mode"    mapstructure:"ssl_mode"`
	Port       string `json:"port"        mapstructure:"port"`
	Name       string `json:"name"        mapstructure:"name"`        // database name
	DisableLog bool   `json:"disable_log" mapstructure:"disable_log"` // disable log
	Alias      string `json:"alias"       mapstructure:"alias"`       // default set Name value
	Default    bool   `json:"default"     mapstructure:"default"`     // set default
}

Driver database driver args struct

type H

type H map[string]interface{}

H is map[string]interface{} abbr

type LogWriter

type LogWriter interface {
	Println(v ...interface{})
}

LogWriter log writer interface

type Logger

type Logger struct {
	LogWriter
	XReqID string
}

Logger default logger

func (Logger) Print

func (logger Logger) Print(values ...interface{})

Print format & print log

type Map

type Map map[string]interface{}

Map MySQL json/map type usage eg.

type User struct {
	ID   uint
	Name string
	Tags db.Map `gorm:"type:json"`
}

func StringMap

func StringMap(old map[string]string) Map

StringMap convert map[string]string to db Map

func (*Map) Scan

func (m *Map) Scan(value interface{}) error

Scan is custom overwrite func

func (Map) Value

func (m Map) Value() (driver.Value, error)

Value is custom overwrite func

Jump to

Keyboard shortcuts

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