dotsql
dotsql copied to clipboard
Transaction support?
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?
Not sure if transactions should concern dotsql. You can start a transaction with begin and the call queries loaded from dotsql.
closing this, but if you think I'm missing something, feel free to reopen it
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 how would you do it? Could you provide pseudo-code to better understand your idea?
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 I understand better now, it shouldn't be hard to implement right?
Yeah, of course - just originally I had strong feeling that such simple thing is already implemented here somewhere :)
Feel free to open a PR, I'll be happy to review it
Why was ExecTx removed form the v1.0.0 release? I was utilising this.
Which version / commit hash are you using?