dao

package
v0.0.0-...-6093075 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExprValue

func ExprValue(val interface{}) interface{}

func GenerateColumnNames

func GenerateColumnNames(targetFile, tabledMd string, models ...interface{}) error

func IsRecordNotFound

func IsRecordNotFound(err error) bool

func IsUniqueConstraintError

func IsUniqueConstraintError(err error) bool

Types

type BaseModel

type BaseModel struct {
	ID        uuid.UUID `gorm:"type:uuid;primary_key;"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (*BaseModel) GenerateID

func (bm *BaseModel) GenerateID()

func (*BaseModel) GetID

func (bm *BaseModel) GetID() uuid.UUID

func (*BaseModel) IsIDNil

func (bm *BaseModel) IsIDNil() bool

type ColumnInfo

type ColumnInfo func() (string, interface{})

type Dao

type Dao struct {
	Logger         Logger                `inject:""`
	StatsCollector *stats.StatsCollector `inject:"db_stats"`

	Debug bool
	// contains filtered or unexported fields
}

func New

func New(version string, database string, connectionString string, models ...interface{}) *Dao

func NewDebug

func NewDebug(version string, database string, connectionString string, models ...interface{}) *Dao

func (*Dao) AddIndex

func (d *Dao) AddIndex(c context.Context, index, validationMsg string, model Model, columns ...string) error

func (*Dao) AddInitialStatements

func (d *Dao) AddInitialStatements(c context.Context, statement string)

func (*Dao) AddListener

func (d *Dao) AddListener(m Model, lstnr ListenerFunc)

func (*Dao) AddUniqueIndex

func (d *Dao) AddUniqueIndex(c context.Context, index, validationMsg string, model Model, columns ...string) error

func (*Dao) ByID

func (d *Dao) ByID(c context.Context, m Model, id uuid.UUID) error

func (*Dao) ByStringID

func (d *Dao) ByStringID(c context.Context, m Model, strID string) error

func (*Dao) Clean

func (d *Dao) Clean() error

func (*Dao) Create

func (d *Dao) Create(c context.Context, m Model) error

func (*Dao) CreateMulti

func (d *Dao) CreateMulti(c context.Context, modls ...Model) error

func (*Dao) CreateOrUpdate

func (d *Dao) CreateOrUpdate(c context.Context, m Model) error

func (*Dao) CreateOrUpdateColumns

func (d *Dao) CreateOrUpdateColumns(c context.Context, m Model, ci ...ColumnInfo) error

func (*Dao) DbInfo

func (d *Dao) DbInfo(c context.Context) (string, error)

func (*Dao) Delete

func (d *Dao) Delete(c context.Context, m Model) error

func (*Dao) GetDeletedByID

func (d *Dao) GetDeletedByID(c context.Context, m Model, id uuid.UUID) error

func (*Dao) Init

func (d *Dao) Init() error

func (*Dao) IsRecordNotFound

func (d *Dao) IsRecordNotFound(err error) bool

func (*Dao) Load

func (d *Dao) Load(c context.Context, m Model) error

func (*Dao) Print

func (d *Dao) Print(v ...interface{})

Print is used to log sql statements (implementation of gorm.logger)

func (*Dao) Query

func (d *Dao) Query(c context.Context) *Query

func (*Dao) Reload

func (d *Dao) Reload(c context.Context, models ...Model) error

func (*Dao) UpdateColumnValues

func (d *Dao) UpdateColumnValues(c context.Context, model Model, cols map[string]interface{}) error

func (*Dao) UpdateColumns

func (d *Dao) UpdateColumns(c context.Context, model Model, ci ...ColumnInfo) error

type DbHook

type DbHook int
const (
	BeforeCreate DbHook = iota
	AfterCreate  DbHook = iota
	BeforeUpdate DbHook = iota
	AfterUpdate  DbHook = iota
	AfterDelete  DbHook = iota
)

type DbStatsCollector

type DbStatsCollector interface {
	AddStats(c context.Context, since time.Time, queryFmt string, params ...interface{})
}

type DeletableBaseModel

type DeletableBaseModel struct {
	BaseModel
	DeletedAt *time.Time `sql:"index"`
}

DeletableBaseModel can be used for tables with `deleted_at` columns.

Use GetDeletedByID() to load those entities anyway.

Note that the problem with keeping those in the table are unique columns. For example, a user with `deleted_at` set will still have an email, and any new user can't reuse it. So, if keeping deleted values is important -- maybe it would be better to keep them in another table.

type HookCtx

type HookCtx struct {
	Fields    map[string]interface{}
	AllFields bool
	Vars      map[string]interface{}
	// contains filtered or unexported fields
}

func (HookCtx) HasField

func (hctx HookCtx) HasField(fld string) bool

type Listener

type Listener interface {
	DbHook(c context.Context, hook DbHook, hctx *HookCtx)
}

type ListenerFunc

type ListenerFunc func(c context.Context, hook DbHook, m Model, hctx *HookCtx)

type Logger

type Logger interface {
	Debugf(c context.Context, format string, args ...interface{})
	Infof(c context.Context, format string, args ...interface{})
	Warningf(c context.Context, format string, args ...interface{})
	Errorf(c context.Context, format string, args ...interface{})
	Errf(c context.Context, err error, format string, args ...interface{})
	Criticalf(c context.Context, format string, args ...interface{})
	ClearErrorSamples() []string
}

type Model

type Model interface {
	GetID() uuid.UUID
	GenerateID()
	IsIDNil() bool
}

type Query

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

func (*Query) All

func (q *Query) All(target interface{}) error

func (*Query) AllIterator

func (q *Query) AllIterator(m Model) (*QueryIterator, error)

func (*Query) AllWithPageFull

func (q *Query) AllWithPageFull(target interface{}) (pageFull bool, err error)

func (*Query) Count

func (q *Query) Count(sample Model) (int, error)

func (*Query) Filter

func (q *Query) Filter(column, operation string, value interface{}) *Query

func (*Query) FilterExpr

func (q *Query) FilterExpr(expr ...interface{}) *Query

func (*Query) FilterIn

func (q *Query) FilterIn(column string, values ...interface{}) *Query

func (*Query) FilterInStrings

func (q *Query) FilterInStrings(column string, valuesStrs ...string) *Query

func (*Query) FilterIsNotNull

func (q *Query) FilterIsNotNull(column string) *Query

func (*Query) FilterRawExpression

func (q *Query) FilterRawExpression(expression string, values ...interface{}) *Query

func (*Query) First

func (q *Query) First(target Model) error

func (*Query) FulltextSearch

func (q *Query) FulltextSearch(columns []string, values []string) *Query

FulltextSearch uses postgresql fulltext, which means the words must be whole (i.e. it won't search by substrings)

func (*Query) FulltextSubsttringSearch

func (q *Query) FulltextSubsttringSearch(table string, columns []string, values []string, limit int) (*QueryIterator, error)

FulltextSubsttringSearch can be slow!

func (*Query) IncludeDeleted

func (q *Query) IncludeDeleted() *Query

func (*Query) OrderByAsc

func (q *Query) OrderByAsc(column string) *Query

func (*Query) OrderByDesc

func (q *Query) OrderByDesc(column string) *Query

func (*Query) OrderByExpression

func (q *Query) OrderByExpression(expr ...interface{}) *Query

func (*Query) OrderByRawExpression

func (q *Query) OrderByRawExpression(expression string, values ...interface{}) *Query

func (*Query) RawIterator

func (q *Query) RawIterator(sql string, values ...interface{}) (*QueryIterator, error)

func (*Query) RawRows

func (q *Query) RawRows(sql string, values ...interface{}) (*sql.Rows, error)

func (*Query) WithDefaultPageSize

func (q *Query) WithDefaultPageSize() *Query

func (*Query) WithMaxIntPageSize

func (q *Query) WithMaxIntPageSize() *Query

func (*Query) WithPageNo

func (q *Query) WithPageNo(n int) *Query

func (*Query) WithPageNoString

func (q *Query) WithPageNoString(s string) *Query

func (*Query) WithPageSize

func (q *Query) WithPageSize(s int) *Query

func (*Query) WithStringPageNo

func (q *Query) WithStringPageNo(n string) *Query

type QueryIterator

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

func (QueryIterator) Close

func (qi QueryIterator) Close()

Close closes the rows. It will be called automatically if iterator is iterated until the last line.

func (QueryIterator) Next

func (qi QueryIterator) Next() bool

func (QueryIterator) Scan

func (qi QueryIterator) Scan(target Model) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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