loggable

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2017 License: MIT Imports: 9 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

This section is empty.

Functions

This section is empty.

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 LoggableModel

type LoggableModel struct {
}

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) (LoggablePlugin, error)

Jump to

Keyboard shortcuts

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