-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
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
flexible the cacheconn #3995
base: master
Are you sure you want to change the base?
flexible the cacheconn #3995
Conversation
This change is more flexible.We can use the sqlc.cacheConn to obtain the equal effect of sqlx.SqlConn without changing sqlc.cacheConn
@@ -88,6 +88,10 @@ func (cc CachedConn) GetCacheCtx(ctx context.Context, key string, v any) error { | |||
return cc.cache.GetCtx(ctx, key, v) | |||
} | |||
|
|||
func(cc CachedConn)GetRawConnNoCache()sqlx.SqlConn{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When NewConn is used, the conn is passed in from the outside. It is of little significance to provide RawConn here. If you really want to get it, you can save it by the business itself, or explain the value of providing the new method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your explanation is reasonable,but this situation need be token care .In the most of environment, i can only declare a cacheConn variable in my servercontext obviously,but according to the real environment,i must to use the conn which skip the cache level in some condition query,because the series query will hit rarely. To make easier operation,i must expose this sqlx.SqlConn to directly use the NonCache query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep the implementation simple, I think it's more straightforward that you keep the reference on your own.
This change is more flexible.We can use the sqlc.cacheConn to obtain the equal effect of sqlx.SqlConn without changing sqlc.cacheConn