dynamicsql

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCommand

func NewCommand() *cobra.Command

func Run

func Run(opts Options) error

Types

type IAdvancedQuery

type IAdvancedQuery interface {
	// FilterWithCondition - 使用where模板表达式
	// SELECT * FROM @@table
	// {{where}}
	//   {{if condition != ""}}
	//     @condition
	//   {{end}}
	// {{end}}
	FilterWithCondition(condition string) ([]gen.T, error)

	// FilterWithTime - 使用if/else模板表达式
	// SELECT * FROM @@table
	// {{if !start.IsZero()}}
	//   WHERE created_at > @start
	// {{end}}
	// {{if !end.IsZero()}}
	//   AND created_at < @end
	// {{end}}
	FilterWithTime(start, end time.Time) ([]gen.T, error)

	// UpdateWithSet - 使用set模板表达式
	// UPDATE @@table
	// {{set}}
	//   {{if name != ""}} name=@name, {{end}}
	//   {{if age > 0}} age=@age, {{end}}
	//   updated_at=NOW()
	// {{end}}
	// WHERE id=@id
	UpdateWithSet(name string, age int, id uint) error
}

高级查询接口 - 支持模板表达式

type IBusinessQuery

type IBusinessQuery interface {
	// GetByField - 通用字段查询
	// SELECT * FROM @@table WHERE @@field = @value
	GetByField(field, value string) (gen.T, error)

	// GetByFields - 多字段查询
	// SELECT * FROM @@table WHERE @@field1 = @value1 AND @@field2 = @value2
	GetByFields(field1, value1, field2, value2 string) ([]gen.T, error)

	// BatchUpdate - 批量更新
	// UPDATE @@table SET @@field = @value WHERE id IN @ids
	BatchUpdate(field, value string, ids []uint) error
}

业务特定查询接口 - 适用于特定业务场景

type ICommonQuery

type ICommonQuery interface {
	// GetByID
	// SELECT * FROM @@table WHERE id = @id
	GetByID(id uint) (gen.T, error)

	// GetByIDs
	// SELECT * FROM @@table WHERE id IN @ids
	GetByIDs(ids []uint) ([]gen.T, error)

	// CountRecords
	// SELECT COUNT(*) FROM @@table
	CountRecords() (int64, error)

	// Exists
	// SELECT 1 FROM @@table WHERE id = @id LIMIT 1
	Exists(id uint) (bool, error)

	// DeleteByID
	// DELETE FROM @@table WHERE id = @id
	DeleteByID(id uint) error

	// DeleteByIDs
	// DELETE FROM @@table WHERE id IN @ids
	DeleteByIDs(ids []uint) error
}

通用查询接口 - 适用于所有模型的基础CRUD操作

type IPaginationQuery

type IPaginationQuery interface {
	// GetPage
	// SELECT * FROM @@table ORDER BY @orderBy LIMIT @limit OFFSET @offset
	GetPage(offset, limit int, orderBy string) ([]gen.T, error)

	// GetPageWithCondition
	// SELECT * FROM @@table WHERE @condition ORDER BY @orderBy LIMIT @limit OFFSET @offset
	GetPageWithCondition(condition string, offset, limit int, orderBy string) ([]gen.T, error)
}

分页查询接口 - 适用于需要分页的模型

type ISearchQuery

type ISearchQuery interface {
	// Search
	// SELECT * FROM @@table WHERE @field LIKE @keyword
	Search(field, keyword string) ([]gen.T, error)

	// SearchMultiple
	// SELECT * FROM @@table WHERE @field1 LIKE @keyword OR @field2 LIKE @keyword
	SearchMultiple(field1, field2, keyword string) ([]gen.T, error)
}

搜索查询接口 - 适用于需要搜索功能的模型

type IStatusQuery

type IStatusQuery interface {
	// GetByStatus
	// SELECT * FROM @@table WHERE status = @status
	GetByStatus(status int) ([]gen.T, error)

	// UpdateStatus
	// UPDATE @@table SET status = @status WHERE id = @id
	UpdateStatus(id uint, status int) error

	// GetActive
	// SELECT * FROM @@table WHERE status = 1
	GetActive() ([]gen.T, error)

	// GetInactive
	// SELECT * FROM @@table WHERE status = 0
	GetInactive() ([]gen.T, error)
}

状态查询接口 - 适用于有状态字段的模型

type Options

type Options struct {
	Config string
}

Jump to

Keyboard shortcuts

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