models

package
v0.0.0-...-ca969d9 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUser

func AddUser(m *User) (id int64, err error)

AddUser insert a new User into database and returns last inserted Id on success.

func DeleteUser

func DeleteUser(id int64) (err error)

DeleteUser deletes User by Id and returns error if the record to be deleted doesn't exist

func GetAllUser

func GetAllUser(query map[string]string, fields []string, sortby []string, order []string,
	offset int64, limit int64) (ml []interface{}, err error)

GetAllUser retrieves all User matches certain condition. Returns empty list if no records exist

func UpdateUserById

func UpdateUserById(m *User) (err error)

UpdateUserById updates User by Id and returns error if the record to be updated doesn't exist

Types

type Base

type Base struct {
	UUID      uuid.UUID  `gorm:"type:uuid;" json:"uuid"`
	OwnerID   string     `json:"owner_id"`
	CreatedAt time.Time  `orm:"auto_now_add;type(datetime)" json:"created_at"`
	UpdatedAt time.Time  `orm:"auto_now;type(datetime)" json:"updated_at"`
	DeletedAt *time.Time `sql:"index"`
}

Base contains common columns for all tables.

func (*Base) BeforeCreate

func (base *Base) BeforeCreate(scope *gorm.Scope) error

BeforeCreate will set a UUID rather than numeric ID.

type User

type User struct {
	ID int64 `orm:"auto"`
	Base
	Username string `gorm:"column:name;size:128;not null;" json:"username"`
	Password string
}

User is the model for the user table.

func GetUserById

func GetUserById(id int64) (v *User, err error)

GetUserById retrieves User by Id. Returns error if Id doesn't exist

Jump to

Keyboard shortcuts

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