Documentation ¶
Overview ¶
Package gormodel toolkits.
Index ¶
- func BindContext(ctx context.Context, db *gorm.DB) (c context.Context)
- func ExtractContext(ctx context.Context) (db *gorm.DB)
- type Actions
- type Base
- func (b *Base) Create(ctx context.Context, i interface{}) error
- func (b *Base) FirstOrCreate(ctx context.Context, i interface{}) error
- func (b *Base) Get(ctx context.Context, i interface{}) error
- func (b *Base) GetByID(ctx context.Context, i interface{}, id ...uint) error
- func (b *Base) Remove(ctx context.Context, i interface{}) error
- func (b *Base) UpdateAttrs(ctx context.Context, i interface{}, attrs map[string]interface{}) error
- func (b *Base) UpdateOrCreate(ctx context.Context, i interface{}) error
- type Creator
- type Finder
- type Model
- type Modeler
- type Remover
- type Updater
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindContext ¶
BindContext bind db to context.Context.
Types ¶
type Base ¶
type Base struct { }
Base operations helpers.
func (*Base) FirstOrCreate ¶ added in v0.2.0
FirstOrCreate create if exists or return first match
func (*Base) UpdateAttrs ¶ added in v0.2.0
UpdateAttrs updates given attrs.
type Creator ¶ added in v0.2.0
type Creator interface { Create(context.Context, interface{}) error FirstOrCreate(context.Context, interface{}) error }
Creator for create actions.
type Finder ¶ added in v0.2.0
type Finder interface { GetByID(context.Context, interface{}, ...uint) error Get(context.Context, interface{}) error }
Finder for find actions.
type Model ¶
type Model struct { ID uint `gorm:"PRIMARY_KEY" json:"id"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` DeletedAt *time.Time `sql:"index" json:"-"` }
Model likes gorm.Model but with json little camel-case keys.
Example ¶
package main import ( "github.com/ipfans/gormodel" ) func main() { type User struct { gormodel.Model Name string } }
Output:
type Modeler ¶ added in v0.2.0
type Modeler interface {
TableName() string
}
Modeler for table name.
Click to show internal directories.
Click to hide internal directories.