Documentation ¶
Overview ¶
Package gorm provides support for relational database access using GORM (Object-Relational Mapping)
Index ¶
- type DbContext
- type DbTransaction
- type Entity
- type RepositoryBase
- func (r *RepositoryBase) Context() rdbms.DbContext
- func (r *RepositoryBase) Delete(entity interface{}, where ...interface{}) error
- func (r *RepositoryBase) Find(out interface{}, where ...interface{}) error
- func (r *RepositoryBase) First(out interface{}, where ...interface{}) error
- func (r *RepositoryBase) ResetContext()
- func (r *RepositoryBase) Save(entity interface{}) error
- func (r *RepositoryBase) SetContext(c rdbms.DbContext)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DbContext ¶
type DbContext struct { DB *gorm.DB // raw gorm database object // contains filtered or unexported fields }
DbContext represents relational database access mechanism using GORM library.
func NewDbContext ¶
NewDbContext creates DbContext instance with specified SQL dialect and connection string. It should be create once per goroutine and reused. It opens database connection which should be closed in defer function using Dispose method.
func (*DbContext) BeginTransaction ¶
func (c *DbContext) BeginTransaction() rdbms.DbTransaction
BeginTransaction starts new database transaction. Panics if DbContext is already in transaction.
func (*DbContext) Dispose ¶
func (c *DbContext) Dispose()
Dispose closes database context and cleans up DbContext instance.
func (*DbContext) IsInTransaction ¶
IsInTransaction indicates if DbContext has started DbTransaction.
type DbTransaction ¶
type DbTransaction struct {
// contains filtered or unexported fields
}
DbTransaction represents transaction in relational database using GORM library.
func (*DbTransaction) Commit ¶
func (t *DbTransaction) Commit() error
Commit commits database transaction.
func (*DbTransaction) Context ¶
func (t *DbTransaction) Context() rdbms.DbContext
Context returns DbContext associated with DbTransaction.
func (*DbTransaction) Rollback ¶
func (t *DbTransaction) Rollback() error
Rollback rollbacks database transaction.
type RepositoryBase ¶
type RepositoryBase struct {
// contains filtered or unexported fields
}
RepositoryBase represents base Repository implementation used to create specific repositories like UserRepository etc. (using GORM library)
func (*RepositoryBase) Context ¶
func (r *RepositoryBase) Context() rdbms.DbContext
Context returns current database context associated with Repository.
func (*RepositoryBase) Delete ¶
func (r *RepositoryBase) Delete(entity interface{}, where ...interface{}) error
Delete removes specified entity or all entities of out type which match where criteria.
func (*RepositoryBase) Find ¶
func (r *RepositoryBase) Find(out interface{}, where ...interface{}) error
Find retrives entities of out type which match where criteria.
func (*RepositoryBase) First ¶
func (r *RepositoryBase) First(out interface{}, where ...interface{}) error
First retrives first entity from relational database which matches where criteria.
func (*RepositoryBase) ResetContext ¶
func (r *RepositoryBase) ResetContext()
ResetContext restores last saved Repository database context.
func (*RepositoryBase) Save ¶
func (r *RepositoryBase) Save(entity interface{}) error
Save stores enity in relational database.
func (*RepositoryBase) SetContext ¶
func (r *RepositoryBase) SetContext(c rdbms.DbContext)
SetContext sets current database context for Repository.