gorm

package module
v3.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deadlock

func Deadlock(err error) bool

Deadlock is true when deadlock was detected

func NotFound

func NotFound(err error) bool

NotFound is true when there was no appropriate record

func UniqueViolation

func UniqueViolation(err error) bool

UniqueViolation is true when database unique index is violated

Types

type Backend

type Backend struct {
	DB              *gorm.DB
	Driver          gorm.Dialector
	Config          *gorm.Config
	Debug           bool
	UseLogMixin     bool
	Migrate         bool
	MaxIdleConns    int
	MaxOpenConns    int
	ConnMaxLifetime time.Duration
	InitSchema      func(*gorm.DB) error
}

Backend implements generic database backend

func (*Backend) Begin

func (b *Backend) Begin() *Backend

func (*Backend) Close

func (b *Backend) Close() error

Close DB connection

func (*Backend) Connect

func (b *Backend) Connect(migrations ...*gormigrate.Migration) error

Connect sets up the backend and applies migrations if Migrate flag is set to true. InitSchema func if set, is used to create initial schema.

func (*Backend) Context

func (b *Backend) Context() context.Context

Context returns context associated with Backend

func (*Backend) End

func (b *Backend) End(rErr error) error

func (*Backend) WithContext

func (b *Backend) WithContext(ctx context.Context) *Backend

WithContext creates Backend clone with new context and logger

func (*Backend) WithLogger

func (b *Backend) WithLogger(printer Printer) *Backend

WithLogger injects log printer func into Backend

type Pagination

type Pagination struct {
	PageSize      int    `json:"page_size"`
	NextPageToken string `json:"next_page_token"`
	ThisPageToken string `json:"this_page_token"`
	PrevPageToken string `json:"prev_page_token"`
}

Pagination contains pagination fields

func (*Pagination) GetPageSize

func (p *Pagination) GetPageSize() int

GetPageSize returns pagination size

type Paginator

type Paginator[A any] struct {
	FieldName     string
	TieBreakField string
	Reverse       bool
	Debug         bool
	IsTime        bool
}

Paginator provides cursor-based paginator

func (*Paginator[A]) Paginate

func (p *Paginator[A]) Paginate(src []A, pgn *Pagination) ([]A, *Pagination)

Paginate query result according to parameter

func (*Paginator[A]) Scope

func (p *Paginator[A]) Scope(pgn *Pagination) func(*gorm.DB) *gorm.DB

Scope provides proper offset and ordering for cursor db

type Printer

type Printer func(string, ...interface{})

func (Printer) Printf

func (p Printer) Printf(format string, vals ...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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