loggable

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 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, use loggable.SetUser("username").

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"`
	ChangedFrom 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 {
	SetUser(user string) *gorm.DB
	SetFrom(from 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