sql

package
v1.7.8 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT, Apache-2.0 Imports: 12 Imported by: 8

Documentation

Index

Constants

View Source
const (
	Mysql    = "mysql"
	Postgres = "postgres"
	Sqlite   = "sqlite"
)
View Source
const (
	TmFmtWithMS = "2006-01-02 15:04:05.999"
	NullStr     = "NULL"
)
View Source
const (
	ColumnDeletedAt = "deleted_at"
	ColumnId        = "id"
	ColumnName      = "name"
)
View Source
const (
	ExprEqual    = " = ?"
	ExprNotEqual = " != ?"
	ExprGreater  = " > ?"
)
View Source
const (
	Insert    = "INSERT"
	Select    = "SELECT"
	Update    = "UPDATE"
	Delete    = "DELETE"
	LeftJoin  = "LEFT JOIN"
	RightJoin = "RIGHT JOIN"
	InnerJoin = "INNER JOIN"
	Limit     = `LIMIT %d`
	Offset    = `OFFSET %d`
	Limit1    = `LIMIT 1`
)
View Source
const (
	NotDeleted     = ColumnDeletedAt + " IS " + NullStr
	WithNotDeleted = ` AND ` + NotDeleted
)
View Source
const (
	IdEqual   = ColumnId + ExprEqual
	NameEqual = ColumnName + ExprEqual
)
View Source
const (
	CondiTagName = "sqlcond" // e.g: `sqlcond:"column:id;operate:="`

)

Variables

This section is empty.

Functions

func AnyToAnys added in v1.7.0

func AnyToAnys(a any) []any

func ConvertParams

func ConvertParams(v any, escaper string) string

func DeleteByIdSQL

func DeleteByIdSQL(tableName string) string

func DeleteSQL

func DeleteSQL(tableName, column string) string

func ExistsByFilterExprs

func ExistsByFilterExprs(db *sql.DB, tableName string, filters FilterExprs) (bool, error)

func ExistsByFilterExprsSQL

func ExistsByFilterExprsSQL(tableName string, filters FilterExprs) string

func ExistsByQuerySQL

func ExistsByQuerySQL(qsql string) string

func ExistsSQL

func ExistsSQL(tableName, column string, withDeletedAt bool) string

func StringConvertFor

func StringConvertFor[T any](str string) (T, error)

Types

type ConditionOperation

type ConditionOperation int
const (
	OperationPlace ConditionOperation = iota
	Equal
	NotEqual
	Greater
	Less
	Between
	GreaterOrEqual
	LessOrEqual
	IsNotNull
	IsNull
	In
	NotIn
	Like
	NotLike
)

func ParseConditionOperation

func ParseConditionOperation(op string) ConditionOperation

func (ConditionOperation) SQL

func (m ConditionOperation) SQL() string

func (ConditionOperation) String

func (m ConditionOperation) String() string

type ConditionTag

type ConditionTag struct {
	Column     string `meta:"column"`
	Operate    string `meta:"operate"`
	EmptyValid bool   `meta:"emptyvalid"`
}

func GetConditionTagTag added in v1.6.11

func GetConditionTagTag(tag reflect.StructTag) (*ConditionTag, error)

type Cursor added in v1.7.0

type Cursor[T any] struct {
	Field string `json:"field,omitempty"`
	Prev  T      `json:"prev,omitempty"`
	Size  int    `json:"size,omitempty"`
}

type FilterExpr

type FilterExpr struct {
	Field     string             `json:"field,omitempty"`
	Operation ConditionOperation `json:"op,omitempty"`
	Value     any                `json:"value,omitempty"`
}

func (*FilterExpr) Build

func (filter *FilterExpr) Build() string

type FilterExprMap added in v1.7.0

type FilterExprMap map[string]FilterExpr

type FilterExprs

type FilterExprs []FilterExpr

func (FilterExprs) Build

func (f FilterExprs) Build() string

func (FilterExprs) BuildSQL

func (f FilterExprs) BuildSQL() (string, []any)

type Id added in v1.7.0

type Id struct {
	Id uint64 `json:"id"`
}

type List added in v1.7.0

type List struct {
	Pagination Pagination  `json:"page,omitempty"`
	Sort       Sorts       `json:"sort,omitempty"`
	Filters    FilterExprs `json:"filters,omitempty"`
}

type Ordered added in v1.7.0

type Ordered interface {
	constraints.Ordered | time.Time | ~*time.Time
}

type Pagination added in v1.7.0

type Pagination struct {
	No   uint32 `json:"no"`
	Size uint32 `json:"size"`
}

type PaginationEmbedded added in v1.7.0

type PaginationEmbedded struct {
	PageNo   uint32 `json:"pageNo"`
	PageSize uint32 `json:"pageSize"`
}

type Range added in v1.7.0

type Range[T any] struct {
	Field string    `json:"field,omitempty"`
	Begin T         `json:"begin"`
	End   T         `json:"end"`
	Type  RangeMode `json:"type,omitempty"`
}

type RangeMode added in v1.7.0

type RangeMode int8
const (
	RangeModeContainsEnd RangeMode = 1 << iota
	RangeModeContainsBegin
	RangeModeHasEnd
	RangeModeHasBegin
)

func (RangeMode) ContainsBegin added in v1.7.0

func (r RangeMode) ContainsBegin() bool

func (RangeMode) ContainsEnd added in v1.7.0

func (r RangeMode) ContainsEnd() bool

func (RangeMode) HasBegin added in v1.7.0

func (r RangeMode) HasBegin() bool

func (RangeMode) HasEnd added in v1.7.0

func (r RangeMode) HasEnd() bool

type Sort added in v1.7.0

type Sort struct {
	Field string   `json:"field"`
	Type  SortType `json:"type,omitempty"`
}

type SortExpr added in v1.7.4

type SortExpr struct {
	Sql                string `json:"sql"`
	Var                any    `json:"var"`
	WithoutParenthesis bool   `json:"withoutParenthesis"`
}

type SortType added in v1.7.0

type SortType uint8
const (
	SortTypeDesc SortType = iota
	SortTypeAsc
)

type Sorts added in v1.7.4

type Sorts []Sort

Directories

Path Synopsis
export
gen

Jump to

Keyboard shortcuts

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