orm

package
v0.0.0-...-e3f3f79 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTimestring = errors.New("msf.db: invalid time string")

ErrInvalidTimestring invalid time string

Functions

func GenOrm

func GenOrm(ormFile string)

GenOrm 生成orm文件

func GetTableFieldNames

func GetTableFieldNames(args []*ColumnInfo) string

GetTableFieldNames 根据ColumnInfo 数组返回根据逗号拼接的字段

Types

type Bit

type Bit bool

Bit type

func (*Bit) Scan

func (bit *Bit) Scan(value interface{}) error

Scan implements the Scanner interface. bit 类型,转化为uint8类型,值转为string处理为 \x00" or "\x01"

func (Bit) Value

func (bit Bit) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type ColumnInfo

type ColumnInfo struct {
	Field   string
	Type    string
	Null    string
	Key     string
	Default *string
	Extra   string

	AutoIncrement bool
	Unique        bool
	GoType        string
}

ColumnInfo table column info

type DBInfo

type DBInfo struct {
	*gorm.DB
}

DBInfo db链接信息

func (*DBInfo) Begin

func (dbInfo *DBInfo) Begin(trans *Transaction, objects ...TransactionObject) (*Transaction, error)

Begin 开启事物

type GormLogger

type GormLogger struct {
}

GormLogger gorm logger

func (*GormLogger) Print

func (logger *GormLogger) Print(values ...interface{})

Print 输出sql执行信息

type NullBit

type NullBit struct {
	Bit   Bit
	Valid bool
}

NullBit null bit

func NewNullBit

func NewNullBit(v interface{}) (n NullBit)

NewNullBit new

func (NullBit) MarshalJSON

func (n NullBit) MarshalJSON() ([]byte, error)

MarshalJSON correctly serializes a NullString to JSON

func (*NullBit) Scan

func (n *NullBit) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullBit) UnmarshalJSON

func (n *NullBit) UnmarshalJSON(b []byte) error

UnmarshalJSON correctly deserializes a NullString from JSON

func (NullBit) Value

func (n NullBit) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullBool

type NullBool struct {
	sql.NullBool
}

NullBool is a type that can be null or a bool

func NewNullBool

func NewNullBool(v interface{}) (n NullBool)

NewNullBool new

func (NullBool) MarshalJSON

func (n NullBool) MarshalJSON() ([]byte, error)

MarshalJSON correctly serializes a NullBool to JSON

func (*NullBool) UnmarshalJSON

func (n *NullBool) UnmarshalJSON(b []byte) error

UnmarshalJSON correctly deserializes a NullBool from JSON

type NullFloat64

type NullFloat64 struct {
	sql.NullFloat64
}

NullFloat64 is a type that can be null or a float64

func NewNullFloat64

func NewNullFloat64(v interface{}) (n NullFloat64)

NewNullFloat64 new

func (NullFloat64) MarshalJSON

func (n NullFloat64) MarshalJSON() ([]byte, error)

MarshalJSON correctly serializes a NullFloat64 to JSON

func (*NullFloat64) UnmarshalJSON

func (n *NullFloat64) UnmarshalJSON(b []byte) error

UnmarshalJSON correctly deserializes a NullFloat64 from JSON

type NullInt64

type NullInt64 struct {
	sql.NullInt64
}

NullInt64 is a type that can be null or an int

func NewNullInt64

func NewNullInt64(v interface{}) (n NullInt64)

NewNullInt64 new

func (NullInt64) MarshalJSON

func (n NullInt64) MarshalJSON() ([]byte, error)

MarshalJSON correctly serializes a NullInt64 to JSON

func (*NullInt64) UnmarshalJSON

func (n *NullInt64) UnmarshalJSON(b []byte) error

UnmarshalJSON correctly deserializes a NullInt64 from JSON

type NullString

type NullString struct {
	sql.NullString
}

NullString is a type that can be null or a string

func NewNullString

func NewNullString(v interface{}) (n NullString)

NewNullString new

func (NullString) MarshalJSON

func (n NullString) MarshalJSON() ([]byte, error)

MarshalJSON correctly serializes a NullString to JSON

func (*NullString) UnmarshalJSON

func (n *NullString) UnmarshalJSON(b []byte) error

UnmarshalJSON correctly deserializes a NullString from JSON

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

NullTime is a type that can be null or a time

func NewNullTime

func NewNullTime(v interface{}) (n NullTime)

NewNullTime new

func (NullTime) MarshalJSON

func (n NullTime) MarshalJSON() ([]byte, error)

MarshalJSON correctly serializes a NullTime to JSON

func (*NullTime) Scan

func (n *NullTime) Scan(value interface{}) error

Scan implements the Scanner interface. The value type must be time.Time or string / []byte (formatted time-string), otherwise Scan fails.

func (*NullTime) UnmarshalJSON

func (n *NullTime) UnmarshalJSON(b []byte) error

UnmarshalJSON correctly deserializes a NullTime from JSON

func (NullTime) Value

func (n NullTime) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Options

type Options struct {
	Driver       string `json:"driver"`
	Host         string `json:"host"`
	DBName       string `json:"dbName"`
	Username     string `json:"username"`
	Password     string `json:"password"`
	DataSource   string `json:"dataSource"`
	EnableLog    bool   `json:"enable_log"`
	LogLevel     int    `json:"logLevel"`
	MaxIdleConns int    `json:"maxIdleConns"`
	MaxOpenConns int    `json:"maxOpenConns"`
}

Options 数据库配置

type SQLExecutor

type SQLExecutor interface {
	NewRecord(value interface{}) bool
	Create(value interface{}) *gorm.DB
	Save(value interface{}) *gorm.DB
	Delete(value interface{}, where ...interface{}) *gorm.DB

	Find(out interface{}, where ...interface{}) *gorm.DB
	Exec(sql string, values ...interface{}) *gorm.DB
	First(out interface{}, where ...interface{}) *gorm.DB
}

SQLExecutor sql执行器

type Transaction

type Transaction struct {
	*gorm.DB
	// contains filtered or unexported fields
}

Transaction 事物维护的object

func (*Transaction) AddObject

func (trans *Transaction) AddObject(o TransactionObject)

AddObject 往事物维护的object中增加object

func (*Transaction) Commit

func (trans *Transaction) Commit() error

Commit 事物提交

func (*Transaction) Rollback

func (trans *Transaction) Rollback() error

Rollback 事物回滚

type TransactionObject

type TransactionObject interface {
	SetTransaction(trans *Transaction)
}

TransactionObject interface

Jump to

Keyboard shortcuts

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