db

package
v0.0.0-...-900ead6 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB global defined db config

View Source
var SlaveDB *gorm.DB

SlaveDB global defined db config

Functions

func CloseDB

func CloseDB()

CloseDB close db connection

func Connection

func Connection() *gorm.DB

Connection get db connection

func Setup

func Setup()

Setup init db

func SlaveConnection

func SlaveConnection() *gorm.DB

SlaveConnection get db connection

Types

type Configure

type Configure struct {
	Database  string `env:"MYSQL_DATABASE" envDefault:"database"`
	Username  string `env:"MYSQL_USERNAME" envDefault:"user"`
	Password  string `env:"MYSQL_PASSWORD" envDefault:"password"`
	Host      string `env:"MYSQL_HOST" envDefault:"localhost"`
	SlaveHost string `env:"MYSQL_SLAVE_HOST" envDefault:""`
	Port      string `env:"MYSQL_PORT" envDefault:"3306"`
}

Configure config for db

var Config Configure

Config global defined db config

type Model

type Model struct {
	ID        uint64     `form:"id" json:"id" gorm:"primary_key"`
	CreatedBy uint64     `json:"-"`
	UpdatedBy uint64     `json:"-"`
	DeletedBy uint64     `json:"-"`
	CreatedAt time.Time  `json:"createdAt"`
	UpdatedAt time.Time  `json:"updatedAt"`
	DeletedAt *time.Time `json:"-" sql:"index"`
}

Model global basic model struct

type Pagination

type Pagination struct {
	Data interface{} `json:"data"`
	Meta struct {
		Total     int `json:"total"`
		TotalPage int `json:"totalPage"`
		Offset    int `json:"offset"`
		Limit     int `json:"limit"`
		Page      int `json:"page"`
		PrevPage  int `json:"prevPage"`
		NextPage  int `json:"nextPage"`
	} `json:"meta"`
}

Pagination for using pagination

func Paginate

func Paginate(p *PaginationParam, dataSource interface{}) *Pagination

Paginate for using pagination

type PaginationParam

type PaginationParam struct {
	DB          *gorm.DB
	Page        int    `form:"page" json:"page"`
	Limit       int    `form:"limit" json:"limit"`
	OrderBy     string `form:"orderBy" json:"orderBy"`
	OrderBySort string `form:"orderBySort" json:"orderBySort"`
}

PaginationParam for using pagination

Jump to

Keyboard shortcuts

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