database

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PostgreSQL

func PostgreSQL() *gorm.DB

PostgreSQL returns a PostgreSQL connection pool.

func Redis

func Redis() *redis.Client

Redis returns a client to Redis Server.

Types

type BaseModel

type BaseModel struct {
	ID string `json:"id" gorm:"PRIMARY_KEY"`

	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at" sql:"index"`
}

BaseModel is a model definition, including fields `ID` as UUID, `CreatedAt`, `UpdatedAt`, and `DeletedAt`, which could be embedded in your models.

USAGE:

type User struct {
	database.BaseModel

	Email    string `json:"email" gorm:"UNIQUE;NOT NULL"`
	Password string `json:"password" gorm:"NOT NULL"`
}

func (*BaseModel) BeforeSave

func (baseModel *BaseModel) BeforeSave(tx *gorm.DB) error

BeforeSave generates and sets an `UUID` for `ID` column.

Jump to

Keyboard shortcuts

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