loggable

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2018 License: MIT Imports: 11 Imported by: 0

README

Loggable

Loggable is used to helps tracking changes and history of your GORM models.

It creates change_logs table in your database and writes to all loggable models when they are changed.

Usage

  1. Register plugin using loggable.Register(db)
  2. Add loggable.LoggableModel to your GORM model
  3. If you want to set user, who makes changes, and place, where it happened, use loggable.SetUserAndFrom("username", "London").

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ToSnakeCase = toSomeCase("_")

Functions

func LazyUpdateOption added in v1.3.0

func LazyUpdateOption(fields ...string) func(options *options)

func StringMap added in v1.1.1

func StringMap(strs []string, fn func(string) string) []string

func ToLowerFirst added in v1.1.1

func ToLowerFirst(s string) string

Types

type ChangeLog

type ChangeLog struct {
	ID           string    `gorm:"type:uuid;primary_key;"`
	CreatedAt    time.Time `sql:"DEFAULT:current_timestamp"`
	ChangedBy    string    `gorm:"index"`
	ChangedWhere string    `gorm:"index"`
	Action       string
	ObjectID     string `gorm:"index"`
	ObjectType   string `gorm:"index"`
	Object       JSONB  `sql:"type:JSONB"`
}

type JSONB

type JSONB []byte

func (JSONB) Equals

func (j JSONB) Equals(j1 JSONB) bool

func (JSONB) IsNull

func (j JSONB) IsNull() bool

func (JSONB) MarshalJSON

func (j JSONB) MarshalJSON() ([]byte, error)

func (*JSONB) Scan

func (j *JSONB) Scan(value interface{}) error

func (*JSONB) UnmarshalJSON

func (j *JSONB) UnmarshalJSON(data []byte) error

func (JSONB) Value

func (j JSONB) Value() (driver.Value, error)

type LoggableInterface added in v1.4.0

type LoggableInterface interface {
	SetEnabled(v bool)
	Enabled() bool
}

type LoggableModel

type LoggableModel struct {
	Disabled bool
}

func (LoggableModel) Enabled added in v1.4.0

func (m LoggableModel) Enabled() bool

func (LoggableModel) SetEnabled added in v1.4.0

func (m LoggableModel) SetEnabled(v bool)

type LoggablePlugin

type LoggablePlugin interface {
	// Deprecated: Use SetUserAndWhere instead.
	SetUser(user string) *gorm.DB
	// Deprecated: Use SetUserAndWhere instead.
	SetWhere(from string) *gorm.DB
	SetUserAndWhere(user, where string) *gorm.DB
	GetRecords(objectId string) ([]*ChangeLog, error)
}

func Register

func Register(db *gorm.DB, opts ...Option) (LoggablePlugin, error)

type Option added in v1.1.1

type Option func(options *options)

Jump to

Keyboard shortcuts

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