We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
调用wuid生成id后,会自动关闭数据库连接,导致后续数据库操作无法继续执行 package tools import (
"database/sql" "github.com/astaxie/beego/orm" "github.com/edwingeng/wuid/mysql" _"github.com/go-sql-driver/mysql"
)
var newDB = func() (*sql.DB,bool,error){ db,_ := orm.GetDB() return db,true,nil }
var g = wuid.NewWUID("default", nil)
func NewId() (uint64){ g.LoadH28FromMysql(newDB, "wuid") return g.Next() }
调用代码:
func AddUser(u *User) (int64, error) { // db,err := orm.GetDB() //fmt.Println(err) o := orm.NewOrm() u.Id = 74837477878 for i:=0;i<100;i++ { fmt.Println(tools.NewId()) }
fmt.Println(u) return o.Insert(u)
}
插入操作无法继续执行, [ORM]2019/05/12 22:09:56 -[Queries/default] - [FAIL / db.Exec / 0.0ms] - [INSERT INTO sys_user (id, username, password, phone, email, name, avatar, salt, status, is_staff, last_login_time, login_error_times, remark, delete_flag, create_by, create_time, update_by, update_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)] - 74837477878, qingmumao, xxxxxxxx, 13332978703, huiii@qq.com, , , , `0`, `0`, `0`, `0`, , 0, 0, 0, 0, 0 - sql: database is closed
sys_user
id
username
password
phone
email
name
avatar
salt
status
is_staff
last_login_time
login_error_times
remark
delete_flag
create_by
create_time
update_by
update_time
74837477878
qingmumao
xxxxxxxx
13332978703
huiii@qq.com
,
, `0`, `0`, `0`, `0`,
0
The text was updated successfully, but these errors were encountered:
var newDB = func() (*sql.DB,bool,error){ db,_ := orm.GetDB() return db,true,nil
这样就可以了:return db, false, nil
return db, false, nil
Sorry, something went wrong.
No branches or pull requests
调用wuid生成id后,会自动关闭数据库连接,导致后续数据库操作无法继续执行
package tools
import (
)
var newDB = func() (*sql.DB,bool,error){
db,_ := orm.GetDB()
return db,true,nil
}
var g = wuid.NewWUID("default", nil)
func NewId() (uint64){
g.LoadH28FromMysql(newDB, "wuid")
return g.Next()
}
调用代码:
func AddUser(u *User) (int64, error) {
// db,err := orm.GetDB()
//fmt.Println(err)
o := orm.NewOrm()
u.Id = 74837477878
for i:=0;i<100;i++ {
fmt.Println(tools.NewId())
}
}
插入操作无法继续执行,
[ORM]2019/05/12 22:09:56 -[Queries/default] - [FAIL / db.Exec / 0.0ms] - [INSERT INTO
sys_user
(id
,username
,password
,phone
,email
,name
,avatar
,salt
,status
,is_staff
,last_login_time
,login_error_times
,remark
,delete_flag
,create_by
,create_time
,update_by
,update_time
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)] -74837477878
,qingmumao
,xxxxxxxx
,13332978703
,huiii@qq.com
,,
,, `0`, `0`, `0`, `0`,
,0
,0
,0
,0
,0
- sql: database is closedThe text was updated successfully, but these errors were encountered: