norm

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 11 Imported by: 0

README

norm

Documentation

Index

Constants

View Source
const (
	DefaultModelTag = "db"
	SelectTemp      = "SELECT %s FROM %s"
	InsertTemp      = "INSERT INTO %s (%s) VALUES (%s)"
	UpdateTemp      = "UPDATE %s SET %s"
	DeleteTemp      = "DELETE FROM %s"
)
View Source
const (
	SortKey = "~sort~"
)
View Source
const (
	UnsupportedControllerError = "%s not supported for %s"
)

Variables

View Source
var (
	ErrDuplicateKey = operator.ErrDuplicateKey
	ErrNotFound     = operator.ErrNotFound
)

Functions

func CreatePointerAndSlice

func CreatePointerAndSlice(input interface{}) (interface{}, interface{})

func DeepCopy

func DeepCopy(src any) (any, error)

DeepCopy deep copy

func EachOR

func EachOR(conds any) any

func NewController

func NewController(conn any, op Operator, m any) func(ctx context.Context) Controller

func StrSlice2Map

func StrSlice2Map(s []string) (res map[string]struct{})

StrSlice2Map convert string slice to map

func Struct2Map

func Struct2Map(obj any, tag string) map[string]any

Struct2Map convert struct to map, tag is the tag name of struct

func StructSlice2MapSlice

func StructSlice2MapSlice(obj any, tag string) []map[string]any

StructSlice2MapSlice convert struct slice to map slice, tag is the tag name of struct

func ToOR

func ToOR(key string) string

Types

type AND

type AND map[string]any

type Cond

type Cond map[string]any

type Controller

type Controller interface {
	WithSession(session sqlx.Session) Controller
	Reset() Controller
	Filter(filter ...any) Controller
	Exclude(exclude ...any) Controller
	Where(cond string, args ...any) Controller
	Select(columns any) Controller
	Limit(pageSize, pageNum int64) Controller
	OrderBy(orderBy any) Controller
	GroupBy(groupBy any) Controller
	Having(having string, args ...any) Controller
	Insert(data map[string]any) (id int64, err error)
	InsertModel(model any) (id int64, err error)
	//BulkInsert(data []map[string]any, handler sqlx.ResultHandler) (err error)
	//BulkInsertModel(modelSlice any, handler sqlx.ResultHandler) (err error)
	Remove() (num int64, err error)
	Update(data map[string]any) (num int64, err error)
	Count() (num int64, err error)
	FindOne() (result map[string]any, err error)
	FindOneModel(modelPtr any) (err error)
	FindAll() (result []map[string]any, err error)
	FindAllModel(modelSlicePtr any) (err error)
	Delete() (num int64, err error)
	Modify(data map[string]any) (num int64, err error)
	Exist() (exist bool, error error)
	List() (num int64, data []map[string]any, err error)
	GetOrCreate(data map[string]any) (result map[string]any, err error)
	CreateOrUpdate(data map[string]any, filter ...any) (created bool, num int64, err error)
	GetC2CMap(column1, column2 string) (res map[any]any, err error)
	CreateIfNotExist(data map[string]any) (id int64, created bool, err error)
	// contains filtered or unexported methods
}

type Impl

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

func (*Impl) BulkInsert

func (m *Impl) BulkInsert(data []map[string]any, handler sqlx.ResultHandler) (err error)

func (*Impl) BulkInsertModel

func (m *Impl) BulkInsertModel(modelSlice any, handler sqlx.ResultHandler) (err error)

func (*Impl) Count

func (m *Impl) Count() (num int64, err error)

func (*Impl) CreateIfNotExist

func (m *Impl) CreateIfNotExist(data map[string]any) (id int64, created bool, err error)

func (*Impl) CreateOrUpdate

func (m *Impl) CreateOrUpdate(data map[string]any, filter ...any) (bool, int64, error)

func (*Impl) Delete

func (m *Impl) Delete() (int64, error)

func (*Impl) Exclude

func (m *Impl) Exclude(exclude ...any) Controller

func (*Impl) Exist

func (m *Impl) Exist() (exist bool, err error)

func (*Impl) Filter

func (m *Impl) Filter(filter ...any) Controller

func (*Impl) FindAll

func (m *Impl) FindAll() (result []map[string]any, err error)

func (*Impl) FindAllModel

func (m *Impl) FindAllModel(modelSlicePtr any) (err error)

func (*Impl) FindOne

func (m *Impl) FindOne() (result map[string]any, err error)

func (*Impl) FindOneModel

func (m *Impl) FindOneModel(modelPtr any) (err error)

func (*Impl) GetC2CMap

func (m *Impl) GetC2CMap(column1, column2 string) (res map[any]any, err error)

func (*Impl) GetOrCreate

func (m *Impl) GetOrCreate(data map[string]any) (map[string]any, error)

func (*Impl) GroupBy

func (m *Impl) GroupBy(groupBy any) Controller

func (*Impl) Having added in v0.0.3

func (m *Impl) Having(having string, args ...any) Controller

func (*Impl) Insert

func (m *Impl) Insert(data map[string]any) (id int64, err error)

func (*Impl) InsertModel

func (m *Impl) InsertModel(model any) (id int64, err error)

