-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Transaction Level #472
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
Comments
Bear in mind, |
No need to do anything special. Solved: |
Actually, I had to reopen it. I am using mysql-go driver's connection pooling. How can I guarantee that |
Why don't you use |
https://dev.mysql.com/doc/refman/5.6/en/set-transaction.html
The documentation states it has to be called BEFORE starting transaction. |
Have you read readme? |
If you want to change variable only for one connection, possible solution is:
|
I believe that system variable changes the default transaction level for everything, whereas I only want to change the transaction level for 1 particular query. Using I've known of that alternative driver but been hesitant to use it because it doesn't have anywhere near active user base (hence very few updates). |
@arnehormann @julienschmidt Any suggestions? |
The only solution I can think of is fork this package, and rename the id that That way for this particular query, I can call: A messy hack unfortunately. |
I meant having two |
Hmmm. I'm quite confused by your suggestion. If I create a standard one and a specialized one.
|
No. Each |
I had no idea. Thanks @methane I'll test it out. |
If you really need it per-connection, a hackish solution might be to use Otherwise settings can only be made per connection pool / |
@julienschmidt Can you clarify what you mean by use Is it this?
The documentation states |
I don't know the gorm syntax, but it should be something like: tx := gorm.Begin()
if err := tx.Exec("ROLLBACK").Error; err != nil { ... } // Abort
if err := tx.Exec("START TRANSACTION [options]").Error; err != nil { ... } // Start new transaction with custom options
// Do whatever you wanted to do in the transaction
tx.Commit() // Again, I don't know the syntax, but finish the transaction as usual. However this is a quite nasty workaround and causes some extra overhead (logging, extra network round-trips etc). If possible, I would use the DSN parameter instead. |
thanks @julienschmidt @methane |
You can try this:
but this will be of *sql.Tx type |
I was wondering what the best way was to set the transaction level and have it revert back to default after the transaction - particularly in case of a panic:
I'm currently doing this:
The text was updated successfully, but these errors were encountered: