Documentation ¶
Index ¶
- Constants
- func GetDB() *gorm.DB
- func InitDB()
- type Repository
- func (rep *Repository) Create(value interface{}) *gorm.DB
- func (rep *Repository) Delete(value interface{}) *gorm.DB
- func (rep *Repository) Exec(sql string, values ...interface{}) *gorm.DB
- func (rep *Repository) Find(out interface{}, where ...interface{}) *gorm.DB
- func (rep *Repository) First(out interface{}, where ...interface{}) *gorm.DB
- func (rep *Repository) Preload(column string, conditions ...interface{}) *gorm.DB
- func (rep *Repository) Raw(sql string, values ...interface{}) *gorm.DB
- func (rep *Repository) Save(value interface{}) *gorm.DB
- func (rep *Repository) Scopes(funcs ...func(*gorm.DB) *gorm.DB) *gorm.DB
- func (rep *Repository) Transaction(fc func(tx *Repository) error) (err error)
- func (rep *Repository) Update(value interface{}) *gorm.DB
- func (rep *Repository) Where(query interface{}, args ...interface{}) *gorm.DB
Constants ¶
const ( // SQLITE represents SQLite3 SQLITE = "sqlite3" // POSTGRES represents PostgreSQL POSTGRES = "postgres" // MYSQL represents MySQL MYSQL = "mysql" )
Variables ¶
This section is empty.
Functions ¶
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) 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) Scopes ¶
Scopes pass current database connection to arguments `func(*DB) *DB`, which could be used to add conditions dynamically
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.