Documentation ¶
Index ¶
- Constants
- type BW
- func (this *BW) CheckIndex(uPtr interface{}) *BW
- func (this *BW) Count(uPtr interface{}) (int, error)
- func (this *BW) Delete(uPtr interface{}, field []string) (num int, err error)
- func (this *BW) DeleteAll(uPtr interface{}) (num int, err error)
- func (this *BW) Driver(driver int) *BW
- func (this *BW) Error() error
- func (this *BW) FindAll(u interface{}, aPtr interface{}) (err error)
- func (this *BW) FindAllWithSort(uPtr interface{}, aArray interface{}, sortField []string) (err error)
- func (this *BW) FindOne(uPtr interface{}) (err error)
- func (this *BW) First(uPtr interface{}) (err error)
- func (this *BW) Map(u interface{}, name string) *BW
- func (this *BW) Save(u interface{}) (err error)
- func (this *BW) SaveAll(uArray interface{}) (err error)
- func (this *BW) Update(uPtr interface{}, field []string) (num int, err error)
- func (this *BW) Version() string
- type BWDriver
- type BWMongo
- type BWMongoConf
- type BWPostgresConf
- type BWPostgresql
Constants ¶
const ( //DRIVER_MONGO Mongo驱动 DRIVER_MONGO = iota //DRIVER_PQ Postgresql驱动 DRIVER_PQ )
const ( BW_MONGO_ENDPOINT = "BW_ENV_MONGO_ENDPOINT" BW_MONGO_USER = "BW_ENV_MONGO_USER" BW_MONGO_PASSWD = "BW_ENV_MONGO_PASSWD" BW_MONGO_DB = "BW_ENV_MONGO_DB" BW_PQ_ENDPOINT = "BW_ENV_PQ_ENDPOINT" BW_PQ_USER = "BW_ENV_PQ_USER" BW_PQ_PASSWD = "BW_ENV_PQ_PASSWD" BW_PQ_DB = "BW_ENV_PQ_DB" )
const (
BW_VERSION = "0.1.0-Alpha"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BW ¶
type BW struct {
// contains filtered or unexported fields
}
var Widow *BW
##### Example
```go
//BWidow Init bw := bwidow.GetWidow() err := bw.Driver(bwidow.DRIVER_MONGO) if err != nil { logrus.WithFields(logrus.Fields{"Init Error": err}).Errorln(ModuleName) return } //Setting Model And Table bw.Map(User{}, "devex_user_copy") u := User{ CurrentAuthority: "BW", } //Delete All Matched Record num, err := bw.Delete(&u, []string{"currentauthority"}) if err != nil { logrus.Errorln(err) return } logrus.WithFields(logrus.Fields{"change": num}).Info(ModuleName)
```
func (*BW) CheckIndex ¶
func (*BW) Delete ¶
Delete 删除命中的所有数据 uPtr 供定位记录的数据 field 用于筛选的字段
##### Example
```go
u := User{ CurrentAuthority: "BW", } //Delete All Matched Record num, err := bw.Delete(&u, []string{"currentauthority"}) if err != nil { logrus.Errorln(err) return }
```
func (*BW) Driver ¶
Driver 设置使用的数据库类型 当前支持的类型为: DRIVER_MONGO - Mongo
##### Example
```go
err := bw.Driver(bwidow.DRIVER_MONGO) if err != nil { logrus.WithFields(logrus.Fields{"Init Error": err}).Errorln(ModuleName) return }
```
func (*BW) FindAll ¶
FindAll 通过u的字段查询所有数据 BW会解析u的字段,然后将所有非空字段作为查询条件进行查询,同时将查询到的数据赋值给a u 查找记录使用的数据 a必须为array/slice类型的指针
##### Example
``` go
u := User{ CurrentAuthority: "dev", } var allUser []User err = bw.FindAll(u, &allUser) if err != nil { logrus.Error(err) return } logrus.WithFields(logrus.Fields{"FindAll": allUser}).Info(ModuleName)
```
func (*BW) FindAllWithSort ¶
func (this *BW) FindAllWithSort(uPtr interface{}, aArray interface{}, sortField []string) (err error)
FindAllWithSort 通过u的字段查询所有数据并且按照给定的条件进行排序 BW会解析u的字段,然后将所有非空字段作为查询条件进行查询,同时将查询到的数据赋值给a u 查找记录使用的数据 a 必须为array/slice类型的指针 sortField 需要排序的字段数组
##### Example
```go
u := User{ CurrentAuthority: "dev", } var allUser []User err = bw.FindAllWithSort(u, &allUser, []string{"+name"}) if err != nil { logrus.Error(err) return } logrus.WithFields(logrus.Fields{"FindAllWithSort": allUser}).Info(ModuleName)
```
func (*BW) FindOne ¶
FindOne 通过u的字段查询数据 BW会解析u的字段,然后将所有非空字段作为查询条件进行查询,同时将查询到的数据赋值给u u必须为指针
##### Example
```go
u := User{ Name: "ztao8607@gmail.com", } logrus.WithFields(logrus.Fields{"Query": u}).Info(ModuleName) err = bw.FindOne(&p) if err != nil { logrus.Error(err) return }
```
func (*BW) First ¶
First 查询与u绑定的表中的首条记录 u 数据结构体指针
#### Example
```go
u := User{} err = bw.First(&u) if err != nil { logrus.Error(err) return } logrus.WithFields(logrus.Fields{"First": u}).Info(ModuleName)
```
func (*BW) Map ¶
Map 将u与数据表进行绑定 u 数据结构体 name 数据表名
##### Example
```go
bw.Map(User{}, "devex_user_copy")
```
func (*BW) Save ¶
Save 插入单条数据
##### Example
```go
u := User{ ID: bson.NewObjectId(), Name: "fromBW@gmail.com", } err = bw.Save(u) if err != nil { logrus.Errorln(err) return }
```
func (*BW) SaveAll ¶
SaveAll 插入一批次的数据 支持数组内存在不同数据类型 u 为数组
##### Example
```go
al := []User{ { ID: bson.NewObjectId(), Name: "fromBW1@gmail.com", }, { ID: bson.NewObjectId(), Name: "fromBW2@gmail.com", }, { ID: bson.NewObjectId(), Name: "fromBW3@gmail.com", }, } err = bw.SaveAll(al) if err != nil { logrus.Errorln(err) return }
```
func (*BW) Update ¶
Update 更新命中的所有数据. uPtr 供定位记录的数据 field 用于筛选的字段
##### Example
```go
u := User{ Name: "fromBW2@gmail.com", CurrentAuthority: "BW", } num, err := bw.Update(&u, []string{"name"}) if err != nil { logrus.Errorln(err) return } logrus.WithFields(logrus.Fields{"change": num}).Info(ModuleName)
```
type BWMongo ¶
type BWMongo struct {
// contains filtered or unexported fields
}
func (*BWMongo) DriverInit ¶
type BWMongoConf ¶
type BWPostgresConf ¶
type BWPostgresql ¶
type BWPostgresql struct {
// contains filtered or unexported fields
}
func (*BWPostgresql) Check ¶
func (this *BWPostgresql) Check() error
func (*BWPostgresql) DriverInit ¶
func (this *BWPostgresql) DriverInit() error
func (*BWPostgresql) Map ¶
func (this *BWPostgresql) Map(u interface{}, name string)