You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What do you think about adding Context support? My suggestions are:
1- Setting it connection-wide like db.WithContext(context.Context) and each runner interface check if ctx is nil or not and call suitable sql func.
2- For each runner interface add context param with naming suffix ...Ctx like db.SelectFrom("books").DoCtx(&books, ctx). This one will need every runner and Transaction methods to be duplicated for Context parameter with Ctx suffix but more Go-like.
3- Without changing any interface, altering current runners with contex'ed ones internally, and get/set context with a function. For ex: db.SelectFrom("books").Do() internally will run ExecTx with ctx.Background.
If you can check and give directions I can add a PR for this according to your suggestions or better you can add this to godb.
Erkan.
The text was updated successfully, but these errors were encountered:
The way is to add DoCtx functions, but the context has to be the first argument, it's coherent with the stdlib. It's also explicit, I like the python mantra "explicit is better than implicit", and it matches well with Go.
Thanks, looking forward for your implementation. Especially I needed this to use CockroachDB(uses pq's client)'s transactions which can retry. To use godb's transaction directly it needs to implement ExecContext as in here.
So, active transaction from db.CurrentTx() can be used in ExcuteInTx for retrying transactions for CockroachDB.
Please also add ExecContext method to DB for this to work. Otherwise I had to add a wrapper transactor on db.
Hi Sam,
What do you think about adding
Context
support? My suggestions are:1- Setting it connection-wide like
db.WithContext(context.Context)
and each runner interface check if ctx isnil
or not and call suitablesql
func.2- For each runner interface add context param with naming suffix
...Ctx
likedb.SelectFrom("books").DoCtx(&books, ctx)
. This one will need every runner and Transaction methods to be duplicated forContext
parameter withCtx
suffix but moreGo
-like.3- Without changing any interface, altering current runners with contex'ed ones internally, and get/set context with a function. For ex:
db.SelectFrom("books").Do()
internally will runExecTx
withctx.Background
.If you can check and give directions I can add a PR for this according to your suggestions or better you can add this to
godb
.Erkan.
The text was updated successfully, but these errors were encountered: