model

package
v0.0.0-...-9d85d00 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	ColName string       // 数据库中的字段名
	GoName  string       // go struct 中的名字
	Type    reflect.Type // go 中的数据类型,转换成 reflect.Value 的时候,知道是什么类型,不然那没法转
	// Offset 相对于对象起始地址的字段偏移量
	// uintptr 这个类型的值,只是记录相对位置
	Offset uintptr
	Index  int // struct 中 第几个 字段数据
}

Field 字段相关的属性

type Model

type Model struct {
	// TableName 结构体对应的表名
	TableName string
	Fields    []*Field          // 由于 insert 等情况,需要 filed 有序,map 无法满足,所以冗余一个切边,存储顺序
	FieldMap  map[string]*Field // 结构体 属性名 attr name 为 key  ItemId
	ColumnMap map[string]*Field // DB column name 为 key    item_id
}

Model 结构体映射db后的结构

type Option

type Option func(model *Model) error

Option is a function type that modifies a Model.

func WithColumnName

func WithColumnName(field, columnName string) Option

ModelWithColumnName is a function that returns a Option function, which can be used to set the column name for a specific Field in a model.

func WithTableName

func WithTableName(tableName string) Option

WithTableName is a Option function that sets the table name for a Model.

type Registry

type Registry interface {
	Get(val any) (*Model, error)
	Register(val any, opts ...Option) (*Model, error)
}

func NewRegistry

func NewRegistry() Registry

type TableName

type TableName interface {
	TableName() string
}

TableName 用户实现这个接口来返回自定义的表名

Jump to

Keyboard shortcuts

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