orm

package
v0.0.0-...-c9aeb8f Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMustNotNil         = errors.New("data model must not be nil")
	ErrMustBeStruct       = errors.New("data value must be type struct")
	ErrFieldNotFound      = errors.New("field not found")
	ErrTagValueNotFound   = errors.New("tag value not found")
	ErrNotIdentifyFkField = errors.New("not identify fk field on tag")
	ErrRegistryNotFound   = errors.New("registry not found")
)
View Source
var GlobalRegistry = map[string]Registry{
	(uid{}).TypeName():                         uid{},
	(str("")).TypeName():                       str(""),
	(zerouid{}).TypeName():                     zerouid{},
	(integer(0)).TypeName():                    (integer(0)),
	(integer64(0)).TypeName():                  (integer64(0)),
	(floater32(float32(0))).TypeName():         (floater32(0)),
	(floater64(float64(0))).TypeName():         (floater64(0)),
	(timestamp(helper.Timestamp{})).TypeName(): timestamp(helper.Timestamp{}),
	(date(helper.Date{})).TypeName():           date(helper.Date{}),
	(zeroString(zeroString{})).TypeName():      zeroString(zero.String{}),
	(zeroInt(zero.Int{})).TypeName():           zeroInt(zero.Int{}),
	(zeroFloat(zero.Float{})).TypeName():       zeroFloat(zero.Float{}),
	(zeroBool(zero.Bool{})).TypeName():         zeroBool(zero.Bool{}),
	(boolean(true)).TypeName():                 (boolean(true)),
}
View Source
var PAGINATE_COLUMN_NAME = "total_row"
View Source
var TABLE_FIELD_NAME = "TableName"
View Source
var TAGNAME = "db"
View Source
var TAG_FK = "fk"
View Source
var TAG_PK = "pk"
View Source
var TAG_TYPE = "type"

Functions

func GetSelector

func GetSelector(models interface{}) string

Types

type IterationTypes

type IterationTypes string
const (
	ITERATION_TYPE_LIST     IterationTypes = "array_list"
	ITERATION_TYPE_HASH_MAP IterationTypes = "hash_map"
)

type Mapper

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

func Orm

func Orm(model interface{}, rows *sqlx.Rows, options MapperOption) (Mapper, error)

func OrmContext

func OrmContext(ctx context.Context, model interface{}, rows *sqlx.Rows, options MapperOption) (Mapper, error)

func (Mapper) GetColumns

func (m Mapper) GetColumns() []*sql.ColumnType

func (Mapper) GetData

func (m Mapper) GetData() interface{}

func (Mapper) GetIterationHashMap

func (m Mapper) GetIterationHashMap() *hashmap.Map

get(id) -> *hashmap.Map

func (Mapper) GetIterationList

func (m Mapper) GetIterationList() []*arraylist.List

iter -> []interface{}

func (Mapper) GetPaginateTotal

func (m Mapper) GetPaginateTotal() int

func (Mapper) GetRowCount

func (m Mapper) GetRowCount() int

type MapperOption

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

func NewMapperOption

func NewMapperOption() MapperOption

func (MapperOption) SetDisableBinding

func (m MapperOption) SetDisableBinding() MapperOption

func (MapperOption) SetIterationHashMapWithColumns

func (m MapperOption) SetIterationHashMapWithColumns(pkColumnName []string, storeColumns []string) MapperOption

pkColumnName is column from query to get pk if data is null will be skip that rows | storeOnlyColumn is optional choose store column example []string{"orders.id"}, nil

func (MapperOption) SetIterationHashMapWithModel

func (m MapperOption) SetIterationHashMapWithModel(model interface{}, storeColumns []string) MapperOption

model is column from query to get pk if data is null will be skip that rows | storeOnlyColumn is optional choose store column example new(Order), nil

func (MapperOption) SetIterationList

func (m MapperOption) SetIterationList() MapperOption

Copy rows.Next() -> ArrayList

func (MapperOption) SetOverridePKField

func (m MapperOption) SetOverridePKField(fields ...MapperOptionPkField) MapperOption

type MapperOptionPkField

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

func NewMapperOptionPKField

func NewMapperOptionPKField(model interface{}, fieldname []string) MapperOptionPkField

type Registry

type Registry interface {
	TypeName() string
	RegisterPkId(val interface{}) string
	Bind(field *structs.Field, val interface{}) error
	Equal(x interface{}, y interface{}) bool
}

Jump to

Keyboard shortcuts

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