repository

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2020 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// SQLITE represents SQLite3
	SQLITE = "sqlite3"
	// POSTGRES represents PostgreSQL
	POSTGRES = "postgres"
	// MYSQL represents MySQL
	MYSQL = "mysql"
)

Variables

This section is empty.

Functions

func GetDB

func GetDB() *gorm.DB

GetDB returns the object of gorm.DB.

func InitDB

func InitDB()

InitDB initialize a database connection.

Types

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository defines a repository for access the database.

func GetRepository

func GetRepository() *Repository

GetRepository returns the object of repository.

func (*Repository) Create

func (rep *Repository) Create(value interface{}) *gorm.DB

Create insert the value into database.

func (*Repository) Delete

func (rep *Repository) Delete(value interface{}) *gorm.DB

Delete delete value match given conditions.

func (*Repository) Exec

func (rep *Repository) Exec(sql string, values ...interface{}) *gorm.DB

Exec exec given SQL using by gorm.DB.

func (*Repository) Find

func (rep *Repository) Find(out interface{}, where ...interface{}) *gorm.DB

Find find records that match given conditions.

func (*Repository) First

func (rep *Repository) First(out interface{}, where ...interface{}) *gorm.DB

First returns first record that match given conditions, order by primary key.

func (*Repository) Model added in v1.4.0

func (rep *Repository) Model(value interface{}) *gorm.DB

Model specify the model you would like to run db operations

func (*Repository) Preload

func (rep *Repository) Preload(column string, conditions ...interface{}) *gorm.DB

Preload preload associations with given conditions.

func (*Repository) Raw

func (rep *Repository) Raw(sql string, values ...interface{}) *gorm.DB

Raw returns the record that executed the given SQL using gorm.DB.

func (*Repository) Save

func (rep *Repository) Save(value interface{}) *gorm.DB

Save update value in database, if the value doesn't have primary key, will insert it.

func (*Repository) ScanRows added in v1.4.0

func (rep *Repository) ScanRows(rows *sql.Rows, result interface{}) error

ScanRows scan `*sql.Rows` to give struct

func (*Repository) Scopes

func (rep *Repository) Scopes(funcs ...func(*gorm.DB) *gorm.DB) *gorm.DB

Scopes pass current database connection to arguments `func(*DB) *DB`, which could be used to add conditions dynamically

func (*Repository) Select added in v1.4.0

func (rep *Repository) Select(query interface{}, args ...interface{}) *gorm.DB

Select specify fields that you want to retrieve from database when querying, by default, will select all fields;

func (*Repository) Transaction

func (rep *Repository) Transaction(fc func(tx *Repository) error) (err error)

Transaction start a transaction as a block. If it is failed, will rollback and return error. If it is sccuessed, will commit. ref: https://github.com/jinzhu/gorm/blob/master/main.go#L533

func (*Repository) Update

func (rep *Repository) Update(value interface{}) *gorm.DB

Update update value in database

func (*Repository) Where

func (rep *Repository) Where(query interface{}, args ...interface{}) *gorm.DB

Where returns a new relation.

Jump to

Keyboard shortcuts

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