define

package
v4.0.7-ai Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Debug bool

Debug flag for enabling debug mode

Functions

func RegisterFactory

func RegisterFactory(driver string, factory SQLFactory)

RegisterFactory registers a SQL factory for a specific driver

func UnregisterFactory

func UnregisterFactory(driver string)

UnregisterFactory removes a SQL factory for a specific driver

Types

type ColumnInfo

type ColumnInfo struct {
	Name            string // 列名
	Type            string // 数据库类型
	Length          int64  // 长度
	Precision       int    // 精度
	Scale           int    // 小数位数
	IsNullable      bool   // 是否可空
	IsPrimaryKey    bool   // 是否主键
	IsAutoIncrement bool   // 是否自增
	DefaultValue    string // 默认值
	Comment         string // 注释
}

ColumnInfo 列信息

type Condition

type Condition struct {
	Field      string       // Field name
	Op         OpType       // Operator type
	Value      interface{}  // Value to compare against
	Join       JoinType     // How this condition joins with others (AND/OR)
	SubConds   []*Condition // Sub-conditions for nested queries
	IsSubGroup bool         // Whether this is a sub-group of conditions
}

Condition represents a where condition

func Between added in v4.1.3

func Between(field string, start, end interface{}) *Condition

func Eq added in v4.1.3

func Eq(field string, value interface{}) *Condition

Condition builder functions

func Ge added in v4.1.3

func Ge(field string, value interface{}) *Condition

func Gt added in v4.1.3

func Gt(field string, value interface{}) *Condition

func In added in v4.1.3

func In(field string, values ...interface{}) *Condition

In creates an IN condition with variadic parameters that may include arrays

func IsNotNull added in v4.1.3

func IsNotNull(field string) *Condition

func IsNull added in v4.1.3

func IsNull(field string) *Condition

func Le added in v4.1.3

func Le(field string, value interface{}) *Condition

func Like added in v4.1.3

func Like(field string, value interface{}) *Condition

func Lt added in v4.1.3

func Lt(field string, value interface{}) *Condition

func Ne added in v4.1.3

func Ne(field string, value interface{}) *Condition

func NewCondition added in v4.1.3

func NewCondition(field string, op OpType, value interface{}) *Condition

NewCondition creates a new condition

func NotBetween added in v4.1.3

func NotBetween(field string, start, end interface{}) *Condition

func NotIn added in v4.1.3

func NotIn(field string, values ...interface{}) *Condition

NotIn creates a NOT IN condition with variadic parameters that may include arrays

func NotLike added in v4.1.3

func NotLike(field string, value interface{}) *Condition

func (*Condition) And added in v4.1.3

func (c *Condition) And(cond *Condition) *Condition

And adds a condition with AND join

func (*Condition) Or added in v4.1.3

func (c *Condition) Or(cond *Condition) *Condition

Or adds a condition with OR join

type ITableModel

type ITableModel interface {
	// TableName returns the custom table name
	TableName() string
	// CreateSql returns the custom CREATE TABLE SQL statement
	CreateSql() string
}

ITableModel defines the interface for custom table models

type JoinType added in v4.1.3

type JoinType int

JoinType represents how conditions are joined

const (
	JoinAnd JoinType = iota // AND connection
	JoinOr                  // OR connection
)

type OpType added in v4.1.3

type OpType int

OpType represents the type of condition operator

const (
	OpEq         OpType = iota // Equal
	OpNe                       // Not Equal
	OpGt                       // Greater Than
	OpGe                       // Greater Than or Equal
	OpLt                       // Less Than
	OpLe                       // Less Than or Equal
	OpLike                     // LIKE
	OpNotLike                  // NOT LIKE
	OpIn                       // IN
	OpNotIn                    // NOT IN
	OpIsNull                   // IS NULL
	OpIsNotNull                // IS NOT NULL
	OpBetween                  // BETWEEN
	OpNotBetween               // NOT BETWEEN
)

type Result

type Result struct {
	ID       int64
	Affected int64
}

Result implements sql.Result interface

func (*Result) LastInsertId

func (r *Result) LastInsertId() (int64, error)

LastInsertId returns the last inserted ID

func (*Result) RowsAffected

func (r *Result) RowsAffected() (int64, error)

RowsAffected returns the number of rows affected

type SQLFactory

type SQLFactory interface {
	// Connect creates a new database connection
	Connect(dsn string) (*sql.DB, error)

	// BuildSelect builds a SELECT query
	BuildSelect(table string, fields []string, conditions []*Condition, orderBy string, limit, offset int) (string, []interface{})

	// BuildUpdate builds an UPDATE query
	BuildUpdate(table string, fields map[string]interface{}, conditions []*Condition) (string, []interface{})

	// BuildInsert builds an INSERT query
	BuildInsert(table string, fields map[string]interface{}) (string, []interface{})

	// BuildBatchInsert builds a batch INSERT query
	BuildBatchInsert(table string, values []map[string]interface{}) (string, []interface{})

	// BuildDelete builds a DELETE query
	BuildDelete(table string, conditions []*Condition) (string, []interface{})

	// BuildCreateTable builds a CREATE TABLE query
	BuildCreateTable(table string, modelType reflect.Type) string

	// GetTableInfo 获取表信息
	GetTableInfo(db *sql.DB, tableName string) (*TableInfo, error)

	// GetTables 获取符合模式的所有表
	// pattern: 表名匹配模式,支持 * 通配符
	// 对于 PostgreSQL,pattern 可以是 schema.table 格式
	GetTables(db *sql.DB, pattern string) ([]string, error)
}

SQLFactory defines the interface for SQL generation

func GetFactory

func GetFactory(driver string) (SQLFactory, error)

GetFactory returns the SQL factory for a specific driver

type TableInfo

type TableInfo struct {
	TableName    string       // 表名
	TableComment string       // 表注释
	PrimaryKeys  []string     // 主键列表
	Columns      []ColumnInfo // 列信息
	HasDecimal   bool         // 是否包含 Decimal 类型
	HasUUID      bool         // 是否包含 UUID 类型
	HasIP        bool         // 是否包含 IP 类型
}

TableInfo 表信息

Jump to

Keyboard shortcuts

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