Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hsldymq/go-entity
https://github.com/hsldymq/go-entity
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/hsldymq/go-entity
- Owner: hsldymq
- Created: 2019-11-07T12:12:09.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-25T11:37:16.000Z (almost 5 years ago)
- Last Synced: 2024-06-20T16:48:35.892Z (5 months ago)
- Language: Go
- Size: 367 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 介绍
基于sqlx与goqu库,封装了实体对象的基本CRUD方法,除数据库读写外,还实现了自定义缓存机制,在数据库读写过程中,自动使用和更新缓存
样例代码见[example.go](./example/example.go)内
## Struct Tag
``` golang
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查询时会被忽略掉