You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
572 B
30 lines
572 B
package sqlx |
|
|
|
import "github.com/go-sql-driver/mysql" |
|
|
|
const ( |
|
mysqlDriverName = "mysql" |
|
duplicateEntryCode uint16 = 1062 |
|
) |
|
|
|
func NewMysql(datasource string, opts ...SqlOption) SqlConn { |
|
opts = append(opts, func(conn *commonSqlConn) { |
|
conn.accept = func(err error) bool { |
|
if err == nil { |
|
return true |
|
} |
|
myerr, ok := err.(*mysql.MySQLError) |
|
if !ok { |
|
return false |
|
} |
|
switch myerr.Number { |
|
case duplicateEntryCode: |
|
return true |
|
default: |
|
return false |
|
} |
|
} |
|
}) |
|
|
|
return NewSqlConn(mysqlDriverName, datasource, opts...) |
|
}
|
|
|