dal

package
v0.0.0-...-3b8bf74 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyConfiguration

func ApplyConfiguration(db *gorm.DB, c *Configuration) *gorm.DB

ApplyConfiguration applies the GORM configuration to database client.

func ApplyOrderClauses

func ApplyOrderClauses(db *gorm.DB, ocs ...OrderClause) *gorm.DB

ApplyOrderClauses create new db pointer with order clauses applied.

func ApplyPreloadObjs

func ApplyPreloadObjs(db *gorm.DB, preloadObjs ...string) *gorm.DB

ApplyPreloadObjs applies preload objects.

func ApplyScopes

func ApplyScopes(db *gorm.DB, scopes ...Scope) *gorm.DB

ApplyScopes apply scopes to gorm DB interactions.

func ApplySelectFields

func ApplySelectFields(db *gorm.DB, selectFields ...string) *gorm.DB

ApplySelectFields create new db pointer with select fields applied.

func ApplyWhereClauses

func ApplyWhereClauses(db *gorm.DB, wcs ...WhereClause) *gorm.DB

ApplyWhereClauses create new db pointer with where clauses applied.

func BeginTransaction

func BeginTransaction(parentTransaction *gorm.DB, f func(*gorm.DB) error) error

BeginTransaction starts a database transaction.

func SanitizePointer

func SanitizePointer(p interface{}) (interface{}, error)

SanitizePointer checks whether or not the parameter passed in fits to GORM requirements for results (must be a pointer to a struct or slice).

See https://play.golang.org/p/kB6SPuOepwV for test cases.

func SliceToMap

func SliceToMap(src, dest interface{}) error

SliceToMap converts slice of models to map of id to its respective model.

func SliceToUUIDs

func SliceToUUIDs(src, dest interface{}) error

SliceToUUIDs converts slice of models to slice of uuids.

Types

type BaseDAL

type BaseDAL struct {
	DB *gorm.DB
}

BaseDAL encapsulates the basic operations of data access layers.

func GetInstance

func GetInstance() *BaseDAL

GetInstance returns an instance of BaseDAL. If no instance is created yet then create one.

func (*BaseDAL) AppendAssociation

func (d *BaseDAL) AppendAssociation(
	model interface{},
	associationName string,
	associations interface{},
	c *Configuration,
) error

AppendAssociation adds associations for a particular model to the database. @param model = *models @param associations = []models

func (*BaseDAL) ClearAssociation

func (d *BaseDAL) ClearAssociation(
	model interface{},
	associationName string,
	c *Configuration,
) error

ClearAssociation removes all reference between source and association. @param model = *models

func (*BaseDAL) CountAssociation

func (d *BaseDAL) CountAssociation(
	model interface{},
	associationName string,
	c *Configuration,
) (int64, error)

CountAssociation fetches the association count of a particular model from the database. @param model = *models

func (*BaseDAL) Create

func (d *BaseDAL) Create(result interface{}, c *Configuration) error

Create inserts a record to the database with the model passed in. @param result = *models

func (*BaseDAL) DeleteAssociation

func (d *BaseDAL) DeleteAssociation(
	model interface{},
	associationName string,
	associations interface{},
	c *Configuration,
) error

DeleteAssociation deletes associations for a particular model to the database. @param model = *models @param associations = []models

func (*BaseDAL) First

func (d *BaseDAL) First(result interface{}, c *Configuration) error

First fetches the first record matching the criteria set in configuration.

func (*BaseDAL) Get

func (d *BaseDAL) Get(result interface{}, id uint, c *Configuration) error

Get fetches the first record matching the UUID and the criteria set in configuration. @param result = *models

func (*BaseDAL) GetAssociation

func (d *BaseDAL) GetAssociation(
	result interface{},
	model interface{},
	associationName string,
	c *Configuration,
) error

GetAssociation fetches the association of a particular model from the database. @param result = []models @param model = *models

func (*BaseDAL) Remove

func (d *BaseDAL) Remove(result interface{}, c *Configuration) error

Remove deletes a record in the database with the model passed in. @param result = *models

func (*BaseDAL) Update

func (d *BaseDAL) Update(result interface{}, c *Configuration) error

Update updates a record in the database with the model passed in. @param result = *models

func (*BaseDAL) UpdateFields

func (d *BaseDAL) UpdateFields(
	result interface{}, fields map[string]interface{}, c *Configuration) error

UpdateFields updates a record in the database with specified fields to update. @param result = *models @param fields = map[string]interface{}

func (*BaseDAL) Where

func (d *BaseDAL) Where(result interface{}, c *Configuration) error

Where fetches records matching the criteria set in configuration. @param result = *models

type Configuration

type Configuration struct {
	Transaction  *gorm.DB
	PreloadObjs  []string
	SelectFields []string
	WhereClauses []WhereClause
	OrderClauses []OrderClause
	Scopes       []Scope
	Unscoped     bool
}

Configuration GORM configuration to apply before final call.

type OrderClause

type OrderClause struct {
	Query interface{}
}

OrderClause used for DAL statements requiring order clauses.

type Scope

type Scope struct {
	Name string
	F    func(*gorm.DB) *gorm.DB
}

Scope GORM interaction scope.

type WhereClause

type WhereClause struct {
	Query interface{}
	Args  []interface{}
}

WhereClause used for DAL statements requiring where clauses.

Jump to

Keyboard shortcuts

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