db

package
v0.0.0-...-8bbec6a Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxLimit represents the max number of items for pagination
	MaxLimit = 100

	// DefaultSlowThreshold represents the default slow threshold value
	DefaultSlowThreshold time.Duration = 200 * time.Millisecond
)

Variables

This section is empty.

Functions

func Paginate

func Paginate(page, limit string) func(db *gorm.DB) *gorm.DB

Paginate creates a GORM scope to paginate queries. TODO: Continue and Optimize

Types

type DB

type DB struct {
	*gorm.DB
}

DB represents the database.

func New

func New(config *DatabaseConfig) (*DB, error)

New makes the connection to the database.

func (*DB) MakeMigrations

func (db *DB) MakeMigrations()

MakeMigrations runs GORM migrations.

type DatabaseConfig

type DatabaseConfig struct {
	Driver          string // Not used
	Host            string
	Username        string
	Password        string
	Port            int
	Database        string
	Charset         string
	Collation       string
	Location        string
	MaxIdleConns    int           // Sets the maximum number of connections in the idle connection pool
	MaxOpenConns    int           // Sets the maximum number of open connections to the database
	ConnMaxLifetime time.Duration // Sets the maximum amount of time a connection may be reused
	SlowThreshold   time.Duration // Slow SQL threshold (Default: 200ms)
}

DatabaseConfig represents the database configuration.

Jump to

Keyboard shortcuts

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