-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
feat: add tx methods to IDB (#587) #591
Conversation
db.go
Outdated
|
||
// BeginTx will save a point in the running transaction. | ||
func (tx Tx) BeginTx(ctx context.Context, _ *sql.TxOptions) (Tx, error) { | ||
uid, err := uuid.NewRandom() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not add a dependency on uuid
just to generate a random string.
b := make([]byte, 16)
rand.Read(b)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used crypto/rand
but I think also math/rand
is an option as it is safe for concurrent usage (for this usage pseudo random is fine). Maybe we can check which is faster but that will be one word change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, crypto/rand is fine I guess.
This looks pretty good. Could you add a test for savepoints in https://github.com/uptrace/bun/blob/master/internal/dbtest/db_test.go#L273? |
2332441
to
46eb321
Compare
How are these cases handled when different sql should be generated? |
0d2e3c1
to
a29a1b4
Compare
Excellent, thank you 👍 |
Updated
IDB
interface with 2 methodsWhen creating a savepoint the
opts
are ignored.Currently the transaction will not use the name but we can store something like
TX_{random}
same format as for savepoint. Then we can also emit the name with the hooks so logging libraries can show if a query is being executed as part of a transaction or savepoint.