avito-tech / go-transaction-manager

Transaction manager for GoLang
MIT License
231 stars 14 forks source link

May be it's better to use generics? #111

Closed F0rzend closed 2 months ago

F0rzend commented 2 months ago

Your transaction contains method that returns "raw" tx (sql.Tx, sqlx.Tx, etc.) as interface{} (any): https://github.com/avito-tech/go-transaction-manager/blob/main/trm/transaction.go#L44

It seems to me that the API will be more convenient if the transaction is made generalized (generic).

Something like:

type Transaction[T any] interface {
    // Raw returns the real transaction sql.Tx, sqlx.Tx or another.
    Raw() T
    // Commit the trm.Transaction.
    // Commit should be used only inside Manager.
    Commit() error
    // Rollback the trm.Transaction.
    // Rollback should be used only inside Manager.
    Rollback() error
}

With this solution, you don't have to transform the interface to a specific transaction every time in your code.

What do you think about this? If you give approve, I could do it.

maranqz commented 2 months ago

Hi, sounds great, but will your generics solution be compatible with go1.17 and earlier?

F0rzend commented 2 months ago

Hi, sounds great, but will your generics solution be compatible with go1.17 and earlier?

I don't think so... I understand you

maranqz commented 2 months ago

Okay, I close the issue but we can back for this after 1-2 years because it's good idea.