I use Gorp to access the database, Gorp has a standard DbMap type, as well as a Transaction type for when you want to go back. Both types implement the SqlExecutor interface.
Therefore, I program against the SqlExecutor interface, so I can use transactions if I want without changing my code.
Then I initialize the Gorp DbMap or Transaction and pass it as a field property. The problem is that I need a pointer to a Gorp object, otherwise how can I roll back if I use Transaction , if the Gorp object is passed by value instead of a reference.
Then I get a message like
r.Gorp.Get undefined (type *gorp.SqlExecutor has no field or method Get)
when i try to use my code. How do I call methods?
The following is sample code.
package repositories import ( "github.com/coopernurse/gorp" ) type Repository struct { Gorp *gorp.SqlExecutor
go
Lee
source share