saOrm

package
v0.0.0-...-b2602dc Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 19 Imported by: 3

README

saOrm

介绍
  • 支持的tag标签:

    index -> 单字段索引,生成参考建表语句会建立索引 oss -> oss文件,入库、出库前域名、oss type处理; varchar(32) -> 字符最大长度为32 < <= < >= >< -> 大小校验,如果是数组,则校验数组长度;字符串,校验rune长度 required enum(1:激活,2:废弃) in(1,2) in(ms,md) int8 int int64 string varchar(128) char(23) index created updated decimal(1,5) comment default phone updated -> 时间,更新的时候会自动取当前时间,仅支持时间或者时间指针对象 created -> 时间,创建的时候会自动设置当前时间,仅支持时间或者时间指针对象

  • tag示例:

    type:"varchar(32);created;comment:状态 2-正常 1-取消了;default:12;phone;required;in(ms,md);comment:字段;<=23;phone;required;default;err:缺少参数"

  • GenTblSql:

    生成数据库操作SQL,如果表存在则生成建表语句;如果表存在,则生成修改表结构语句

  • DB:

    通过反射,根据标签校验数据格式,及oss相关处理

    支持大小校验、oss处理

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlterTbl

func AlterTbl(db *DB, tblName string, obj interface{})

AlterTbl 修改数据库SQL

func CreateTbl

func CreateTbl(obj interface{})

func FromDb

func FromDb(obj interface{}) error

func GenTblSql

func GenTblSql(db *DB, values ...interface{})

GenTblSql 生成修改数据库表结构语句 数据库不存在则生成建表语句,不存在则查看差异,生成差异代码; 建议如果返回值为true,则panic,因为数据库表结构跟model定义不一致; values项必须为指针

func ToDB

func ToDB(obj interface{}) error

Types

type BaseModel

type BaseModel struct {
	Id        int64      `json:"id"`
	CreatedAt *time.Time `orm:"datetime;created" json:"createdAt"`
}

type BaseModelWithDelete

type BaseModelWithDelete struct {
	BaseModel
	DeletedAt *time.Time `orm:"datetime;default:null" json:"deletedAt"`
}

type Column

type Column struct {
	ColumnName    string `json:"column_name"`
	ColumnType    string `json:"column_type"`
	IsNullable    string `json:"is_nullable"`
	ColumnDefault string `json:"column_default_int"`
	ColumnComment string `json:"column_comment"`
}

type CompressIds

type CompressIds []int64

func (*CompressIds) Scan

func (m *CompressIds) Scan(value interface{}) error

func (CompressIds) Value

func (m CompressIds) Value() (driver.Value, error)

type Conf

type Conf struct {
	MaxIdleConns int
	MaxOpenConns int
	LogMode      int //0-默认 1-Silent 2-Error 3-Warn 4-Info
}

type DB

type DB struct {
	*gorm.DB
}

func Open

func Open(dsn string, conf Conf) *DB

func (*DB) Insert

func (m *DB) Insert(obj interface{}) (tx *gorm.DB)

func (*DB) IsError

func (o *DB) IsError(err error) bool

func (*DB) Session

func (m *DB) Session() *gorm.DB

Session @Description: 每次调用都会生成一个新的会话,为了避免全局会话影响

type Dic

type Dic map[string]interface{}

func (*Dic) Scan

func (m *Dic) Scan(value interface{}) error

func (Dic) Value

func (m Dic) Value() (driver.Value, error)

type Ids

type Ids []int64

func (*Ids) Scan

func (m *Ids) Scan(value interface{}) error

func (Ids) Value

func (m Ids) Value() (driver.Value, error)

type ImgTxt

type ImgTxt struct {
	Ary     []ImgTxtItem `json:"ary,omitempty" form:"ary"`
	RichTxt string       `json:"richTxt,omitempty" form:"richTxt"`
	Txt     string       `json:"txt,omitempty" form:"txt"`
	Path    string       `json:"path,omitempty" form:"path"`
}

func (*ImgTxt) Get

func (m *ImgTxt) Get(oss saOss.SaOss) (err error)

func (*ImgTxt) Save

func (m *ImgTxt) Save(oss saOss.SaOss, path string) (err error)

func (*ImgTxt) Scan

