model

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindDivideArgByFields

func BindDivideArgByFields(_d *DivideArg, _fields ...string) (bool, error)

BindDivideArgByFields query the DivideArg data from database by field keys, and bind it to _d. NOTE:

With cache layer;
_fields' members should be snake format;
Query by the primary key field if fields is empty;
If @return bool=false error=nil, means the data is not exist.

func BindDivideArgByWhere

func BindDivideArgByWhere(_d *DivideArg, whereNamedCond string) (bool, error)

BindDivideArgByWhere query the DivideArg data from database by WHERE condition(whereNamedCond), and bind it to _d. NOTE:

With cache layer;
If @return bool=false error=nil, means the data is not exist;
whereNamedCond e.g. 'id=:id AND created_at>1520000000'.

func BindUserByFields

func BindUserByFields(_u *User, _fields ...string) (bool, error)

BindUserByFields query the User data from database by field keys, and bind it to _u. NOTE:

With cache layer;
_fields' members should be snake format;
Query by the primary key field if fields is empty;
If @return bool=false error=nil, means the data is not exist.

func BindUserByWhere

func BindUserByWhere(_u *User, whereNamedCond string) (bool, error)

BindUserByWhere query the User data from database by WHERE condition(whereNamedCond), and bind it to _u. NOTE:

With cache layer;
If @return bool=false error=nil, means the data is not exist;
whereNamedCond e.g. 'id=:id AND created_at>1520000000'.

func CountDivideArgByWhere

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

CountDivideArgByWhere count DivideArg data number from database by WHERE condition. NOTE:

Without cache layer.

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 DeleteDivideArgByPrimary

func DeleteDivideArgByPrimary(id int64, tx ...*sqlx.Tx) error

DeleteDivideArgByPrimary delete a DivideArg data in database by primary key. NOTE:

With cache layer.

func DeleteUserByPrimary

func DeleteUserByPrimary(id int64, tx ...*sqlx.Tx) error

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

With cache layer.

func GetDB

func GetDB() *mysql.DB

GetDB returns the DB handler.

func GetDivideArgDB

func GetDivideArgDB() *mysql.CacheableDB

GetDivideArgDB returns the DivideArg 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(dbConfig mysql.Config, redisConfig redis.Config) error

Init initializes the model packet.

func InsertDivideArg

func InsertDivideArg(_d *DivideArg, tx ...*sqlx.Tx) (int64, error)

InsertDivideArg insert a DivideArg data into database. NOTE:

Without cache layer.

func InsertUser

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

InsertUser insert a User data into database. NOTE:

Without cache layer.

func UpdateDivideArgByPrimary

func UpdateDivideArgByPrimary(_d *DivideArg, _updateFields []string, tx ...*sqlx.Tx) error

UpdateDivideArgByPrimary update the DivideArg data in database by primary key. NOTE:

With cache layer;
_updateFields' members must be snake format;
Automatic update updated_at field;
Don't update the primary key and the created_at key;
Update all fields except the primary key and the created_at 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:

With cache layer;
_updateFields' members must be snake format;
Automatic update updated_at field;
Don't update the primary key and the created_at key;
Update all fields except the primary key and the created_at key if _updateFields is empty.

func UpsertDivideArg

func UpsertDivideArg(_d *DivideArg, _updateFields []string, tx ...*sqlx.Tx) (int64, error)

UpsertDivideArg insert or update the DivideArg data by primary key. NOTE:

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 snake format;
Automatic update updated_at field;
Don't update the primary key and the created_at key;
Update all fields except the primary key and the created_at 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:

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 snake format;
Automatic update updated_at field;
Don't update the primary key and the created_at key;
Update all fields except the primary key and the created_at key if _updateFields is empty.

Types

type DivideArg

type DivideArg struct {
	Id int64 `json:"id"`
	// dividend
	A float64 `json:"a"`
	// divisor
	B         float64 `json:"b" param:"<range: 0.01:100000>"`
	CreatedAt int64   `json:"created_at"`
	UpdatedAt int64   `json:"updated_at"`
}

DivideArg divide api arg

func GetDivideArgByPrimary

func GetDivideArgByPrimary(id int64) (*DivideArg, bool, error)

GetDivideArgByPrimary query a DivideArg data from database by primary key. NOTE:

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

func GetDivideArgByWhere

func GetDivideArgByWhere(whereCond string, arg ...interface{}) (*DivideArg, bool, error)

GetDivideArgByWhere query a DivideArg data from database by WHERE condition. NOTE:

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

func SelectDivideArgByWhere

func SelectDivideArgByWhere(whereCond string, arg ...interface{}) ([]*DivideArg, error)

SelectDivideArgByWhere query some DivideArg data from database by WHERE condition. NOTE:

Without cache layer.

func (*DivideArg) TableName

func (*DivideArg) TableName() string

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

type User

type User struct {
	Id        int64  `json:"id"`
	Name      string `json:"name"`
	Age       int32  `json:"age"`
	CreatedAt int64  `json:"created_at"`
	UpdatedAt int64  `json:"updated_at"`
}

User user info

func GetUserByPrimary

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

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

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 (*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