pgdb

package
v0.0.0-...-470388c Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPageLimit = 25
View Source
const MaxPageLimit = 100

Variables

This section is empty.

Functions

func Paginate

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

func ToIDModelMap

func ToIDModelMap[M NamedModel](models []M) map[int]M

func ToNameModelMap

func ToNameModelMap[M NamedModel](models []M) map[string]M

Types

type BaseModel

type BaseModel struct {
	ID        int `gorm:"primarykey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

func (BaseModel) IsDeleted

func (d BaseModel) IsDeleted() bool

func (BaseModel) Joins

func (s BaseModel) Joins() []string

func (BaseModel) PK

func (d BaseModel) PK() int

type Config

type Config struct {
	Name            string
	Host            string
	Port            int
	User            string `log:"-"`
	Password        string `log:"-"`
	SSLRootCertPath string
	DebugMigrations bool
	Debug           bool
}

type NamedModel

type NamedModel interface {
	GetName() string
	PK() int
}

type PGDB

type PGDB struct {
	// contains filtered or unexported fields
}

func NewPGConnection

func NewPGConnection(ctx context.Context, config Config) *PGDB

func (*PGDB) DB

func (d *PGDB) DB(ctx context.Context) *gorm.DB

func (*PGDB) Migrate

func (db *PGDB) Migrate(ctx context.Context, models []any)

func (*PGDB) TableName

func (db *PGDB) TableName(m any) string

type Page

type Page struct {
	Page  int `form:"page"`
	Limit int `form:"limit"`
	After int `form:"after"`
}

func NewPage

func NewPage(page, after, limit int) Page

func (Page) Offset

func (p Page) Offset() int

Jump to

Keyboard shortcuts

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