sql

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT, Apache-2.0 Imports: 20 Imported by: 9

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:="`

)
View Source
const ScopeName = "github.com/hopeio/gox/database/sql"

Variables

This section is empty.

Functions

func AnyToAnys added in v1.7.0

func AnyToAnys(a any) []any

AnyToAnys returns the result.

func ConvertParams

func ConvertParams(v any, escaper string) string

ConvertParams converts the value.

func DeleteByIdSQL

func DeleteByIdSQL(tableName string) string

DeleteByIdSQL removes or resets state.

func DeleteSQL

func DeleteSQL(tableName, column string) string

DeleteSQL removes or resets state.

func ExistsByFilterExprs

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

ExistsByFilterExprs performs the operation.

func ExistsByFilterExprsSQL

func ExistsByFilterExprsSQL(tableName string, filters FilterExprs) string

ExistsByFilterExprsSQL returns the result.

func ExistsByQuerySQL

func ExistsByQuerySQL(qsql string) string

ExistsByQuerySQL returns the result.

func ExistsSQL

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

ExistsSQL returns the result.

func StringConvertFor

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

StringConvertFor performs the operation.

Types

type Array added in v1.10.0

type Array[T any] []T

Array represents a PostgreSQL array for T. It implements the ArrayGetter and ArraySetter interfaces. It preserves PostgreSQL dimensions and custom lower bounds. Use FlatArray if these are not needed. only support number

func (*Array[T]) Scan added in v1.10.0

func (d *Array[T]) Scan(value any) error

Scan performs the operation.

func (Array[T]) Value added in v1.10.0

func (d Array[T]) Value() (driver.Value, error)

Value returns the value.

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

ParseConditionOperation parses the input.

func (ConditionOperation) SQL

func (m ConditionOperation) SQL() string

SQL returns the result.

func (ConditionOperation) String

func (m ConditionOperation) String() string

String returns the string representation.

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)

GetConditionTagTag returns the value.

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

Build returns the result.

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

Build returns the result.

func (FilterExprs) BuildSQL

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

BuildSQL creates and returns a new instance.

type FloatArray added in v1.10.0

type FloatArray[T constraints.Float] []T

func (*FloatArray[T]) Scan added in v1.10.0

func (d *FloatArray[T]) Scan(value any) error

Scan performs the operation.

func (FloatArray[T]) Value added in v1.10.0

func (d FloatArray[T]) Value() (driver.Value, error)

Value returns the value.

type Id added in v1.7.0

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

type IntArray added in v1.10.0

type IntArray[T constraints.Integer] []T

adpter postgres

func (*IntArray[T]) Scan added in v1.10.0

func (d *IntArray[T]) Scan(value any) error

Scan performs the operation.

func (IntArray[T]) Value added in v1.10.0

func (d IntArray[T]) Value() (driver.Value, error)

Value returns the value.

type Json added in v1.10.0

type Json[T any] struct {
	V T
}

func (*Json[T]) Scan added in v1.10.0

func (j *Json[T]) Scan(value interface{}) error

Scan performs the operation.

func (*Json[T]) Value added in v1.10.0

func (j *Json[T]) Value() (driver.Value, error)

Value returns the value.

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 MapJson added in v1.10.0

type MapJson[T any] map[string]T

func (*MapJson[T]) Scan added in v1.10.0

func (j *MapJson[T]) Scan(value interface{}) error

Scan performs the operation.

func (MapJson[T]) Value added in v1.10.0

func (j MapJson[T]) Value() (driver.Value, error)

Value returns the value.

type Null added in v1.10.0

type Null[T any] sql.Null[T]

func (Null[T]) MarshalJSON added in v1.10.0

func (n Null[T]) MarshalJSON() ([]byte, error)

MarshalJSON encodes the value.

func (*Null[T]) Scan added in v1.10.0

func (n *Null[T]) Scan(value any) error

Scan performs the operation.

func (*Null[T]) UnmarshalJSON added in v1.10.0

func (n *Null[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes into the value.

func (Null[T]) Value added in v1.10.0

func (n Null[T]) Value() (driver.Value, error)

Value returns the value.

type NullJson added in v1.10.0

type NullJson[T any] struct {
	V     T
	Valid bool
}

func (*NullJson[T]) GormDataType added in v1.10.0

func (*NullJson[T]) GormDataType() string

GormDataType returns the result.

func (*NullJson[T]) Scan added in v1.10.0

func (j *NullJson[T]) Scan(value interface{}) error

Scan performs the operation.

func (*NullJson[T]) Value added in v1.10.0

func (j *NullJson[T]) Value() (driver.Value, error)

Value returns the value.

type OTelDBStats added in v1.10.3

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

func GlobalOTelDBStats added in v1.11.0

func GlobalOTelDBStats() *OTelDBStats

GlobalOTelDBStats returns the result.

func (*OTelDBStats) Close added in v1.10.3

func (s *OTelDBStats) Close() error

Close closes and releases resources.

func (*OTelDBStats) Register added in v1.10.3

func (s *OTelDBStats) Register(db *stdsql.DB, attrs ...attribute.KeyValue) error

Register performs the operation.

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

ContainsBegin reports whether the condition holds.

func (RangeMode) ContainsEnd added in v1.7.0

func (r RangeMode) ContainsEnd() bool

ContainsEnd reports whether the condition holds.

func (RangeMode) HasBegin added in v1.7.0

func (r RangeMode) HasBegin() bool

HasBegin reports whether the condition holds.

func (RangeMode) HasEnd added in v1.7.0

func (r RangeMode) HasEnd() bool

HasEnd reports whether the condition holds.

type RawJson added in v1.10.0

type RawJson []byte

func (*RawJson) GormDataType added in v1.10.0

func (*RawJson) GormDataType() string

GormDataType returns the result.

func (*RawJson) Scan added in v1.10.0

func (j *RawJson) Scan(value interface{}) error

Scan performs the operation.

func (RawJson) Value added in v1.10.0

func (j RawJson) Value() (driver.Value, error)

Value returns the value.

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

type StringArray added in v1.10.0

type StringArray []string

func (*StringArray) Scan added in v1.10.0

func (d *StringArray) Scan(value any) error

Scan performs the operation.

func (StringArray) Value added in v1.10.0

func (d StringArray) Value() (driver.Value, error)

Value returns the value.

type TimeArray added in v1.10.0

type TimeArray []time.Time

func (*TimeArray) Scan added in v1.10.0

func (d *TimeArray) Scan(value any) error

Scan performs the operation.

func (TimeArray) Value added in v1.10.0

func (d TimeArray) Value() (driver.Value, error)

Value returns the value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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