mirror of
https://github.com/astaxie/beego.git
synced 2025-02-16 22:47:02 +00:00
update “modification hardcode
This commit is contained in:
parent
3583ad8cc0
commit
e0e888ab8f
16
orm/db.go
16
orm/db.go
@ -491,23 +491,23 @@ func (d *dbBase) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, names []s
|
|||||||
// InsertOrUpdate a row
|
// InsertOrUpdate a row
|
||||||
// If your primary key or unique column conflict will update
|
// If your primary key or unique column conflict will update
|
||||||
// If no will insert
|
// If no will insert
|
||||||
func (d *dbBase) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Location, dn string, args ...string) (int64, error) {
|
func (d *dbBase) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Location, driver DriverType, args ...string) (int64, error) {
|
||||||
iouStr := ""
|
iouStr := ""
|
||||||
mysql := "mysql"
|
mysql := DRMySQL
|
||||||
postgres := "postgres"
|
postgres := DRPostgres
|
||||||
argsMap := map[string]string{}
|
argsMap := map[string]string{}
|
||||||
args0 := ""
|
args0 := ""
|
||||||
if dn == mysql {
|
if driver == mysql {
|
||||||
iouStr = "ON DUPLICATE KEY UPDATE"
|
iouStr = "ON DUPLICATE KEY UPDATE"
|
||||||
} else if dn == postgres {
|
} else if driver == postgres {
|
||||||
if len(args) == 0 || (len(strings.Split(args0, "=")) != 1) {
|
if len(args) == 0 || (len(strings.Split(args0, "=")) != 1) {
|
||||||
return 0, fmt.Errorf("`%s` use insert or update must have a conflict column arg in first", dn)
|
return 0, fmt.Errorf("`%s` use insert or update must have a conflict column arg in first", driver)
|
||||||
} else {
|
} else {
|
||||||
args0 = strings.ToLower(args[0])
|
args0 = strings.ToLower(args[0])
|
||||||
iouStr = fmt.Sprintf("ON CONFLICT (%s) DO UPDATE SET", args0)
|
iouStr = fmt.Sprintf("ON CONFLICT (%s) DO UPDATE SET", args0)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return 0, fmt.Errorf("`%s` nonsupport insert or update in beego", dn)
|
return 0, fmt.Errorf("`%s` nonsupport insert or update in beego", driver)
|
||||||
}
|
}
|
||||||
//Get on the key-value pairs
|
//Get on the key-value pairs
|
||||||
for _, v := range args {
|
for _, v := range args {
|
||||||
@ -539,7 +539,7 @@ func (d *dbBase) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Value, t
|
|||||||
conflitValue = values[i]
|
conflitValue = values[i]
|
||||||
}
|
}
|
||||||
if valueStr != "" {
|
if valueStr != "" {
|
||||||
switch dn {
|
switch driver {
|
||||||
case mysql:
|
case mysql:
|
||||||
updates[i] = v + "=" + valueStr
|
updates[i] = v + "=" + valueStr
|
||||||
break
|
break
|
||||||
|
@ -212,7 +212,7 @@ func (o *orm) InsertMulti(bulk int, mds interface{}) (int64, error) {
|
|||||||
// InsertOrUpdate data to database
|
// InsertOrUpdate data to database
|
||||||
func (o *orm) InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64, error) {
|
func (o *orm) InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64, error) {
|
||||||
mi, ind := o.getMiInd(md, true)
|
mi, ind := o.getMiInd(md, true)
|
||||||
id, err := o.alias.DbBaser.InsertOrUpdate(o.db, mi, ind, o.alias.TZ, o.alias.DriverName, colConflitAndArgs...)
|
id, err := o.alias.DbBaser.InsertOrUpdate(o.db, mi, ind, o.alias.TZ, o.alias.Driver, colConflitAndArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return id, err
|
return id, err
|
||||||
}
|
}
|
||||||
|
@ -396,7 +396,7 @@ type txEnder interface {
|
|||||||
type dbBaser interface {
|
type dbBaser interface {
|
||||||
Read(dbQuerier, *modelInfo, reflect.Value, *time.Location, []string) error
|
Read(dbQuerier, *modelInfo, reflect.Value, *time.Location, []string) error
|
||||||
Insert(dbQuerier, *modelInfo, reflect.Value, *time.Location) (int64, error)
|
Insert(dbQuerier, *modelInfo, reflect.Value, *time.Location) (int64, error)
|
||||||
InsertOrUpdate(dbQuerier, *modelInfo, reflect.Value, *time.Location, string, ...string) (int64, error)
|
InsertOrUpdate(dbQuerier, *modelInfo, reflect.Value, *time.Location, DriverType, ...string) (int64, error)
|
||||||
InsertMulti(dbQuerier, *modelInfo, reflect.Value, int, *time.Location) (int64, error)
|
InsertMulti(dbQuerier, *modelInfo, reflect.Value, int, *time.Location) (int64, error)
|
||||||
InsertValue(dbQuerier, *modelInfo, bool, []string, []interface{}) (int64, error)
|
InsertValue(dbQuerier, *modelInfo, bool, []string, []interface{}) (int64, error)
|
||||||
InsertStmt(stmtQuerier, *modelInfo, reflect.Value, *time.Location) (int64, error)
|
InsertStmt(stmtQuerier, *modelInfo, reflect.Value, *time.Location) (int64, error)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user