Skip to content
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

Gorp new sql context support #344

Open
soniabhishek opened this issue Feb 24, 2017 · 10 comments
Open

Gorp new sql context support #344

soniabhishek opened this issue Feb 24, 2017 · 10 comments

Comments

@soniabhishek
Copy link

Hey when are we expecting to support context for gorp and if no one else is working can I give it a try, It seems easy to workaround.

@soniabhishek soniabhishek changed the title Gorp support for new sql context support Gorp new sql context support Feb 24, 2017
@srenatus
Copy link

@soniabhishek Heya -- any updates on this? I think it would be nice to have that.

@nelsam
Copy link
Member

nelsam commented Aug 30, 2017

d'oh, this is probably something I should have commented on. There are no current plans, but feel free! If you don't get to it, I'll keep it in mind for the rearch I've been working through.

@bryanpaluch
Copy link

I'm also interested in this as I've just started using tracing libraries. If I had some guidance on the desired API, I may be able to take a swing at it.

@MatthewDolan
Copy link
Contributor

Looks like it might be pretty simple to pipe through.

What are you thinking in terms of the change to the API?

(1) Add new FooContext methods that copy the existing methods.

type SqlExecutor interface {
	Get(i interface{}, keys ...interface{}) (interface{}, error)
	GetContext(ctx context.Context, i interface{}, keys ...interface{}) (interface{}, error)
	
	Insert(list ...interface{}) error
	InsertContext(ctx context.Context, list ...interface{}) error
	
	Update(list ...interface{}) (int64, error)
	UpdateContext(ctx context.Context, list ...interface{}) (int64, error)
	
	Delete(list ...interface{}) (int64, error)
	DeleteContext(ctx context.Context, list ...interface{}) (int64, error)
	
	Exec(query string, args ...interface{}) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	
	...
}

(2) Add a WithContext(ctx) which attaches the context to the dbMap.

type SqlExecutor interface {
	WithContext(ctx context.Context) SqlExecutor

	Get(i interface{}, keys ...interface{}) (interface{}, error)
	Insert(list ...interface{}) error
	Update(list ...interface{}) (int64, error)
	Delete(list ...interface{}) (int64, error)
	Exec(query string, args ...interface{}) (sql.Result, error)
	...
}

(3) I guess it's possible to do something backward incompatible that forces context, but I assume that's not desirable.

(1) is probably most similar to how go changed the underlying sql.Db, but it add the most new methods.

@nelsam
Copy link
Member

nelsam commented Aug 31, 2017 via email

@soniabhishek
Copy link
Author

@srenatus @nelsam I would like to work over this, just wanted to confirm that above-mentioned approach (i.e. 2) is what needs to be implemented

@nelsam
Copy link
Member

nelsam commented Aug 31, 2017

@soniabhishek yeah, the WithContext method on SqlExecutor is the desired approach. @MatthewDolan is working on a solution in #352.

@MatthewDolan
Copy link
Contributor

This is merged.

@nelsam would it be possible to get a new release (2.1.0) associated with this?

@nelsam
Copy link
Member

nelsam commented Sep 19, 2017

Sure thing, I'll do that a little bit later today (ideally)

@sinni800
Copy link

sinni800 commented Oct 3, 2018

So, WithContext does return a new Gorp with a context, but the SQLs won't be executed with that ctx apparently?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants