easysql

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 8 Imported by: 1

README

easysql

this's a golang library for mysql/postgresql/cockroachdb. it's easy to switch backend dbserver between mysql, postgresql and cockroachdb with little change in your golang code.

features:

  1. you should write SQL clause to talk to backend db server.
  2. data type binding between database and golang type. string, int, float, date, datetime, string[], int[], jsonb, etc.
  3. support transfer to default value if one db column is NULL

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BOOL

type BOOL struct {
	sql.NullBool
}

------------------------------------------------------------------------------ 空字段会解析为 false

func (BOOL) MarshalJSON

func (t BOOL) MarshalJSON() ([]byte, error)

func (*BOOL) Scan

func (t *BOOL) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*BOOL) SetNULL

func (t *BOOL) SetNULL()

func (*BOOL) SetVal

func (t *BOOL) SetVal(val bool) error

func (*BOOL) UnmarshalJSON

func (t *BOOL) UnmarshalJSON(data []byte) error

func (BOOL) Value

func (t BOOL) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type ByteArray

type ByteArray = pq.ByteaArray

type DATE

type DATE struct {
	Valid bool
	// contains filtered or unexported fields
}

注意:日期不带时区信息

func NewDate

func NewDate(szDate string) DATE

szDate 为UTC时间。 layout格式为: "2006-01-02"

func (DATE) MarshalJSON

func (t DATE) MarshalJSON() ([]byte, error)

func (DATE) MarshalText

func (t DATE) MarshalText() ([]byte, error)

func (*DATE) Scan

func (t *DATE) Scan(value interface{}) error

Scan implements the Scanner interface. read data from database

func (*DATE) SetLayout

func (t *DATE) SetLayout(layout string) *DATE

时间字符串解析/显示 layout

func (*DATE) SetNULL

func (t *DATE) SetNULL()

func (*DATE) SetVal

func (t *DATE) SetVal(szDate string) error

func (DATE) String

func (t DATE) String() string

func (DATE) ToTime added in v1.1.1

func (t DATE) ToTime() time.Time

func (*DATE) UnmarshalJSON

func (t *DATE) UnmarshalJSON(data []byte) error

func (DATE) Value

func (t DATE) Value() (driver.Value, error)

Value implements the driver Valuer interface. save data to database

type DATETIME

type DATETIME struct {
	Valid bool
	// contains filtered or unexported fields
}

func NewDateTime

func NewDateTime(tm time.Time) DATETIME

layout默认为: "2006-01-02 15:04:05", 时区为tm所在时区

func NewDateTimeLocal

func NewDateTimeLocal(szDate string) DATETIME

szDate为本地时区时间。 layout格式为: "2006-01-02 15:04:05"

func NewDateTimeUTC

func NewDateTimeUTC(szDate string) DATETIME

szDate 为UTC时间。 layout格式为: "2006-01-02 15:04:05"

func (DATETIME) MarshalJSON

func (t DATETIME) MarshalJSON() ([]byte, error)

func (DATETIME) MarshalText

func (t DATETIME) MarshalText() ([]byte, error)

func (*DATETIME) Scan

func (t *DATETIME) Scan(value interface{}) error

Scan implements the sql.Scanner interface. read data from database

func (*DATETIME) SetLayout

func (t *DATETIME) SetLayout(layout string) *DATETIME

时间字符串解析/显示 layout

func (*DATETIME) SetNULL

func (t *DATETIME) SetNULL() *DATETIME

func (*DATETIME) SetTimezone

func (t *DATETIME) SetTimezone(tz *time.Location) *DATETIME

设置时区 影响MarshalJSON(), MarshalText(), String(), UnmarshalJSON() 显示

func (*DATETIME) SetVal

func (t *DATETIME) SetVal(tm time.Time) *DATETIME

func (DATETIME) String

func (t DATETIME) String() string

func (DATETIME) ToTime

func (t DATETIME) ToTime() time.Time

func (*DATETIME) UnmarshalJSON

func (t *DATETIME) UnmarshalJSON(data []byte) error

func (DATETIME) Value

func (t DATETIME) Value() (driver.Value, error)

Value implements the driver.Valuer interface. save data to database

type DATETIME_LOCAL

type DATETIME_LOCAL struct {
	Valid bool
	// contains filtered or unexported fields
}

func (DATETIME_LOCAL) MarshalJSON

