orm

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllCols = "*"

Functions

func CreateStructFromTable added in v0.2.0

func CreateStructFromTable(table Table) error

func CreateTableFromStruct added in v0.2.0

func CreateTableFromStruct(table Table) (string, error)

func SetDefaults added in v0.2.1

func SetDefaults(table Table)

func SliceContain

func SliceContain(array interface{}, val interface{}) (index int)

Types

type JoinType

type JoinType string
const (
	JoinTypeInner JoinType = "join"
	JoinTypeLeft  JoinType = "left join"
	JoinTypeRight JoinType = "right join"
)

type JsonInt

type JsonInt int64

func (JsonInt) MarshalJSON

func (i JsonInt) MarshalJSON() ([]byte, error)

func (*JsonInt) Scan

func (i *JsonInt) Scan(v interface{}) error

func (JsonInt) ToString

func (i JsonInt) ToString() string

func (*JsonInt) UnmarshalJSON

func (i *JsonInt) UnmarshalJSON(data []byte) error

func (JsonInt) Value

func (i JsonInt) Value() (driver.Value, error)

type JsonTime

type JsonTime struct {
	time.Time
}

func (JsonTime) MarshalJSON

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

MarshalJSON on JsonTime format Time field with %Y-%m-%d %H:%M:%S

func (*JsonTime) Scan

func (t *JsonTime) Scan(v interface{}) error

Scan valueof time.Time

func (*JsonTime) UnmarshalJSON

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

MarshalJSON on JsonTime format Time field with %Y-%m-%d %H:%M:%S

func (JsonTime) Value

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

Value insert timestamp into mysql need this function.

type Query

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

func (*Query) AliasTable

func (m *Query) AliasTable(alias string) *Query

func (*Query) DB

func (m *Query) DB() *sql.DB

func (*Query) Delete

func (m *Query) Delete() QueryResult

func (*Query) ExecuteRaw added in v0.2.0

func (m *Query) ExecuteRaw(prepareSql string, bindings ...interface{}) QueryResult

func (*Query) FromTable

func (m *Query) FromTable(table Table, alias ...string) *Query

func (*Query) GroupBy

func (m *Query) GroupBy(columns ...interface{}) *Query

should not use group by after order by

func (*Query) Having

func (m *Query) Having(where func(*Query)) *Query

func (*Query) Insert

func (m *Query) Insert(data interface{}, tableFieldAddrs ...interface{}) QueryResult

tableFieldAddrs: allow insert table columns

func (*Query) InsertIgnore

func (m *Query) InsertIgnore(data interface{}, tableFieldAddrs []interface{}, updates ...UpdateColumn) QueryResult

insert ignore ... // on duplicate key update ...

func (*Query) Join

func (m *Query) Join(table Table, where func(join *Query), alias ...string) *Query

func (*Query) LeftJoin

func (m *Query) LeftJoin(table Table, where func(join *Query), alias ...string) *Query

func (*Query) Limit

func (m *Query) Limit(limit int) *Query

func (*Query) Offset

func (m *Query) Offset(offset int) *Query

func (*Query) OrWhere

func (m *Query) OrWhere(column interface{}, vals ...interface{}) *Query

"id=1" &obj.id, 1 &obj.id, "=", 1

func (*Query) OrWhereGroup

func (m *Query) OrWhereGroup(f func(*Query)) *Query

"id=1" &obj.id, 1 &obj.id, "=", 1

func (*Query) OrderBy

func (m *Query) OrderBy(column interface{}) *Query

func (*Query) OrderByDesc

func (m *Query) OrderByDesc(column interface{}) *Query

func (*Query) RightJoin

func (m *Query) RightJoin(table Table, where func(join *Query), alias ...string) *Query

func (*Query) Select

func (m *Query) Select(dest interface{}, columns ...interface{}) QueryResult

func (*Query) SelectCount

func (m *Query) SelectCount(dest interface{}) QueryResult

dest: *int | *int64 | ...

func (*Query) SelectForUpdate

func (m *Query) SelectForUpdate(dest interface{}, columns ...interface{}) QueryResult

func (*Query) SelectMapOfColumn2KeyByColumn1

