db

package
v0.0.0-...-bd5dacb Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 15 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 Order

func Order(list string, prefixes ...string) func(db *gorm.DB) *gorm.DB

Order creates a GORM scope to sort query attributes. Example: "+created_at,-id" will produce "ORDER BY created_at ASC, id DESC".

func Paginate

func Paginate(p, l string) func(db *gorm.DB) *gorm.DB

Paginate creates a GORM scope to paginate queries.

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() error

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