func (t DATETIME_LOCAL) MarshalJSON() ([]byte, error)

func (DATETIME_LOCAL) MarshalText

func (t DATETIME_LOCAL) MarshalText() ([]byte, error)

func (*DATETIME_LOCAL) Scan

func (t *DATETIME_LOCAL) Scan(value interface{}) error

Scan implements the sql.Scanner interface. read data from database

func (*DATETIME_LOCAL) SetLayout

func (t *DATETIME_LOCAL) SetLayout(layout string)

时间字符串解析/显示 layout

func (*DATETIME_LOCAL) SetNULL

func (t *DATETIME_LOCAL) SetNULL() *DATETIME_LOCAL

func (*DATETIME_LOCAL) SetVal

func (t *DATETIME_LOCAL) SetVal(tm time.Time) *DATETIME_LOCAL

func (DATETIME_LOCAL) String

func (t DATETIME_LOCAL) String() string

func (DATETIME_LOCAL) ToTime

func (t DATETIME_LOCAL) ToTime() time.Time

func (*DATETIME_LOCAL) UnmarshalJSON

func (t *DATETIME_LOCAL) UnmarshalJSON(data []byte) error

func (DATETIME_LOCAL) Value

func (t DATETIME_LOCAL) Value() (driver.Value, error)

Value implements the driver.Valuer interface. save data to database

type FLOAT64

type FLOAT64 struct {
	sql.NullFloat64
}

------------------------------------------------------------------------------ 空字段会解析为0

func (FLOAT64) MarshalJSON

func (t FLOAT64) MarshalJSON() ([]byte, error)

func (*FLOAT64) Scan

func (t *FLOAT64) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*FLOAT64) SetNULL

func (t *FLOAT64) SetNULL()

func (*FLOAT64) SetVal

func (t *FLOAT64) SetVal(val float64) error

func (*FLOAT64) UnmarshalJSON

func (t *FLOAT64) UnmarshalJSON(data []byte) error

func (FLOAT64) Value

func (t FLOAT64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Float64Array

type Float64Array = pq.Float64Array

type INT64

type INT64 struct {
	sql.NullInt64
}

------------------------------------------------------------------------------ 空字段会解析为0

func (INT64) MarshalJSON

func (t INT64) MarshalJSON() ([]byte, error)

func (*INT64) Scan

func (t *INT64) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*INT64) SetNULL

func (t *INT64) SetNULL()

func (*INT64) SetVal

func (t *INT64) SetVal(val int64) error

func (*INT64) UnmarshalJSON

func (t *INT64) UnmarshalJSON(data []byte) error

func (INT64) Value

func (t INT64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Int64Array

type Int64Array = pq.Int64Array

type JSONB

type JSONB struct {
	KV map[string]interface{}
}

------------------------------------------------------------------------------ JSONB格式,数据库字段格式为: "{}", 不能为json数组等其他格式 空字段解析为空map

func (JSONB) MarshalJSON

func (t JSONB) MarshalJSON() ([]byte, error)

func (JSONB) MarshalText

func (t JSONB) MarshalText() ([]byte, error)

func (*JSONB) Merge

func (t *JSONB) Merge(mp map[string]interface{}) *JSONB

func (*JSONB) Scan

func (t *JSONB) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*JSONB) SetNULL

func (t *JSONB) SetNULL()

func (*JSONB) SetVal

func (t *JSONB) SetVal(mp map[string]interface{}) error

func (JSONB) String

func (t JSONB) String() string

func (*JSONB) UnmarshalJSON

func (t *JSONB) UnmarshalJSON(data []byte) error

func (JSONB) Value

func (t JSONB) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type STRING

type STRING struct {
	sql.NullString
}

------------------------------------------------------------------------------ 空字段解析为空字符串

func (STRING) MarshalJSON

func (t STRING) MarshalJSON() ([]byte, error)

func (*STRING) Scan

func (t *STRING) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*STRING) SetNULL

func (t *STRING) SetNULL()

func (*STRING) SetVal

func (t *STRING) SetVal(szVal string) error

func (STRING) String

func (t STRING) String() string

func (*STRING) UnmarshalJSON

func (t *STRING) UnmarshalJSON(data []byte) error

func (STRING) Value

func (t STRING) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type StringArray

type StringArray = pq.StringArray

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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