gormate

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: MIT Imports: 6 Imported by: 0

README

gormate

GORM Mate for gorm.io/gorm.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrDBNotFound warnings gorm.DB not in context.
	ErrDBNotFound = fmt.Errorf("gorm.DB not in context")
)

Functions

func BindContext

func BindContext(ctx context.Context, db *gorm.DB) (newCtx context.Context)

BindContext binds *gorm.DB

func FromContext

func FromContext(ctx context.Context) (db *gorm.DB, err error)

FromContext returns *gorm.DB

Types

type Creator added in v0.3.0

type Creator interface {
	Create(ctx context.Context, i NamedTable) error
	CreateAll(ctx context.Context, i interface{}) error
}

Creator interface.

type Fetcher added in v0.3.0

type Fetcher interface {
	GetByID(ctx context.Context, i NamedTable, id uint64) error
	GetByMultiID(ctx context.Context, i interface{}, ids []uint64) error
	GetByCondition(ctx context.Context, i, cond interface{}, args ...interface{}) error
}

Fetcher interface.

type Model

type Model struct {
	ID        uint64         `json:"id" gorm:"primaryKey"`
	CreatedAt TimeFormat     `json:"createdAt" gorm:"autoCreateTime;type:time"`
	UpdatedAt TimeFormat     `json:"updatedAt" gorm:"autoUpdateTime;type:time"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}

Model for gorm

func (*Model) PK added in v0.2.0

func (m *Model) PK() uint64

PK returns primaryKey

type NamedTable added in v0.2.0

type NamedTable interface {
	TableName() string
	PK() uint64
}

NamedTable for name and PK.

type Operator added in v0.2.0

type Operator struct{}

Operator collections.

func (*Operator) Create added in v0.2.0

func (o *Operator) Create(ctx context.Context, i NamedTable) error

Create item.

func (*Operator) CreateAll added in v0.2.0

func (o *Operator) CreateAll(ctx context.Context, i interface{}) error

CreateAll items.

func (*Operator) GetByCondition added in v0.2.0

func (o *Operator) GetByCondition(ctx context.Context, i, cond interface{}, args ...interface{}) error

GetByCondition query items by conditions.

func (*Operator) GetByID added in v0.2.0

func (o *Operator) GetByID(ctx context.Context, i NamedTable, id uint64) error

GetByID query item by id.

func (*Operator) GetByMultiID added in v0.2.0

func (o *Operator) GetByMultiID(ctx context.Context, i interface{}, ids []uint64) error

GetByMultiID query items by id.

func (*Operator) Remove added in v0.2.0

func (o *Operator) Remove(ctx context.Context, i NamedTable) error

Remove item.

func (*Operator) RemoveAll added in v0.2.0

func (o *Operator) RemoveAll(ctx context.Context, i NamedTable, cond ...interface{}) error

RemoveAll items.

func (*Operator) Save added in v0.2.0

func (o *Operator) Save(ctx context.Context, i NamedTable, selected ...string) error

Save item.

func (*Operator) Updates added in v0.2.0

func (o *Operator) Updates(ctx context.Context, i NamedTable, values map[string]interface{}) error

Updates given fields.

func (*Operator) UpdatesAll added in v0.2.0

func (o *Operator) UpdatesAll(ctx context.Context, i NamedTable, values map[string]interface{}, cond ...interface{}) error

UpdatesAll items.

type Remover added in v0.3.0

type Remover interface {
	Remove(ctx context.Context, i NamedTable) error
	RemoveAll(ctx context.Context, i NamedTable, cond ...interface{}) error
}

Remover interface.

type TimeFormat

type TimeFormat time.Time

TimeFormat with json/db outputs

func (*TimeFormat) FromTime

func (tf *TimeFormat) FromTime(t time.Time)

func (TimeFormat) MarshalJSON

func (tf TimeFormat) MarshalJSON() ([]byte, error)

MarshalJSON for json.Marshaler.

func (*TimeFormat) Scan

func (tf *TimeFormat) Scan(v interface{}) error

Scan value of time.Time

func (TimeFormat) Time

func (tf TimeFormat) Time() time.Time

func (TimeFormat) Value

func (tf TimeFormat) Value() (driver.Value, error)

Value to driver.Value.

type Updater added in v0.3.0

type Updater interface {
	Save(ctx context.Context, i NamedTable, selected ...string) error
	Updates(ctx context.Context, i NamedTable, values map[string]interface{}) error
	UpdatesAll(ctx context.Context, i NamedTable, values map[string]interface{}, cond ...interface{}) error
}

Updater interface.

Jump to

Keyboard shortcuts

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