完成dbpool改造
This commit is contained in:
parent
55494b3002
commit
420c029154
59
dbpool.go
59
dbpool.go
@ -70,7 +70,7 @@ func (this *dbPool) Select(
|
||||
params := []string{}
|
||||
sql := fmt.Sprintf("SELECT %s FROM %s WHERE 1=1 ", this.joinSelectFields(fields), tblName)
|
||||
this.joinWhere(&sql, ¶ms, whereKv)
|
||||
go this.internalQuery(dataSource, sql, params, cb)
|
||||
this.query(dataSource, sql, params, cb)
|
||||
}
|
||||
|
||||
func (this *dbPool) OrmSelect(
|
||||
@ -81,16 +81,16 @@ func (this *dbPool) OrmSelect(
|
||||
params := []string{}
|
||||
sql := fmt.Sprintf("SELECT * FROM %s WHERE 1=1 ", tblName)
|
||||
this.joinWhere(&sql, ¶ms, whereKv)
|
||||
go this.internalQuery(dataSource, sql, params, cb)
|
||||
this.query(dataSource, sql, params, cb)
|
||||
}
|
||||
|
||||
func (this *dbPool) RawQuery(dataSource string, sql string, params []string, cb QueryResultCb) {
|
||||
go this.internalQuery(dataSource, sql, params, cb)
|
||||
this.query(dataSource, sql, params, cb)
|
||||
}
|
||||
|
||||
func (this *dbPool) SelectCustomQuery(dataSource string, sql string, cb QueryResultCb) {
|
||||
params := []string{}
|
||||
go this.internalQuery(dataSource, sql, params, cb)
|
||||
this.query(dataSource, sql, params, cb)
|
||||
}
|
||||
|
||||
func (this *dbPool) SyncSelectCustomQuery(dataSource string, sql string, cb QueryResultCb) {
|
||||
@ -168,7 +168,7 @@ func (this *dbPool) SelectLike(
|
||||
this.joinWhereLike(&sql, ¶ms, likeWhere)
|
||||
sql = fmt.Sprintf("%s ORDER BY idx ASC LIMIT %d", sql, limit)
|
||||
|
||||
go this.internalQuery(dataSource, sql, params, cb)
|
||||
this.query(dataSource, sql, params, cb)
|
||||
}
|
||||
|
||||
func (this *dbPool) SelectOne(
|
||||
@ -180,7 +180,7 @@ func (this *dbPool) SelectOne(
|
||||
params := []string{}
|
||||
sql := fmt.Sprintf("SELECT %s FROM %s WHERE 1=1 ", this.joinSelectFields(fields), tblName)
|
||||
this.joinWhere(&sql, ¶ms, whereKv)
|
||||
go this.internalQueryOne(dataSource, sql, params, cb)
|
||||
this.queryOne(dataSource, sql, params, cb)
|
||||
}
|
||||
|
||||
func (this *dbPool) OrmSelectOne(
|
||||
@ -191,7 +191,7 @@ func (this *dbPool) OrmSelectOne(
|
||||
params := []string{}
|
||||
sql := fmt.Sprintf("SELECT * FROM %s WHERE 1=1 ", tblName)
|
||||
this.joinWhere(&sql, ¶ms, whereKv)
|
||||
go this.internalQueryOne(dataSource, sql, params, cb)
|
||||
this.queryOne(dataSource, sql, params, cb)
|
||||
}
|
||||
|
||||
func (this *dbPool) Update(
|
||||
@ -204,7 +204,7 @@ func (this *dbPool) Update(
|
||||
sql := "UPDATE `" + tblName + "` SET " + this.joinUpdateFields(fieldsKv, ¶ms) +
|
||||
" WHERE 1=1"
|
||||
this.joinWhere(&sql, ¶ms, whereKv)
|
||||
go this.internalExec(dataSource, sql, params, cb)
|
||||
this.exec(dataSource, sql, params, cb)
|
||||
}
|
||||
|
||||
func (this *dbPool) Insert(
|
||||
@ -214,17 +214,7 @@ func (this *dbPool) Insert(
|
||||
cb ExecResultCb) {
|
||||
params := []string{}
|
||||
sql := "INSERT INTO `" + tblName + "` " + this.joinInsertFields(fieldsKv, ¶ms)
|
||||
go this.internalExec(dataSource, sql, params, cb)
|
||||
}
|
||||
|
||||
func (this *dbPool) Replace(
|
||||
dataSource string,
|
||||
tblName string,
|
||||
fieldsKv [][]string,
|
||||
cb ExecResultCb) {
|
||||
params := []string{}
|
||||
sql := "REPLACE INTO `" + tblName + "` " + this.joinInsertFields(fieldsKv, ¶ms)
|
||||
go this.internalExec(dataSource, sql, params, cb)
|
||||
this.exec(dataSource, sql, params, cb)
|
||||
}
|
||||
|
||||
func (this *dbPool) Upsert(
|
||||
@ -268,7 +258,7 @@ func (this *dbPool) PageQuery(
|
||||
finalySql += " " + orderBy + " "
|
||||
}
|
||||
//GetSysLog().Info("finalySql:%s", finalySql)
|
||||
go this.internalQueryOne(
|
||||
this.queryOne(
|
||||
dataSource,
|
||||
fmt.Sprintf("SELECT COUNT(*) FROM (%s) as t", finalySql),
|
||||
params,
|
||||
@ -284,7 +274,7 @@ func (this *dbPool) PageQuery(
|
||||
}
|
||||
start := pagination.PerPage * (pagination.CurrentPage - 1)
|
||||
limit := pagination.PerPage
|
||||
go this.internalQuery(
|
||||
this.query(
|
||||
dataSource,
|
||||
fmt.Sprintf("%s LIMIT %d, %d", finalySql, start, limit),
|
||||
params,
|
||||
@ -524,3 +514,30 @@ func (this *dbPool) internalQueryOne(dataSource string, sql string, params []str
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (this* dbPool) query(dataSource string, sql string, params []string,
|
||||
cb QueryResultCb) {
|
||||
if this.style == GO_STYLE_DB {
|
||||
this.internalQuery(dataSource, sql, params, cb)
|
||||
} else {
|
||||
go this.internalQuery(dataSource, sql, params, cb)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *dbPool) exec(dataSource string, sql string, params []string,
|
||||
cb ExecResultCb) {
|
||||
if this.style == GO_STYLE_DB {
|
||||
this.internalExec(dataSource, sql, params, cb)
|
||||
} else {
|
||||
go this.internalExec(dataSource, sql, params, cb)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *dbPool) queryOne(dataSource string, sql string, params []string,
|
||||
cb QueryOneCb) {
|
||||
if this.style == GO_STYLE_DB {
|
||||
this.internalQueryOne(dataSource, sql, params, cb)
|
||||
} else {
|
||||
go this.internalQueryOne(dataSource, sql, params, cb)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user