postgres

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(cfg *Config) (err error)

Types

type ColumnFilter

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

func NewEqualFilter

func NewEqualFilter(column string, value interface{}) ColumnFilter

func NewGreaterFilter

func NewGreaterFilter(column string, value interface{}) ColumnFilter

func NewInFilter

func NewInFilter(column string, value interface{}) ColumnFilter

func NewLikeFilter

func NewLikeFilter(column string, value string) ColumnFilter

type Config

type Config struct {
	Host    string `json:"host"     required:"true"`
	User    string `json:"user"     required:"true"`
	Pwd     string `json:"pwd"      required:"true"`
	Name    string `json:"name"     required:"true"`
	Port    int    `json:"port"     required:"true"`
	Life    int    `json:"life"     required:"true"`
	MaxConn int    `json:"max_conn" required:"true"`
	MaxIdle int    `json:"max_idle" required:"true"`
}

Config DbLife: the unit is minute

func (*Config) SetDefault

func (cfg *Config) SetDefault()

type DbTable

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

func NewDBTable

func NewDBTable(name string) DbTable

func (DbTable) AutoMigrate

func (t DbTable) AutoMigrate(dst interface{}) error

func (DbTable) Count

func (t DbTable) Count(filter []ColumnFilter) (int, error)

func (DbTable) DB

func (t DbTable) DB() *gorm.DB

func (DbTable) ExecSQL

func (t DbTable) ExecSQL(sql string, result interface{}, args ...interface{}) error

func (DbTable) FirstOrCreate

func (t DbTable) FirstOrCreate(filter, result interface{}) error

func (DbTable) FirstOrCreateWithNot

func (t DbTable) FirstOrCreateWithNot(filter, notFilter, result interface{}) error

func (DbTable) GetRecord

func (t DbTable) GetRecord(filter, result interface{}) error

func (DbTable) GetRecords

func (t DbTable) GetRecords(
	filter []ColumnFilter, result interface{}, p Pagination, sort []SortByColumn,
) (err error)

func (DbTable) Insert

func (t DbTable) Insert(result interface{}) error

func (DbTable) IsRowExists

func (t DbTable) IsRowExists(err error) bool

func (DbTable) IsRowNotFound

func (t DbTable) IsRowNotFound(err error) bool

func (DbTable) UpdateRecord

func (t DbTable) UpdateRecord(filter, update interface{}) (err error)

type Pagination

type Pagination struct {
	PageNum      int
	CountPerPage int
}

type SortByColumn

type SortByColumn struct {
	Column string
	Ascend bool
}

Jump to

Keyboard shortcuts

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