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

Transaction support? #10

Open
dstroot opened this issue Jan 31, 2016 · 10 comments
Open

Transaction support? #10

dstroot opened this issue Jan 31, 2016 · 10 comments

Comments

@dstroot
Copy link

dstroot commented Jan 31, 2016

I need to update several tables at once and would like that to be in one transaction. Can't seem to figure out how dotsql and transactions can play together nicely and noticed you have no examples either. Thoughts?

@qustavo
Copy link
Owner

qustavo commented Jan 31, 2016

Not sure if transactions should concern dotsql. You can start a transaction with begin and the call queries loaded from dotsql.

@qustavo qustavo closed this as completed Feb 10, 2016
@qustavo
Copy link
Owner

qustavo commented Feb 11, 2016

closing this, but if you think I'm missing something, feel free to reopen it

@erthalion
Copy link

Not sure if transactions should concern dotsql. You can start a transaction with begin and the call queries loaded from dotsql.

Maybe I'm missing something, but in this case you need to get a raw query and execute it manually, which is probably less convenient, that just have a wrapper around Tx in the library itself.

@qustavo
Copy link
Owner

qustavo commented Feb 27, 2019

@erthalion how would you do it? Could you provide pseudo-code to better understand your idea?

@qustavo qustavo reopened this Feb 27, 2019
@erthalion
Copy link

For now I'm doing something like that in my code, is that what you're asking?:

func (d DotSql) ExecTx(tx *sql.Tx, name string, args ...interface{}) (sql.Result, error) {
	query, err := d.lookupQuery(name)
	if err != nil {
		return nil, err
	}

	return tx.Exec(query, args...)
}

@qustavo
Copy link
Owner

qustavo commented Feb 27, 2019

@erthalion I understand better now, it shouldn't be hard to implement right?

@erthalion
Copy link

Yeah, of course - just originally I had strong feeling that such simple thing is already implemented here somewhere :)

@qustavo
Copy link
Owner

qustavo commented Feb 27, 2019

Feel free to open a PR, I'll be happy to review it

@AJBrindley
Copy link

Why was ExecTx removed form the v1.0.0 release? I was utilising this.

@qustavo
Copy link
Owner

qustavo commented Nov 12, 2020

Which version / commit hash are you using?

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

4 participants