From b71453985c1dd9cfdc55fbb6e1f1cb81cb45f248 Mon Sep 17 00:00:00 2001 From: chen quan Date: Mon, 10 Jul 2023 09:16:45 +0800 Subject: [PATCH] feat(sqlx): support for custom Acceptable function (#3405) --- core/stores/sqlx/mysql.go | 4 +--- core/stores/sqlx/sqlconn.go | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/stores/sqlx/mysql.go b/core/stores/sqlx/mysql.go index 9f474f55..6f0f731d 100644 --- a/core/stores/sqlx/mysql.go +++ b/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) } diff --git a/core/stores/sqlx/sqlconn.go b/core/stores/sqlx/sqlconn.go index e1297251..fdb9d2be 100644 --- a/core/stores/sqlx/sqlconn.go +++ b/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 + } +}