Documentation
¶
Index ¶
- Variables
- func DefaultCopyFunc(r Recordable, h interface{}) error
- func Disable(db *gorm.DB) *gorm.DB
- func IsDisabled(db *gorm.DB) bool
- func SetSource(db *gorm.DB, source Source) *gorm.DB
- func SetUser(db *gorm.DB, user User) *gorm.DB
- type Action
- type BlameableHistory
- type Config
- type ConfigFunc
- type Context
- type CopyFunc
- type Entry
- func (e *Entry) SetHistoryAction(action Action)
- func (e *Entry) SetHistoryCreatedAt(createdAt time.Time)
- func (e *Entry) SetHistoryObjectID(id interface{})
- func (e *Entry) SetHistorySourceID(id string)
- func (e *Entry) SetHistorySourceType(typ string)
- func (e *Entry) SetHistoryUserEmail(email string)
- func (e *Entry) SetHistoryUserID(id string)
- func (e *Entry) SetHistoryVersion(version Version)
- type History
- type IsZeroer
- type Option
- type Plugin
- type Recordable
- type Source
- type SourceableHistory
- type TimestampableHistory
- type ULIDVersion
- type User
- type Version
- type VersionFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrUnsupportedOperation = errors.New("history is not supported for this operation")
)
Functions ¶
func DefaultCopyFunc ¶
func DefaultCopyFunc(r Recordable, h interface{}) error
func IsDisabled ¶
Types ¶
type BlameableHistory ¶
type Config ¶
type Config struct {
VersionFunc VersionFunc
CopyFunc CopyFunc
}
type ConfigFunc ¶
type ConfigFunc func(c *Config)
func WithCopyFunc ¶
func WithCopyFunc(fn CopyFunc) ConfigFunc
func WithVersionFunc ¶
func WithVersionFunc(fn VersionFunc) ConfigFunc
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) Object ¶
func (c *Context) Object() Recordable
type CopyFunc ¶
type CopyFunc func(r Recordable, h interface{}) error
type Entry ¶
type Entry struct {
Version Version `gorm:"type:char(26)"`
ObjectID string `gorm:"index"`
Action Action `gorm:"type:varchar(24)"`
UserID string `gorm:"type:varchar(255)"`
UserEmail string `gorm:"type:varchar(255)"`
SourceID string `gorm:"type:varchar(255)"`
SourceType string `gorm:"type:varchar(255)"`
CreatedAt time.Time `gorm:"type:datetime"`
}
func (*Entry) SetHistoryAction ¶
func (*Entry) SetHistoryCreatedAt ¶
func (*Entry) SetHistoryObjectID ¶
func (e *Entry) SetHistoryObjectID(id interface{})
func (*Entry) SetHistorySourceID ¶
func (*Entry) SetHistorySourceType ¶
func (*Entry) SetHistoryUserEmail ¶
func (*Entry) SetHistoryUserID ¶
func (*Entry) SetHistoryVersion ¶
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Example ¶
type Person struct {
gorm.Model
FirstName string
LastName string
}
type PersonHistory struct {
gorm.Model
Entry
}
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
if err != nil {
panic(err)
}
db = db.Session(&gorm.Session{})
err = db.AutoMigrate(Person{}, PersonHistory{})
if err != nil {
panic(err)
}
plugin := New()
if err := db.Use(plugin); err != nil {
return
}
p := Person{
FirstName: "John",
LastName: "Doe",
}
if err := db.Save(&p).Error; err != nil {
panic(err)
}
func New ¶
func New(configFuncs ...ConfigFunc) *Plugin
type Recordable ¶
type Recordable interface {
CreateHistory() History
}
type SourceableHistory ¶
type TimestampableHistory ¶
type ULIDVersion ¶
type ULIDVersion struct {
// contains filtered or unexported fields
}
func NewULIDVersion ¶
func NewULIDVersion() *ULIDVersion
type VersionFunc ¶
Click to show internal directories.
Click to hide internal directories.