Categorygithub.com/hsldymq/go-entity
repositorypackage
0.0.3
Repository: https://github.com/hsldymq/go-entity.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

介绍

基于sqlx与goqu库,封装了实体对象的基本CRUD方法,除数据库读写外,还实现了自定义缓存机制,在数据库读写过程中,自动使用和更新缓存

样例代码见example.go

Struct Tag

type User struct {
	ID       int64 `db:"user_id" entity:"primaryKey,autoIncrement"`
	CreateAt int64 `db:"create_at" entity:"refuseUpdate,returningInsert"`
	UpdateAt int64 `db:"update_at"`
	Other    bool  `db:"other" entity:"deprecated"`
}

每个字段属性,必须声明db tag,否则不会作为字段对待

实体配置,写在entity tag内

可用tag:

  • primaryKey 主键字段, 每个实体对象必须至少要声明一个
  • refuseUpdate 不允许更新,UPDATE时会被忽略,当设置了primaryKeyautoIncrementreturningUpdate时,这个配置会自动生效
  • autoIncrement 自增长主键,构造INSERT时此字段会被忽略
  • returningInsert insert时,这个字段会被放到RETURNING子句内返回,无论使用的数据库是否支持RETURNING
  • returningUpdate update时,这个字段会被放到RETURNING子句内返回,无论使用的数据库是否支持RETURNING
  • returning 等于同时使用returningInsertreturningUpdate
  • deprecated 标记为废弃,构造CRUD查询时会被忽略掉