func (*Impl) Limit

func (m *Impl) Limit(pageSize, pageNum int64) Controller

func (*Impl) List

func (m *Impl) List() (total int64, data []map[string]any, err error)

func (*Impl) Modify

func (m *Impl) Modify(data map[string]any) (num int64, err error)

func (*Impl) OrderBy

func (m *Impl) OrderBy(orderBy any) Controller

func (*Impl) Remove

func (m *Impl) Remove() (num int64, err error)

func (*Impl) Reset

func (m *Impl) Reset() Controller

func (*Impl) Select

func (m *Impl) Select(selects any) Controller

func (*Impl) Update

func (m *Impl) Update(data map[string]any) (num int64, err error)

func (*Impl) Where

func (m *Impl) Where(cond string, args ...any) Controller

func (*Impl) WithSession

func (m *Impl) WithSession(session sqlx.Session) Controller

type OR

type OR map[string]any

type Operator

type Operator operator.Operator

type QuerySet

type QuerySet interface {
	Error() error
	Reset()
	GetQuerySet() (string, []any)
	FilterToSQL(notTag int, filter ...any) QuerySet
	WhereToSQL(cond string, args ...any) QuerySet
	GetSelectSQL() string
	SelectToSQL(columns any) QuerySet
	StrSelectToSQL(columns string) QuerySet
	SliceSelectToSQL(columns []string) QuerySet
	GetLimitSQL() string
	LimitToSQL(pageSize, pageNum int64) QuerySet
	GetOrderBySQL() string
	OrderByToSQL(orderBy any) QuerySet
	StrOrderByToSQL(orderBy string) QuerySet
	SliceOrderByToSQL(orderBy []string) QuerySet
	GetGroupBySQL() string
	GroupByToSQL(groupBy any) QuerySet
	StrGroupByToSQL(groupBy string) QuerySet
	SliceGroupByToSQL(groupBy []string) QuerySet
	GetHavingSQL() (string, []any)
	HavingToSQL(having string, args ...any) QuerySet
	// contains filtered or unexported methods
}

func NewQuerySet

func NewQuerySet(op Operator) QuerySet

type QuerySetImpl

type QuerySetImpl struct {
	Operator
	// contains filtered or unexported fields
}

func (*QuerySetImpl) Error

func (p *QuerySetImpl) Error() error

func (*QuerySetImpl) FilterToSQL

func (p *QuerySetImpl) FilterToSQL(isNot int, filter ...any) QuerySet

func (*QuerySetImpl) GetGroupBySQL

func (p *QuerySetImpl) GetGroupBySQL() string

func (*QuerySetImpl) GetHavingSQL added in v0.0.3

func (p *QuerySetImpl) GetHavingSQL() (string, []any)

func (*QuerySetImpl) GetLimitSQL

func (p *QuerySetImpl) GetLimitSQL() string

func (*QuerySetImpl) GetOrderBySQL

func (p *QuerySetImpl) GetOrderBySQL() string

func (*QuerySetImpl) GetQuerySet

func (p *QuerySetImpl) GetQuerySet() (sql string, args []any)

func (*QuerySetImpl) GetSelectSQL

func (p *QuerySetImpl) GetSelectSQL() string

func (*QuerySetImpl) GroupByToSQL

func (p *QuerySetImpl) GroupByToSQL(groupBy any) QuerySet

func (*QuerySetImpl) HavingToSQL added in v0.0.3

func (p *QuerySetImpl) HavingToSQL(having string, args ...any) QuerySet

func (*QuerySetImpl) LimitToSQL

func (p *QuerySetImpl) LimitToSQL(pageSize, pageNum int64) QuerySet

func (*QuerySetImpl) OrderByToSQL

func (p *QuerySetImpl) OrderByToSQL(orderBy any) QuerySet

func (*QuerySetImpl) Reset

func (p *QuerySetImpl) Reset()

func (*QuerySetImpl) SelectToSQL

func (p *QuerySetImpl) SelectToSQL(columns any) QuerySet

func (*QuerySetImpl) SliceGroupByToSQL added in v0.0.2

func (p *QuerySetImpl) SliceGroupByToSQL(groupBy []string) QuerySet

func (*QuerySetImpl) SliceOrderByToSQL added in v0.0.2

func (p *QuerySetImpl) SliceOrderByToSQL(orderBy []string) QuerySet

func (*QuerySetImpl) SliceSelectToSQL added in v0.0.2

func (p *QuerySetImpl) SliceSelectToSQL(columns []string) QuerySet

func (*QuerySetImpl) StrGroupByToSQL added in v0.0.2

func (p *QuerySetImpl) StrGroupByToSQL(groupBy string) QuerySet

func (*QuerySetImpl) StrOrderByToSQL added in v0.0.2

func (p *QuerySetImpl) StrOrderByToSQL(orderBy string) QuerySet

func (*QuerySetImpl) StrSelectToSQL added in v0.0.2

func (p *QuerySetImpl) StrSelectToSQL(columns string) QuerySet

func (*QuerySetImpl) WhereToSQL

func (p *QuerySetImpl) WhereToSQL(cond string, args ...any) QuerySet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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