gorm

package
v0.0.0-...-7d43bac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2017 License: MIT Imports: 3 Imported by: 4

Documentation

Overview

Package gorm provides support for relational database access using GORM (Object-Relational Mapping)

Index

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

func NewDbContext(dialect string, connStr string) (*DbContext, error)

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

func (c *DbContext) IsInTransaction() bool

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 Entity

type Entity struct {
	rdbms.Entity
	gorm.Model
}

Entity represents object stored in relational database.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL