orm

package
v0.0.0-...-e120e2b Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JoinStatementLeftJoin  = JoinStatement("LEFT JOIN")
	JoinStatementRightJoin = JoinStatement("RIGHT JOIN")
)
View Source
const (
	ConditionLogicAnd = ConditionLogic("AND")
	ConditionLogicOr  = ConditionLogic("OR")
)
View Source
const DefaultInsertBatchSize = 1000
View Source
const DefaultName = "default"
View Source
const DefaultRetry = 3

Variables

View Source
var TablePrefix = ""

Functions

func Clone

func Clone(ctx context.Context, configName string, w CloneWrapper) (result sql.Result, err error)

func Delete

func Delete(ctx context.Context, configName string, w DeleteWrapper) (result sql.Result, err error)

func InitConfig

func InitConfig(config ...Config) error

func Insert

func Insert(ctx context.Context, configName string, w InsertWrapper) (result sql.Result, err error)

func JoinFieldNames

func JoinFieldNames(fields []FieldName, sep string) string

func Now

func Now() int64

func QueryScan

func QueryScan(ctx context.Context, configName string, out interface{}, statement string, values ...interface{}) error

func Select

func Select(ctx context.Context, configName string, w QueryWrapper, out interface{}) error

func Update

func Update(ctx context.Context, configName string, w UpdateWrapper) (result sql.Result, err error)

Types

type CloneWrapper

type CloneWrapper interface {
	Build() (statement string, values []interface{}, err error)
}

func NewCloneWrapper

func NewCloneWrapper(templateTableName, newTableName TableName) CloneWrapper

type Column

type Column struct {
	reflect.Value
	Name string
}

type Condition

type Condition interface {
	Clone() Condition
	Build() (statement string, values []interface{}, err error)
}

func NewExpressionCondition

func NewExpressionCondition(field FieldName, operator string, value interface{}) Condition

func NewNestedCondition

func NewNestedCondition(w WhereWrapper) Condition

func NewNotNullCondition

func NewNotNullCondition(field FieldName) Condition

func NewNullCondition

func NewNullCondition(field FieldName) Condition

type ConditionLogic

type ConditionLogic string

type Config

type Config struct {
	Name   string `json:"name"`
	Host   string `json:"host"`
	Port   int    `json:"port"`
	User   string `json:"user"`
	Pass   string `json:"pass"`
	Schema string `json:"schema"`
}

type DataSet

type DataSet []Row

func NewDataSet

func NewDataSet() DataSet

func QueryRows

func QueryRows(ctx context.Context, configName string, statement string, values ...interface{}) (DataSet, error)

func (*DataSet) Reform

func (t *DataSet) Reform(out interface{}) error

type DeleteWrapper

type DeleteWrapper interface {
	Model(model interface{}) DeleteWrapper
	WhereWrapper
	TableName(tableName TableName) DeleteWrapper
	Build() (statement string, values []interface{}, err error)
}

func NewDeleteWrapper

func NewDeleteWrapper(model ...interface{}) DeleteWrapper

type FieldName

type FieldName string

func (FieldName) LowerFirstHump

func (t FieldName) LowerFirstHump() string

func (FieldName) String

func (t FieldName) String() string

func (FieldName) UpperFirstHump

func (t FieldName) UpperFirstHump() string

func (FieldName) WithAlias

func (t FieldName) WithAlias(alias string) FieldName

func (FieldName) WithTableAlias

func (t FieldName) WithTableAlias(alias string) FieldName

func (FieldName) Wrap

func (t FieldName) Wrap() FieldName

type H

type H map[FieldName]interface{}

type IManager

type IManager interface {
	Add(c Config) error
	Exec(ctx context.Context, configName string, statement string, values ...interface{}) (result sql.Result, err error)
	Query(ctx context.Context, configName string, statement string, values ...interface{}) (result *sql.Rows, err error)

	QueryRows(ctx context.Context, configName string, statement string, values ...interface{}) (DataSet, error)
	// contains filtered or unexported methods
}

func NewConnManager

func NewConnManager() IManager

type InsertWrapper

type InsertWrapper interface {
	Model(v interface{}) InsertWrapper
	BatchSize(batchSize int) InsertWrapper
	Fields(fields ...FieldName) InsertWrapper
	DataLen() int
	Reset() InsertWrapper
	Build() (statement string, values []interface{}, next bool, err error)
	Ignore() InsertWrapper
	Add(v ...interface{}) InsertWrapper
	OnDuplicatedUpdate(field FieldName, values ...interface{}) InsertWrapper
}

func NewInsertWrapper

func NewInsertWrapper(model ...interface{}) InsertWrapper

type Join

type Join struct {
	Statement    JoinStatement
	TableName    TableName
	WhereWrapper WhereWrapper
}

type JoinStatement

type JoinStatement string

type Model

type Model struct {
	TableName TableName
	Fields    []FieldName
}

func CreateModel

func CreateModel(model interface{}) Model

type Order

type Order struct {
	IsAsc     bool
	FieldName FieldName
}

func ASC

func ASC(field FieldName) Order

func DESC

func DESC(field FieldName) Order

type QueryWrapper

type QueryWrapper interface {
	TableName(tb TableName) QueryWrapper
	Model(v interface{}) QueryWrapper
	WhereWrapper
	OrderDesc(fields ...FieldName) QueryWrapper
	OrderAsc(fields ...FieldName) QueryWrapper
	Order(orderBy ...Order) QueryWrapper
	Offset(offset int64) QueryWrapper
	Limit(limit int64) QueryWrapper
	Page(pageNum, pageSize int64) QueryWrapper
	Select(fields ...FieldName) QueryWrapper
	LeftJoin(tableName TableName, where WhereWrapper) QueryWrapper
	RightJoin(tableName TableName, where WhereWrapper) QueryWrapper
	SetWhere(where WhereWrapper) QueryWrapper
}

func NewQueryWrapper

func NewQueryWrapper(model ...interface{}) QueryWrapper

type Row

type Row []Column

func (Row) Reform

func (t Row) Reform(out reflect.Value) error

type TableName

type TableName string

func (TableName) Alias

func (t TableName) Alias(name string) string

func (TableName) Prefix

func (t TableName) Prefix(p string) TableName

func (TableName) String

func (t TableName) String() string

func (TableName) Suffix

func (t TableName) Suffix(p string) TableName

func (TableName) Wrap

func (t TableName) Wrap() TableName

type TableNameList

type TableNameList []TableName

func ShowTables

func ShowTables(ctx context.Context, configName string) (tableNameList TableNameList, err error)

func (TableNameList) Contain

func (t TableNameList) Contain(tb TableName) bool

type UpdateExpression

type UpdateExpression interface {
	Build() (statement string, values []interface{}, err error)
	Clone() UpdateExpression
}

func NewDuplicatedUpdateExpression

func NewDuplicatedUpdateExpression(fields ...FieldName) UpdateExpression

func NewIncreaseExpression

func NewIncreaseExpression(field FieldName, value interface{}) UpdateExpression

func NewSetValueUpdateExpression

func NewSetValueUpdateExpression(field FieldName, value interface{}) UpdateExpression

func NewUpdateExpression

func NewUpdateExpression(modelOrMap interface{}, ignoreFields ...FieldName) UpdateExpression

type UpdateWrapper

type UpdateWrapper interface {
	Model(v interface{}) UpdateWrapper
	WhereWrapper
	LeftJoin(tableName TableName, where WhereWrapper) UpdateWrapper
	RightJoin(tableName TableName, where WhereWrapper) UpdateWrapper
	SetValue(field FieldName, value interface{}) UpdateWrapper
	SetExpression(expressions ...UpdateExpression) UpdateWrapper
	Inc(field FieldName, value interface{}) UpdateWrapper
	Updates(object interface{}, ignoreFields ...FieldName) UpdateWrapper
	Build() (statement string, values []interface{}, err error)
	Table(tableName TableName) UpdateWrapper
	SetWhere(w WhereWrapper) UpdateWrapper
}

func NewUpdateWrapper

func NewUpdateWrapper(model ...interface{}) UpdateWrapper

type WhereWrapper

type WhereWrapper interface {
	Eq(field FieldName, v interface{}) WhereWrapper
	Neq(field FieldName, v interface{}) WhereWrapper
	Le(field FieldName, v interface{}) WhereWrapper
	Lt(field FieldName, v interface{}) WhereWrapper
	Gt(field FieldName, v interface{}) WhereWrapper
	Ge(field FieldName, v interface{}) WhereWrapper
	In(field FieldName, v interface{}) WhereWrapper
	NotIn(field FieldName, v interface{}) WhereWrapper
	IsNotNull(field FieldName) WhereWrapper
	IsNull(field FieldName) WhereWrapper
	Nested(w WhereWrapper) WhereWrapper
	Like(field FieldName, v interface{}) WhereWrapper
	Clone() WhereWrapper
	Build() (string, []interface{}, error)
}

func NewAndWhereWrapper

func NewAndWhereWrapper() WhereWrapper

func NewOrWhereWrapper

func NewOrWhereWrapper() WhereWrapper

Jump to

Keyboard shortcuts

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