orm

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NowFunc = func() time.Time {
	return time.Now()
}

NowFunc returns current time, this function is exported in order to be able to give the flexibility to the developer to customize it according to their needs, e.g:

gorm.NowFunc = func() time.Time {
  return time.Now().UTC()
}

Functions

func ToDBName

func ToDBName(name string) string

ToDBName convert string to db name

Types

type DBService

type DBService interface {
	GetDB() *gorm.DB
}

DBService DB Service interface

type InstanceNotFoundError

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

InstanceNotFoundError xxx

func (*InstanceNotFoundError) Error

func (p *InstanceNotFoundError) Error() string

type ModelDescriptor

type ModelDescriptor struct {
	Type     interface{}
	New      func() interface{}
	NewSlice func() interface{}
}

ModelDescriptor db model descriptor

type ModelRegistry

type ModelRegistry interface {
	Put(name string, model *ModelDescriptor)
	Get(name string) *ModelDescriptor
	Models() <-chan *ModelDescriptor
}

ModelRegistry Register all orm models

type ModelRegistryImpl

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

ModelRegistryImpl model registry impelement struct

func (*ModelRegistryImpl) Get

Get get db model by model struct name

func (*ModelRegistryImpl) Models

func (p *ModelRegistryImpl) Models() <-chan *ModelDescriptor

Models models channels

func (*ModelRegistryImpl) Put

func (p *ModelRegistryImpl) Put(name string, model *ModelDescriptor)

Put registry db model

type Repository

type Repository interface {
	Get(class string, id interface{}, ass string) (interface{}, error)
	List(class string, selectFields []string, where string, whereValues []interface{}, order string, page int, pageSize int) (map[string]interface{}, error)
	Create(class string, data interface{}) error
	Remove(className string, id interface{}) (interface{}, error)
	Update(className string, data interface{}) error
	GetDB() *gorm.DB
}

Repository manage all objects in db

type SQLExpr

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

SQLExpr expression

func Expr

func Expr(expression string, args ...interface{}) *SQLExpr

Expr generate raw SQL expression, for example:

DB.Model(&product).Update("price", gorm.Expr("price * ? + ?", 2, 100))

type Service

type Service struct {
	DB            DBService     `inject:"DB"`
	ModelRegistry ModelRegistry `inject:"DB"`
}

Service orm service struct

func (*Service) Create

func (p *Service) Create(class string, data interface{}) error

Create create data

func (*Service) Get

func (p *Service) Get(class string, id interface{}, ass string) (interface{}, error)

Get query db model with where conditions

func (*Service) GetDB

func (p *Service) GetDB() *gorm.DB

GetDB return db conn

func (*Service) List

func (p *Service) List(class string, selectFields []string, where string, whereValues []interface{}, order string, page int, pageSize int) (map[string]interface{}, error)

List query db model list with where conditions

func (*Service) Remove

func (p *Service) Remove(className string, id interface{}) (interface{}, error)

Remove remove db data

func (*Service) Update

func (p *Service) Update(className string, data interface{}) error

Update update db data

Directories

Path Synopsis
dialects

Jump to

Keyboard shortcuts

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