https://github.com/xfali/neve-database
neve的数据库扩展组件,用于集成数据库相关操作。
https://github.com/xfali/neve-database
database neve orm
Last synced: 6 months ago
JSON representation
neve的数据库扩展组件,用于集成数据库相关操作。
- Host: GitHub
- URL: https://github.com/xfali/neve-database
- Owner: xfali
- License: apache-2.0
- Created: 2020-09-16T14:44:39.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-24T01:33:58.000Z (about 4 years ago)
- Last Synced: 2024-09-27T09:09:36.086Z (almost 2 years ago)
- Topics: database, neve, orm
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# neve-database
neve-database是neve的数据库扩展组件,用于集成数据库相关操作。
内置ORM工具为[gobatis](https://github.com/xfali/gobatis)
## 安装
```
go get github.com/xfali/neve-database
```
## 使用
### 1. neve集成(依赖[neve-core](https://github.com/xfali/neve-core))
```
app := neve.NewFileConfigApplication("assets/config-example.yaml")
app.RegisterBean(gobatiseve.NewProcessor())
//Register other beans...
//app.RegisterBean(test.NewMyTest())
app.Run()
```
### 2. 配置
在config-example.yaml中配置示例如下:
```
neve:
dataSources:
testDB:
driverName: "mysql"
driverInfo: "test:123@tcp(127.0.0.1:3306)/test?timeout=10s&readTimeout=15s&charset=uft8"
maxConn: 1000
maxIdleConn: 500
connMaxLifetime: 15
gobatis:
mapper:
dir: "assets/mappers"
log:
level: DEBUG
pagehelper:
enable: true
```
* 【neve.dataSources.testDB】为注入的DataSource名称,请根据实际项目进行修改,通过inject注入名称为testDB可直接获得SessionManager(testDB下为数据库相关配置)。
(SessionManager用法参考[gobatis](https://github.com/xfali/gobatis)及[gobatis-cmd](https://github.com/xfali/gobatis-cmd))
```
type MyTest struct {
SessMgr *gobatis.SessionManager `inject:"testDB"`
}
func (t *MyTest) test() {
sess := t.SessMgr.NewSession()
var ret []test
sess.Select("select * from test").Param().Result(&ret)
}
```
* 【gobatis.mapper.dir】配置扫描mapper文件的路径
* 【gobatis.mapper.log】配置日志级别,默认为info
* 【gobatis.mapper.pagehelper】配置是否启用自动分页(集成分页插件)