Forráskód Böngészése

feat(sqlx): support for custom Acceptable function (#3405)

chen quan 1 éve
szülő
commit
b71453985c
2 módosított fájl, 9 hozzáadás és 3 törlés
  1. 1 3
      core/stores/sqlx/mysql.go
  2. 8 0
      core/stores/sqlx/sqlconn.go

+ 1 - 3
core/stores/sqlx/mysql.go

@@ -32,7 +32,5 @@ func mysqlAcceptable(err error) bool {
 }
 
 func withMysqlAcceptable() SqlOption {
-	return func(conn *commonSqlConn) {
-		conn.accept = mysqlAcceptable
-	}
+	return WithAcceptable(mysqlAcceptable)
 }

+ 8 - 0
core/stores/sqlx/sqlconn.go

@@ -399,3 +399,11 @@ func (s statement) QueryRowsPartialCtx(ctx context.Context, v any, args ...any)
 		return unmarshalRows(v, rows, false)
 	}, s.query, args...)
 }
+
+// WithAcceptable returns a SqlOption that setting the acceptable function.
+// acceptable is the func to check if the error can be accepted.
+func WithAcceptable(acceptable func(err error) bool) SqlOption {
+	return func(conn *commonSqlConn) {
+		conn.accept = acceptable
+	}
+}