model

package
v0.0.0-...-0bbac7a Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountUserByWhere

func CountUserByWhere(whereCond string, arg ...interface{}) (int64, error)

CountUserByWhere count User data number from database by WHERE condition. NOTE:

Without cache layer.

func DeleteUserByName

func DeleteUserByName(_name string, deleteHard bool, tx ...*sqlx.Tx) error

DeleteUserByName delete a User data in database by 'name' unique key. NOTE:

With cache layer.

func DeleteUserByPrimary

func DeleteUserByPrimary(_id int64, deleteHard bool, tx ...*sqlx.Tx) error

DeleteUserByPrimary delete a User data in database by primary key. NOTE:

Primary key: 'id';
With cache layer.

func GetMongoDB

func GetMongoDB() *mongo.DB

GetMongoDB returns the mongo DB handler.

func GetMysqlDB

func GetMysqlDB() *mysql.DB

GetMysqlDB returns the mysql DB handler.

func GetRedis

func GetRedis() *redis.Client

GetRedis returns the redis client.

func GetUserDB

func GetUserDB() *mysql.CacheableDB

GetUserDB returns the User DB handler.

func Init

func Init(mysqlConfig *mysql.Config, mongoConfig *mongo.Config, redisConfig *redis.Config, _cacheExpire time.Duration) error

Init initializes the model packet.

func InsertUser

func InsertUser(_u *User, tx ...*sqlx.Tx) (int64, error)

InsertUser insert a User data into database. NOTE:

Primary key: 'id';
Without cache layer.

func ToArgsUser

func ToArgsUser(_u *User) *args.User

ToArgsUser converts to *args.User type.

func ToArgsUserSlice

func ToArgsUserSlice(a []*User) []*args.User

ToArgsUserSlice converts to []*args.User type.

func UpdateUserByName

func UpdateUserByName(_u *User, _updateFields []string, tx ...*sqlx.Tx) error

UpdateUserByName update the User data in database by 'name' unique key. NOTE:

With cache layer;
_updateFields' members must be db field style (snake format);
Automatic update 'updated_at' field;
Don't update the primary keys, 'created_at' key and 'deleted_ts' key;
Update all fields except the primary keys, 'name' unique key, 'created_at' key and 'deleted_ts' key, if _updateFields is empty.

func UpdateUserByPrimary

func UpdateUserByPrimary(_u *User, _updateFields []string, tx ...*sqlx.Tx) error

UpdateUserByPrimary update the User data in database by primary key. NOTE:

Primary key: 'id';
With cache layer;
_updateFields' members must be db field style (snake format);
Automatic update 'updated_at' field;
Don't update the primary keys, 'created_at' key and 'deleted_ts' key;
Update all fields except the primary keys, 'created_at' key and 'deleted_ts' key, if _updateFields is empty.

func UpsertUser

func UpsertUser(_u *User, _updateFields []string, tx ...*sqlx.Tx) (int64, error)

UpsertUser insert or update the User data by primary key. NOTE:

Primary key: 'id';
With cache layer;
Insert data if the primary key is specified;
Update data based on _updateFields if no primary key is specified;
_updateFields' members must be db field style (snake format);
Automatic update 'updated_at' field;
Don't update the primary keys, 'created_at' key and 'deleted_ts' key;
Update all fields except the primary keys, 'created_at' key and 'deleted_ts' key, if _updateFields is empty.

Types

type User

type User args.User

User user info

func GetUserByName

func GetUserByName(_name string) (*User, bool, error)

GetUserByName query a User data from database by 'name' unique key. NOTE:

With cache layer;
If @return bool=false error=nil, means the data is not exist.

func GetUserByPrimary

func GetUserByPrimary(_id int64) (*User, bool, error)

GetUserByPrimary query a User data from database by primary key. NOTE:

Primary key: 'id';
With cache layer;
If @return bool=false error=nil, means the data is not exist.

func GetUserByWhere

func GetUserByWhere(whereCond string, arg ...interface{}) (*User, bool, error)

GetUserByWhere query a User data from database by WHERE condition. NOTE:

Without cache layer;
If @return bool=false error=nil, means the data is not exist.

func SelectUserByWhere

func SelectUserByWhere(whereCond string, arg ...interface{}) ([]*User, error)

SelectUserByWhere query some User data from database by WHERE condition. NOTE:

Without cache layer.

func ToUser

func ToUser(_u *args.User) *User

ToUser converts to *User type.

func ToUserSlice

func ToUserSlice(a []*args.User) []*User

ToUserSlice converts to []*User type.

func (*User) TableName

func (*User) TableName() string

TableName implements 'github.com/xiaoenai/tp-micro/model'.Cacheable

Jump to

Keyboard shortcuts

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