func (m *Query) SelectMapOfColumn2KeyByColumn1(dest interface{}, columns ...interface{}) QueryResult

dest: *map [int | string | ...] int | string ...

func (*Query) SelectMapOfStructKeyByColumn1

func (m *Query) SelectMapOfStructKeyByColumn1(dest interface{}, columns ...interface{}) QueryResult

dest: *map [int | string | ...] struct

func (*Query) SelectMapOfStructSliceKeyByColumn1

func (m *Query) SelectMapOfStructSliceKeyByColumn1(dest interface{}, columns ...interface{}) QueryResult

dest: *map [int | string | ...] []struct

func (*Query) SelectMapStr2Interface added in v0.2.0

func (m *Query) SelectMapStr2Interface(dest *map[string]interface{}, columns ...interface{}) QueryResult

dest, first of sql rows: *map[column_name]column_value

func (*Query) SelectRaw added in v0.2.0

func (m *Query) SelectRaw(dest interface{}, prepareSql string, bindings ...interface{}) QueryResult

select from raw sql

func (*Query) SelectSliceOfColumn1

func (m *Query) SelectSliceOfColumn1(dest interface{}, columns ...interface{}) QueryResult

dest: *[]int | *[]string | ...

func (*Query) SelectSliceOfMapStr2Interface added in v0.2.0

func (m *Query) SelectSliceOfMapStr2Interface(dest *[]map[string]interface{}, columns ...interface{}) QueryResult

dest, sql rows: *[]map[column_name]column_value

func (*Query) SelectSliceOfStruct

func (m *Query) SelectSliceOfStruct(dest interface{}, columns ...interface{}) QueryResult

dest: *[]struct

func (*Query) SelectStructOfRow1

func (m *Query) SelectStructOfRow1(dest interface{}, columns ...interface{}) QueryResult

dest: *struct

func (*Query) SelectSub

func (m *Query) SelectSub(columns ...interface{}) *tempTable

func (*Query) SelectValueOfFirstCell

func (m *Query) SelectValueOfFirstCell(dest interface{}, columns ...interface{}) QueryResult

dest: *int | *string | ...

func (*Query) Transaction

func (m *Query) Transaction(query func(db *Query) error) error

func (*Query) Update

func (m *Query) Update(column interface{}, val interface{}) QueryResult

func (*Query) Updates

func (m *Query) Updates(updates ...UpdateColumn) QueryResult

func (*Query) UseDB

func (m *Query) UseDB(db *sql.DB) *Query

func (*Query) UseTx

func (m *Query) UseTx(tx *sql.Tx) *Query

func (*Query) Where

func (m *Query) Where(column interface{}, vals ...interface{}) *Query

"id=1" &obj.id, 1 &obj.id, "=", 1

func (*Query) WhereGroup

func (m *Query) WhereGroup(f func(*Query)) *Query

"id=1" &obj.id, 1 &obj.id, "=", 1

type QueryResult

type QueryResult struct {
	PrepareSql   string
	Bindings     []interface{}
	LastInsertId int64
	RowsAffected int64
	Err          error
}

func (*QueryResult) Sql

func (q *QueryResult) Sql() string

type Raw

type Raw string

type Table

type Table interface {
	Query() *Query
	TableName() string
	DatabaseName() string
}

type UpdateColumn

type UpdateColumn struct {
	Column interface{}
	Val    interface{}
}

type WhereOperator

type WhereOperator Raw
const (
	WhereEqual          WhereOperator = "="
	WhereNotEqual       WhereOperator = "!="
	WhereGreatThan      WhereOperator = ">"
	WhereGreaterOrEqual WhereOperator = ">="
	WhereLessThan       WhereOperator = "<"
	WhereLessOrEqual    WhereOperator = "<="
	WhereIn             WhereOperator = "in"
	WhereNotIn          WhereOperator = "not in"
	WhereLike           WhereOperator = "like"
	WhereNotLike        WhereOperator = "not like"
	WhereRlike          WhereOperator = "rlike"
	WhereNotRlike       WhereOperator = "not rlike"
	WhereIsNull         WhereOperator = "is null"
	WhereIsNotNull      WhereOperator = "is not null"
)

Jump to

Keyboard shortcuts

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