func (m *ImgTxt) Scan(value interface{}) error

func (ImgTxt) Value

func (m ImgTxt) Value() (driver.Value, error)

type ImgTxtItem

type ImgTxtItem struct {
	Title string `json:"title,omitempty" form:"title"`
	Desc  string `json:"desc,omitempty" form:"desc"`
	Img   string `json:"img,omitempty" form:"img"`
}

type Ints

type Ints []int

func (*Ints) Scan

func (m *Ints) Scan(value interface{}) error

func (Ints) Value

func (m Ints) Value() (driver.Value, error)

type LiPrice

type LiPrice float32

func (*LiPrice) Scan

func (m *LiPrice) Scan(value interface{}) error

func (LiPrice) Value

func (m LiPrice) Value() (driver.Value, error)

type Price

type Price float32

func (*Price) Scan

func (m *Price) Scan(value interface{}) error

func (Price) Value

func (m Price) Value() (driver.Value, error)

type PriceDigit4

type PriceDigit4 float32

func (*PriceDigit4) Scan

func (m *PriceDigit4) Scan(value interface{}) error

func (PriceDigit4) Value

func (m PriceDigit4) Value() (driver.Value, error)

type QueryAry

type QueryAry interface {
	Len() int
}

type Rate

type Rate float32

func (*Rate) Scan

func (m *Rate) Scan(value interface{}) error

func (Rate) Value

func (m Rate) Value() (driver.Value, error)

type RichTxt

type RichTxt struct {
	Type    RichTxtType `json:"type,omitempty"`
	Md5     string      `json:"md5,omitempty"`
	InOss   bool        `json:"inOss,omitempty"`
	Content string      `json:"content,omitempty"`
}

RichTxt 数据库存储格式:json或者内容字符,当内容小于200时,直接存入数据库;否则存入OSS,content存储路径 不管存储在哪里,MD5都是原始content的MD5 Deprecated

func (*RichTxt) Get

func (m *RichTxt) Get(oss saOss.SaOss) (txt string, err error)

func (*RichTxt) Save

func (m *RichTxt) Save(oss saOss.SaOss, t RichTxtType, txt string, path string) (err error)

func (*RichTxt) Scan

func (m *RichTxt) Scan(value interface{}) error

func (RichTxt) Value

func (m RichTxt) Value() (driver.Value, error)

type RichTxtType

type RichTxtType int
const (
	RichTxtTypeTxt  RichTxtType = iota //文本
	RichTxtTypeJson RichTxtType = 1    //json
)

type RtItem

type RtItem struct {
	Title string `json:"title"`
	Desc  string `json:"desc"`
	Img   string `json:"img"`
}

RtItem json时对象格式应该是这样的,也可以自行扩展

type Set

type Set struct {
	Obj              interface{}
	Options          string //设置:controller;ms;tbl;doc; 默认全部
	DB               string //数据库全局变量
	PK               string //主键名
	AddImgRootFun    string
	DeleteImgRootFun string
}

type StringAry

type StringAry []string

func (StringAry) IsSameImages

func (m StringAry) IsSameImages(n StringAry) bool

func (*StringAry) Scan

func (m *StringAry) Scan(value interface{}) error

func (StringAry) TrimSpace

func (m StringAry) TrimSpace() StringAry

func (StringAry) Value

func (m StringAry) Value() (driver.Value, error)

type Time

type Time string

func AfterLongTiem

func AfterLongTiem() *Time

func BeforeLongTiem

func BeforeLongTiem() *Time

func Now

func Now() *Time

func TimeFromStr

func TimeFromStr(str string) *Time

func TimeFromUnix

func TimeFromUnix(t int64) *Time

func (*Time) Format

func (m *Time) Format(format string) *Time

func (*Time) IsZero

func (m *Time) IsZero() bool

func (*Time) Scan

func (m *Time) Scan(value interface{}) error

func (*Time) SetNow

func (m *Time) SetNow()

func (*Time) String

func (m *Time) String() string

func (*Time) T

func (m *Time) T() time.Time

func (Time) Value

func (m Time) Value() (driver.Value, error)

type Weight

type Weight float32

func (*Weight) Scan

func (m *Weight) Scan(value interface{}) error

func (Weight) Value

func (m Weight) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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