dotsql icon indicating copy to clipboard operation
dotsql copied to clipboard

Transaction support?

Open dstroot opened this issue 9 years ago • 10 comments

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?

dstroot avatar Jan 31 '16 14:01 dstroot

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

qustavo avatar Jan 31 '16 22:01 qustavo

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

qustavo avatar Feb 11 '16 14:02 qustavo

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.

erthalion avatar Feb 27 '19 12:02 erthalion

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

qustavo avatar Feb 27 '19 12:02 qustavo

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...)
}

erthalion avatar Feb 27 '19 12:02 erthalion

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

qustavo avatar Feb 27 '19 12:02 qustavo

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

erthalion avatar Feb 27 '19 12:02 erthalion

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

qustavo avatar Feb 27 '19 12:02 qustavo

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

AJBrindley avatar Nov 09 '20 17:11 AJBrindley

Which version / commit hash are you using?

qustavo avatar Nov 12 '20 10:11 qustavo