# 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时会被忽略,当设置了primaryKey
或autoIncrement
或returningUpdate
时,这个配置会自动生效autoIncrement
自增长主键,构造INSERT时此字段会被忽略returningInsert
insert时,这个字段会被放到RETURNING
子句内返回,无论使用的数据库是否支持RETURNING
returningUpdate
update时,这个字段会被放到RETURNING
子句内返回,无论使用的数据库是否支持RETURNING
returning
等于同时使用returningInsert
和returningUpdate
deprecated
标记为废弃,构造CRUD查询时会被忽略掉
# Packages
No description provided by the author
# Functions
Delete 删除entity.
DeleteCache 删除entity缓存.
Insert 插入新entity.
Load 从数据库载入entity.
NewMetadata 构造实体对象元数据.
SaveCache 保存entity缓存.
Update 更新entity.
# Constants
EventAfterDelete after delete entity.
EventAfterInsert after insert entity.
EventAfterUpdate after update entity.
EventBeforeDelete before delete entity.
EventBeforeInsert before insert entity.
EventBeforeUpdate before update entity.
EventUnknown 未定义事件.
# Variables
DefaultCacher 默认缓存存储.
DefaultEnDecoder 默认的缓存数据编码解码器.
DefaultExpiration 默认缓存时间.
ErrConflict 发生了数据冲突.
ReadTimeout 读取entity数据的默认超时时间.
WriteTimeout 写入entity数据的默认超时时间.
# Structs
CacheOption 缓存参数.
Column 字段信息.
JSONEnDecoder 默认缓存数据编码解码器.
Metadata 元数据.
# Type aliases
Event 存储事件.