db

package
v0.0.0-...-da2e21c Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(dbMode string) (*gorm.DB, error)

Connect connects to its database and returns the instance

func Instance

func Instance(c *gin.Context) *gorm.DB

Instance returns the connected db instance

func IsIpv4AddressIncluding

func IsIpv4AddressIncluding(baseCIDR, targetCIDR string) bool

IsIpv4AddressIncluding checks if left includes right network address, used in sqlite3

func SetupCustomDBFunctions

func SetupCustomDBFunctions()

SetupCustomDBFunctions setups custom sql functions

Types

type Parameter

type Parameter struct {
	Filters             map[string]string
	Preloads            string
	PreloadsFilterMap   map[string]map[string]string
	Sort                string
	Limit               int
	Page                int
	LastID              int
	Order               string
	IsLastID            bool
	IsPaginationEnabled bool
}

Parameter is the struct what contains parameters related to db

func NewParameter

func NewParameter(query url.Values) (*Parameter, error)

NewParameter creates a new Parameter instance

func (*Parameter) DefaultQuery

func (parameter *Parameter) DefaultQuery(query url.Values, key string, defaultValue string) string

DefaultQuery get a query parameter. If key does not exist, it returns defaultValue

func (*Parameter) FilterFields

func (parameter *Parameter) FilterFields(db *gorm.DB) *gorm.DB

FilterFields filters fields

func (*Parameter) GetRawFilterQuery

func (parameter *Parameter) GetRawFilterQuery() string

GetRawFilterQuery generates a filter query string

func (*Parameter) Paginate

func (parameter *Parameter) Paginate(db *gorm.DB) (*gorm.DB, error)

Paginate sets the parameter related to pagination to db

func (parameter *Parameter) SetHeaderLink(c *gin.Context, index int) error

SetHeaderLink sets the header links to HTTP header

func (*Parameter) SetPreloads

func (parameter *Parameter) SetPreloads(db *gorm.DB) *gorm.DB

SetPreloads configures the preload settings of the connected db

func (*Parameter) SortRecords

func (parameter *Parameter) SortRecords(db *gorm.DB) *gorm.DB

SortRecords set the sort method to the db

Jump to

Keyboard shortcuts

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