gormcnm

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 9 Imported by: 0

README

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

GORMCNM

gormcnm - Eliminate hardcoded strings in GORM operations with type-safe column names and compile-time validation.


Ecosystem

GORM Type-Safe Ecosystem


CHINESE README

中文说明


Language Ecosystem Comparison

Language ORM Type-Safe Columns Example
Java MyBatis Plus Example::getName wrapper.eq(Example::getName, "alice")
Python SQLAlchemy Example.name query.filter(Example.name == "alice")
Go GORMCNM cls.Name.Eq() db.Where(cls.Name.Eq("alice"))

Main Features

  • 🎯 Core Value: Avoid hardcoded column names with type-safe operations
  • 🎯 Type-Safe Column Operations: Generic ColumnName[T] type with compile-time validation
  • Zero Runtime Overhead: Type checking happens at compile time
  • 🔄 Rename-Safe Queries: IDE auto-completion and automatic rename support
  • 🌍 Rich Gorm Operations: Comprehensive comparison, range, pattern, and aggregate operations
  • 📋 Ecosystem Foundation: Powers code generation and repo pattern tools

Installation

go get github.com/yylego/gormcnm

🔥 Quick Start Example

package main

import (
	"fmt"

	"github.com/google/uuid"
	"github.com/yylego/done"
	"github.com/yylego/gormcnm"
	"github.com/yylego/neatjson/neatjsons"
	"github.com/yylego/rese"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

type Account struct {
	Username string `gorm:"primary_key;type:varchar(100);"`
	Nickname string `gorm:"column:nickname;"`
	Age      int    `gorm:"column:age;"`
}

const (
	columnUsername = gormcnm.ColumnName[string]("username")
	columnNickname = gormcnm.ColumnName[string]("nickname")
	columnAge      = gormcnm.ColumnName[int]("age")
)

func main() {
	dsn := fmt.Sprintf("file:db-%s?mode=memory&cache=shared", uuid.New().String())
	db := rese.P1(gorm.Open(sqlite.Open(dsn), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
	}))
	defer rese.F0(rese.P1(db.DB()).Close)

	//CREATE TABLE `accounts` (`username` varchar(100),`nickname` text,`age` integer,PRIMARY KEY (`username`))
	done.Done(db.AutoMigrate(&Account{}))
	//INSERT INTO `accounts` (`username`,`nickname`,`age`) VALUES ("alice","Alice",17)
	done.Done(db.Create(&Account{Username: "alice", Nickname: "Alice", Age: 17}).Error)

	//SELECT * FROM `accounts` WHERE username="alice" ORDER BY `accounts`.`username` LIMIT 1
	var account Account
	done.Done(db.Where(columnUsername.Eq("alice")).First(&account).Error)
	fmt.Println(neatjsons.S(account))

	//UPDATE `accounts` SET `nickname`="Alice-2" WHERE `username` = "alice"
	done.Done(db.Model(&account).Update(columnNickname.Kv("Alice-2")).Error)
	//SELECT * FROM `accounts` WHERE username="alice" ORDER BY `accounts`.`username` LIMIT 1
	done.Done(db.Where(columnUsername.Eq("alice")).First(&account).Error)
	fmt.Println(neatjsons.S(account))

	//UPDATE `accounts` SET `age`=18,`nickname`="Alice-3" WHERE `username` = "alice"
	done.Done(db.Model(&account).Updates(columnNickname.Kw("Alice-3").Kw(columnAge.Kv(18)).AsMap()).Error)
	//SELECT * FROM `accounts` WHERE username="alice" ORDER BY `accounts`.`username` LIMIT 1
	done.Done(db.Where(columnUsername.Eq("alice")).First(&account).Error)
	fmt.Println(neatjsons.S(account))

	//UPDATE `accounts` SET `age`=age + 1 WHERE `username` = "alice"
	done.Done(db.Model(&account).Update(columnAge.KeAdd(1)).Error)
	//SELECT * FROM `accounts` WHERE username="alice" ORDER BY `accounts`.`username` LIMIT 1
	done.Done(db.Where(columnUsername.Eq("alice")).First(&account).Error)
	fmt.Println(neatjsons.S(account))
}

⬆️ Source: Source


🔥 Advanced Queries Example

package main

import (
	"fmt"

	"github.com/google/uuid"
	"github.com/yylego/done"
	"github.com/yylego/gormcnm"
	"github.com/yylego/must"
	"github.com/yylego/rese"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

// Example is a gorm model define 3 fields(name, type, rank)
type Example struct {
	Name string `gorm:"primary_key;type:varchar(100);"`
	Type string `gorm:"column:type;"`
	Rank int    `gorm:"column:rank;"`
}

// Now define the fields enum vars(name, type rank)
const (
	columnName = gormcnm.ColumnName[string]("name")
	columnType = gormcnm.ColumnName[string]("type")
	columnRank = gormcnm.ColumnName[int]("rank")
)

func main() {
	//new db connection
	dsn := fmt.Sprintf("file:db-%s?mode=memory&cache=shared", uuid.New().String())
	db := rese.P1(gorm.Open(sqlite.Open(dsn), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
	}))
	defer rese.F0(rese.P1(db.DB()).Close)

	//create example data
	done.Done(db.AutoMigrate(&Example{}))
	done.Done(db.Save(&Example{Name: "abc", Type: "xyz", Rank: 123}).Error)
	done.Done(db.Save(&Example{Name: "aaa", Type: "xxx", Rank: 456}).Error)

	{
		//SELECT * FROM `examples` WHERE name="abc" ORDER BY `examples`.`name` LIMIT 1
		var res Example
		must.Done(db.Where("name=?", "abc").First(&res).Error)
		fmt.Println(res)
	}
	{
		//SELECT * FROM `examples` WHERE name="abc" AND type="xyz" AND rank>100 AND rank<200 ORDER BY `examples`.`name` LIMIT 1
		var res Example
		must.Done(db.Where(columnName.Eq("abc")).
			Where(columnType.Eq("xyz")).
			Where(columnRank.Gt(100)).
			Where(columnRank.Lt(200)).
			First(&res).Error)
		fmt.Println(res)
	}
}

⬆️ Source: Source


Core API

The ColumnName[T] generic type provides type-safe SQL operations:

type ColumnName[T any] string
Comparison Operations
db.Where(columnAge.Eq(25))       // =
db.Where(columnAge.Ne(25))       // !=
db.Where(columnAge.Gt(18))       // >
db.Where(columnAge.Gte(18))      // >=
db.Where(columnAge.Lt(65))       // <
db.Where(columnAge.Lte(65))      // <=
Range and Pattern Operations
Method SQL Example
Between(a, b) BETWEEN a AND b cls.Age.Between(18, 65)
In(values) IN (...) cls.ID.In([]int{1,2,3})
Like(pattern) LIKE pattern cls.Name.Like("A%")
IsNull() IS NULL cls.DeletedAt.IsNull()
IsNotNull() IS NOT NULL cls.Email.IsNotNull()
Update Operations
Method Description Example
Kv(value) Single field update db.Model(&user).Update(cls.Age.Kv(26))
Kw(value) Build update map cls.Age.Kw(26).Kw(cls.Email.Kv("new@example.com")).AsMap()
KeAdd(n) Expression: add db.Model(&user).Update(cls.Age.KeAdd(1))
KeSub(n) Expression: subtract db.Model(&user).Update(cls.Score.KeSub(10))
ColumnValueMap Usage

ColumnValueMap is used when updating multiple columns with gormrepo.Updates, gormrepo.UpdatesM, or GORM native db.Updates.

With gormrepo.Updates (requires AsMap() conversion):

repo.Updates(where, func(cls *AccountColumns) map[string]interface{} {
    return cls.
        Kw(cls.Nickname.Kv(newNickname)).
        Kw(cls.Password.Kv(newPassword)).
        AsMap() // Convert to map[string]interface{}
})

With gormrepo.UpdatesM (no AsMap() needed, recommended):

repo.UpdatesM(where, func(cls *AccountColumns) gormcnm.ColumnValueMap {
    return cls.
        Kw(cls.Nickname.Kv(newNickname)).
        Kw(cls.Password.Kv(newPassword))
    // No AsMap() needed!
})

With GORM native db.Updates:

db.Model(&account).Updates(
    cls.Nickname.Kw(newNickname).
        Kw(cls.Password.Kv(newPassword)).
        AsMap(),
)
Aggregates and Ordering
Method SQL Example
Count(alias) COUNT(column) AS alias db.Select(cls.ID.Count("total"))
Ob(direction) ORDER BY db.Order(cls.Age.Ob("asc").Ox())

🔗 Using with gormrepo

Combine gormcnm with gormrepo to get type-safe CRUD operations.

Quick Preview
// Create repo with columns
repo := gormrepo.NewRepo(&Account{}, (&Account{}).Columns())

// Concise approach with gormrepo/gormclass
repo := gormrepo.NewRepo(gormclass.Use(&Account{}))

// Type-safe queries
account, err := repo.With(ctx, db).First(func(db *gorm.DB, cls *AccountColumns) *gorm.DB {
    return db.Where(cls.Username.Eq("alice"))
})

// Find with conditions
accounts, err := repo.With(ctx, db).Find(func(db *gorm.DB, cls *AccountColumns) *gorm.DB {
    return db.Where(cls.Age.Gte(18)).Where(cls.Age.Lte(65))
})

// Type-safe updates
err := repo.With(ctx, db).Updates(
    func(db *gorm.DB, cls *AccountColumns) *gorm.DB {
        return db.Where(cls.ID.Eq(1))
    },
    func(cls *AccountColumns) map[string]interface{} {
        return cls.Kw(cls.Age.Kv(26)).Kw(cls.Nickname.Kv("NewNick")).AsMap()
    },
)

👉 See gormrepo to get complete documentation and more examples.


Extension Packages

This package includes extension sub-packages for specialized database operations:

  • 📦 gormcnmjson - Type-safe JSON column operations (SQLite JSON functions support)

Future Extensions (planned):

Package Purpose Status
gormcnmtext Text search operations Planned
gormcnmdate Date/time operations Planned
gormcnmmath Math operations Planned

Explore the complete GORM ecosystem with these integrated packages:

Core Ecosystem
  • gormcnm - GORM foundation providing type-safe column operations and statement construction (this project)
  • gormcngen - Code generation tool using AST, enables type-safe GORM operations
  • gormrepo - Repo pattern implementation with GORM best practices
  • gormmom - Native language GORM tag generation engine with smart column naming
  • gormzhcn - Complete Chinese programming interface with GORM

Each package targets different aspects of GORM development, from localization to type-safe operations and code generation.


📄 License

MIT License - see LICENSE.


💬 Contact & Feedback

Contributions are welcome! Report bugs, suggest features, and contribute code:

  • 🐛 Mistake reports? Open an issue on GitHub with reproduction steps
  • 💡 Fresh ideas? Create an issue to discuss
  • 📖 Documentation confusing? Report it so we can improve
  • 🚀 Need new features? Share the use cases to help us understand requirements
  • Performance issue? Help us optimize through reporting slow operations
  • 🔧 Configuration problem? Ask questions about complex setups
  • 📢 Follow project progress? Watch the repo to get new releases and features
  • 🌟 Success stories? Share how this package improved the workflow
  • 💬 Feedback? We welcome suggestions and comments

🔧 Development

New code contributions, follow this process:

  1. Fork: Fork the repo on GitHub (using the webpage UI).
  2. Clone: Clone the forked project (git clone https://github.com/yourname/repo-name.git).
  3. Navigate: Navigate to the cloned project (cd repo-name)
  4. Branch: Create a feature branch (git checkout -b feature/xxx).
  5. Code: Implement the changes with comprehensive tests
  6. Testing: (Golang project) Ensure tests pass (go test ./...) and follow Go code style conventions
  7. Documentation: Update documentation to support client-facing changes
  8. Stage: Stage changes (git add .)
  9. Commit: Commit changes (git commit -m "Add feature xxx") ensuring backward compatible code
  10. Push: Push to the branch (git push origin feature/xxx).
  11. PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.

Please ensure tests pass and include relevant documentation updates.


🌟 Support

Welcome to contribute to this project via submitting merge requests and reporting issues.

Project Support:

  • Give GitHub stars if this project helps you
  • 🤝 Share with teammates and (golang) programming friends
  • 📝 Write tech blogs about development tools and workflows - we provide content writing support
  • 🌟 Join the ecosystem - committed to supporting open source and the (golang) development scene

Have Fun Coding with this package! 🎉🎉🎉


📈 GitHub Stars

Starring

Documentation

Overview

Package gormcnm provides type-safe column name operations with comprehensive SQL queries support Auto handles comparisons, equivalence checks, range queries, pattern matching, and NULL value operations Supports column aliases, raw column names, and dynamic SQL generation with compile-time type-safe features

gormcnm 包提供类型安全的列名操作,具有全面的 SQL 查询支持 自动处理比较、等值检查、范围查询、模式匹配和 NULL 值操作 支持列别名、原始列名和动态 SQL 生成,具有编译时类型安全特性

Package gormcnm provides advanced column operations including math expressions and aggregate functions Auto creates GORM expressions with ExprAdd, ExprSub, ExprMul, ExprDiv and aggregate operations Supports building complex SQL operations with type-safe column expressions and GORM integration

gormcnm 包提供高级列操作,包括数学表达式和聚合函数 自动创建 GORM 表达式,包含 ExprAdd、ExprSub、ExprMul、ExprDiv 和聚合操作 支持使用类型安全的列表达式构建复杂 SQL 操作,具有 GORM 集成

Package gormcnm provides GORM scope function type definitions, enabling custom GORM conditions Auto enables type-safe scope functions that integrate with GORM's db.Scopes() method Supports building reusable where modifiers and composable database operations

gormcnm 提供 GORM 作用域函数类型定义,用于自定义查询条件 自动启用类型安全的作用域函数,与 GORM 的 db.Scopes() 方法集成 支持构建可重用的查询修饰符和可组合的数据库操作

Package gormcnm provides column name creation and decoration operations with flexible patterns Auto creates ColumnName instances with type inference and customizable decoration strategies Supports plain names, table-prefixed names, and custom transformation logic

gormcnm 包提供列名创建和装饰操作,具有灵活的模式 自动创建 ColumnName 实例,包含类型推断和可定制的装饰策略 支持普通名称、表前缀名称和自定义转换逻辑

Package gormcnm provides GORM clause operations for type-safe column assignments Auto creates clause.Column and clause.Assignment instances with table and alias support Supports building complex SQL clauses with proper column qualification and raw SQL handling

gormcnm 提供 GORM 子句操作,实现类型安全的列赋值 自动创建 clause.Column 和 clause.Assignment 实例,支持表名和别名 支持构建复杂的 SQL 子句,具备正确的列限定和原始 SQL 处理

Package gormcnm provides common column operation patterns and utilities functions Auto exposes ColumnOperationClass with queries conditions, select statements, and JOIN operations Supports building reusable operation patterns with scope management and variable tracking

gormcnm 包提供常用列操作模式和实用函数 自动暴露 ColumnOperationClass,包含查询条件、select 语句和 JOIN 操作 支持构建可重用的操作模式,具有作用域管理和变量追踪

Package gormcnm provides ORDER BY statement building operations with flexible sorting patterns Auto creates OrderByBottle instances with ASC/DESC direction support and combination logic Supports building complex sorting clauses with multiple columns and GORM integration

gormcnm 包提供 ORDER BY 语句构建操作,具有灵活的排序模式 自动创建 OrderByBottle 实例,支持 ASC/DESC 方向和组合逻辑 支持构建多列的复杂排序子句,具有 GORM 集成

Package gormcnm provides COALESCE and IFNULL operations for NULL-safe SQL queries Auto handles NULL values in aggregate functions using COALESCE (standard) or IFNULL (MySQL) Supports SUM, COUNT, AVG, MAX, MIN with automatic NULL value protection

gormcnm 提供 COALESCE 和 IFNULL 操作,实现 NULL 安全的 SQL 查询 自动使用 COALESCE(标准)或 IFNULL(MySQL)处理聚合函数中的 NULL 值 支持 SUM、COUNT、AVG、MAX、MIN,具备自动 NULL 值保护

Package gormcnm provides conjunction operations to build complex WHERE clauses Auto combines multiple conditions using AND, OR, NOT boolean operators Supports nested conditions and flexible queries composition with type-safe SQL generation

gormcnm 提供查询语句连接词操作,用于构建复杂的 WHERE 子句 自动使用 AND、OR、NOT 逻辑运算符组合多个条件 支持嵌套条件和灵活的查询组合,具备类型安全的 SQL 生成

Package gormcnm provides conjunction operations with statement and arguments binding Auto handles complex WHERE clauses with argument binding and boolean operators Supports building dynamic queries with type-safe argument management and GORM integration

gormcnm 提供查询连接词操作,具备语句和参数绑定功能 自动处理复杂的 WHERE 子句,包含参数绑定和逻辑运算符 支持构建动态查询,具备类型安全的参数管理和 GORM 集成

Package gormcnm provides SELECT statement building operations for custom column selection Auto constructs SELECT clauses with column combinations, aliases, and aggregate functions Supports building complex SELECT queries with type-safe column management and GORM integration

gormcnm 提供 SELECT 语句构建操作,用于自定义列选择 自动构建 SELECT 子句,包含列组合、别名和聚合函数 支持构建复杂的 SELECT 操作,具备类型安全的列管理和 GORM 集成

Package gormcnm provides statement and arguments tuple handling in GORM queries operations Auto manages SQL statements with argument binding and type conversion Supports driver.Valuer interface implementation, enabling custom types in GORM WHERE clauses

gormcnm 提供语句和参数元组处理,用于 GORM 查询操作 自动管理 SQL 语句及参数绑定和类型转换 支持 driver.Valuer 接口实现,用于 GORM WHERE 子句中的自定义类型

Package gormcnm provides table-qualified column operations to support multi-table data retrieval Auto creates columns with table prefixes to facilitate JOIN operations and complex data retrieval Supports building complete column names with table association

gormcnm 提供表限定列操作,用于多表查询 自动创建带表前缀的列,用于 JOIN 操作和复杂查询 支持构建完全限定的列名,具备表关联功能

Package gormcnm provides table JOIN operations to build multi-table data relationships Auto creates LEFT JOIN, INNER JOIN, and custom JOIN operations with ON conditions Supports building complex table relationships with type-safe join clause construction

gormcnm 提供表 JOIN 操作,用于构建多表查询关系 自动创建 LEFT JOIN、INNER JOIN 和自定义 JOIN 操作,包含 ON 条件 支持构建复杂的表关系,具备类型安全的连接子句构建

Package gormcnm provides column-value map operations for GORM update and batch operations Auto manages column-value mappings for Updates and UpdateColumns operations Supports building dynamic update maps with type-safe column assignments

gormcnm 提供列值映射操作,用于 GORM 更新和批量操作 自动管理 Updates 和 UpdateColumns 操作的列值映射 支持构建动态更新映射,具备类型安全的列赋值

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClauseColumn

type ClauseColumn[TYPE any] clause.Column

ClauseColumn represents a column with additional properties such as table, alias, and raw flag. ClauseColumn 表示一个具有额外属性(如表名、别名和 raw 标志)的列。

func (*ClauseColumn[TYPE]) Assignment

func (clauseColumn *ClauseColumn[TYPE]) Assignment(value TYPE) clause.Assignment

Assignment returns a GORM clause.Assignment, which is used to assign a value to a column. Assignment 返回一个 GORM 的 clause.Assignment,用于将值赋给列。

func (*ClauseColumn[TYPE]) Column

func (clauseColumn *ClauseColumn[TYPE]) Column() clause.Column

Column returns a GORM clause.Column, which represents a column in a SQL statement. Column 返回一个 GORM 的 clause.Column,表示 SQL 语句中的一个列。

func (*ClauseColumn[TYPE]) WithAlias

func (clauseColumn *ClauseColumn[TYPE]) WithAlias(alias string) *ClauseColumn[TYPE]

WithAlias sets the alias for the ClauseColumn and returns the updated ClauseColumn. WithAlias 为 ClauseColumn 设置别名并返回更新后的 ClauseColumn。

func (*ClauseColumn[TYPE]) WithRaw

func (clauseColumn *ClauseColumn[TYPE]) WithRaw(raw bool) *ClauseColumn[TYPE]

WithRaw sets the raw flag for the ClauseColumn and returns the updated ClauseColumn. WithRaw 为 ClauseColumn 设置 raw 标志并返回更新后的 ClauseColumn。

func (*ClauseColumn[TYPE]) WithTable

func (clauseColumn *ClauseColumn[TYPE]) WithTable(tableName string) *ClauseColumn[TYPE]

WithTable sets the table name for the ClauseColumn and returns the updated ClauseColumn. WithTable 为 ClauseColumn 设置表名并返回更新后的 ClauseColumn。

type CoalesceNonNullGuardian

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

CoalesceNonNullGuardian provides SQL aggregate functions with NULL value protection Auto handles NULL values using COALESCE or IFNULL functions to provide default values CoalesceNonNullGuardian 提供带有 NULL 值保护的 SQL 聚合函数 自动使用 COALESCE 或 IFNULL 函数处理 NULL 值以提供默认值

func NewCoalesceNonNullGuardian

func NewCoalesceNonNullGuardian(methodName string, columnName string) *CoalesceNonNullGuardian

NewCoalesceNonNullGuardian creates a new CoalesceNonNullGuardian with specified method and column NewCoalesceNonNullGuardian 使用指定的方法和列名创建新的 CoalesceNonNullGuardian

func (*CoalesceNonNullGuardian) AvgStmt

func (qs *CoalesceNonNullGuardian) AvgStmt(alias string) string

AvgStmt generates an SQL statement to calculate the average value of the column, using 0 as the default value. AvgStmt 生成一个 SQL 语句,计算列的平均值,默认值为 0。

func (*CoalesceNonNullGuardian) MaxStmt

func (qs *CoalesceNonNullGuardian) MaxStmt(alias string) string

MaxStmt generates an SQL statement to retrieve the maximum value of the column, using 0 as the default value. MaxStmt 生成一个 SQL 语句,检索列的最大值,默认值为 0。

func (*CoalesceNonNullGuardian) MinStmt

func (qs *CoalesceNonNullGuardian) MinStmt(alias string) string

MinStmt generates an SQL statement to retrieve the minimum value of the column, using 0 as the default value. MinStmt 生成一个 SQL 语句,检索列的最小值,默认值为 0。

func (*CoalesceNonNullGuardian) Stmt

func (qs *CoalesceNonNullGuardian) Stmt(sfn string, dfv string, alias string) string

Stmt generates an SQL statement for the COALESCE or IFNULL function with the given function and default value. Stmt 生成一个 SQL 语句,包含 COALESCE 或 IFNULL 函数,并指定默认值。

func (*CoalesceNonNullGuardian) SumStmt

func (qs *CoalesceNonNullGuardian) SumStmt(alias string) string

SumStmt generates an SQL statement to calculate the sum of the column, using 0 as the default value. SumStmt 生成一个 SQL 语句,计算列的总和,默认值为 0。

type ColumnName

type ColumnName[TYPE any] string

ColumnName represents a generic column name used in SQL queries ColumnName 表示一个通用的列名 可用于 SQL 查询

func Cmn

func Cmn[T any](v T, name string, decoration ColumnNameDecoration) ColumnName[T]

Cmn creates a ColumnName with decoration applied to the name Cmn 创建一个对名称应用装饰的 ColumnName

func Cnm

func Cnm[T any](v T, name string) ColumnName[T]

Cnm creates a ColumnName using the type inferred from the value argument Cnm 使用从值参数推断出的类型创建 ColumnName

func New

func New[T any](name string) ColumnName[T]

New creates a new ColumnName with the specified type and name New 创建一个带有指定类型和名称的新 ColumnName

func (ColumnName[TYPE]) AsAlias

func (columnName ColumnName[TYPE]) AsAlias(alias string) string

AsAlias returns the column name with applied alias. AsAlias 返回带有别名的列名。

func (ColumnName[TYPE]) AsName

func (columnName ColumnName[TYPE]) AsName(alias ColumnName[TYPE]) string

AsName generates a SQL alias when using the specified ColumnName as the alias. AsName 使用指定的 ColumnName 作为别名生成列的 SQL 别名。

func (ColumnName[TYPE]) Avg

func (columnName ColumnName[TYPE]) Avg(alias string) string

Avg creates an AVG aggregate statement on the column. Avg: 创建一个 AVG 聚合查询,计算列值的平均值。

func (ColumnName[TYPE]) Between

func (columnName ColumnName[TYPE]) Between(arg1, arg2 TYPE) (string, TYPE, TYPE)

Between creates a SQL statement to check if the column's value is between two given values. Auto provides most intuitive function name when doing range queries, enhancing the development experience Developers often search the "Between" keyword when looking up BETWEEN SQL operations

Between 创建一个 SQL 语句来判断列的值是否介于两个给定的值之间。 自动提供范围查询最直观的函数名,提升开发体验 开发者查找 BETWEEN SQL 操作时通常搜索 "Between"

func (ColumnName[TYPE]) BetweenAND

func (columnName ColumnName[TYPE]) BetweenAND(arg1, arg2 TYPE) (string, TYPE, TYPE)

BetweenAND creates a SQL statement to check if the column's value is between two given values. BetweenAND 创建一个 SQL 语句来判断列的值是否介于两个给定的值之间。

func (ColumnName[TYPE]) BetweenAnd

func (columnName ColumnName[TYPE]) BetweenAnd(arg1, arg2 TYPE) (string, TYPE, TYPE)

BetweenAnd creates a SQL statement to check if the column's value is between two given values. BetweenAnd 创建一个 SQL 语句来判断列的值是否介于两个给定的值之间。

func (ColumnName[TYPE]) COALESCE

func (columnName ColumnName[TYPE]) COALESCE() *CoalesceNonNullGuardian

COALESCE creates a COALESCE function wrapper for handling NULL values in SQL queries Auto uses SQL standard COALESCE function, supported by most database systems COALESCE 为处理 SQL 查询中的 NULL 值创建 COALESCE 函数包装器 自动使用 SQL 标准的 COALESCE 函数,被大多数数据库系统支持

func (ColumnName[TYPE]) Clause

func (columnName ColumnName[TYPE]) Clause() *ClauseColumn[TYPE]

Clause creates a ClauseColumn of the ColumnName instance. Clause 给 ColumnName 实例创建一个 ClauseColumn。

func (ColumnName[TYPE]) ClauseWithTable

func (columnName ColumnName[TYPE]) ClauseWithTable(tableName string) *ClauseColumn[TYPE]

ClauseWithTable creates a ClauseColumn with a specified table name. ClauseWithTable 创建一个带有指定表名的 ClauseColumn。

func (ColumnName[TYPE]) ColumnCondition

func (columnName ColumnName[TYPE]) ColumnCondition(op string) QsConjunction

ColumnCondition creates a condition when using the provided op (e.g., '=', '>', etc.) with this column. ColumnCondition: 使用提供的运算符(例如 '=', '>', 等)为列创建条件。

func (ColumnName[TYPE]) ColumnConditionWithValue

func (columnName ColumnName[TYPE]) ColumnConditionWithValue(op string, x TYPE) *QxConjunction

ColumnConditionWithValue creates a condition with an op and a value when using this column, designed to build complex queries. ColumnConditionWithValue: 创建带有运算符和值的列条件,用于构建复杂的查询。

func (ColumnName[TYPE]) ColumnKeyAndValue

func (columnName ColumnName[TYPE]) ColumnKeyAndValue(x TYPE) (string, TYPE)

ColumnKeyAndValue returns a column-value mapping, works with GORM's Update function. ColumnKeyAndValue: 返回键值对,适用于 GORM 的 Update 函数。

func (ColumnName[TYPE]) Count

func (columnName ColumnName[TYPE]) Count(alias string) string

Count creates a COUNT queries statement on the column, excluding NULL values. Count: 创建一个 COUNT 查询,只统计非 NULL 值的列。

func (ColumnName[TYPE]) CountDistinct

func (columnName ColumnName[TYPE]) CountDistinct(alias string) string

CountDistinct creates a COUNT DISTINCT queries statement on the given column, skipping NULL values in the count. CountDistinct: 创建一个 COUNT DISTINCT 查询,用于给定列,跳过 NULL 值。

func (ColumnName[TYPE]) CreateColumnValueMap

func (columnName ColumnName[TYPE]) CreateColumnValueMap(x TYPE) ColumnValueMap

CreateColumnValueMap creates a map with a single column-value mapping. CreateColumnValueMap: 创建一个包含单个键值对的 map。

func (ColumnName[TYPE]) Eq

func (columnName ColumnName[TYPE]) Eq(x TYPE) (string, TYPE)

Eq creates a SQL statement to check if the column equals a given value. Most often used method when doing equivalence comparisons with type-safe operations and clean syntax Auto generates "column=?" pattern with param binding when using GORM WHERE operations Core building block when constructing database queries and the foundation of type-safe SQL

With GORM:

db.Where("name = ?", "abc").Where("rank = ?", 100)

With Eq:

const (
	columnName = ColumnName[string]("name")  // Demo definition here
	columnRank = ColumnName[int]("rank")     // Use github.com/yylego/gormcngen auto generation in projects
)
db.Where(columnName.Eq("abc")).Where(columnRank.Eq(100))

Both generate: "WHERE name = ? AND rank = ?" Benefits: Type-safe operations, no typos, IDE autocompletion, refactoring support

Eq 创建一个 SQL 语句来判断列是否等于给定的值。 最常用的相等比较方法,具有类型安全和简洁语法 自动生成 "column=?" 模式并为 GORM WHERE 操作绑定参数 所有数据库查询的基础构建块,类型安全 SQL 的基石

传统写法:

db.Where("name = ?", "abc").Where("rank = ?", 100)

使用 Eq:

const (
	columnName = ColumnName[string]("name")  // 演示用定义
	columnRank = ColumnName[int]("rank")     // 项目中使用 github.com/yylego/gormcngen 自动生成
)
db.Where(columnName.Eq("abc")).Where(columnRank.Eq(100))

都生成:"WHERE name = ? AND rank = ?" 优势:类型安全、无拼写错误、IDE 自动补全、重构支持

func (ColumnName[TYPE]) ExprAdd

func (columnName ColumnName[TYPE]) ExprAdd(v TYPE) clause.Expr

ExprAdd creates a GORM expression to add a value to the column. ExprAdd: 创建一个 GORM 表达式,将一个值加到列中。

func (ColumnName[TYPE]) ExprConcat

func (columnName ColumnName[TYPE]) ExprConcat(v TYPE) clause.Expr

ExprConcat creates a GORM expression to concatenate a string to the column. ExprConcat: 创建一个 GORM 表达式,将字符串连接到列。

func (ColumnName[TYPE]) ExprDiv

func (columnName ColumnName[TYPE]) ExprDiv(v TYPE) clause.Expr

ExprDiv creates a GORM expression to divide the column by a value. ExprDiv: 创建一个 GORM 表达式,将列除以一个值。

func (ColumnName[TYPE]) ExprMul

func (columnName ColumnName[TYPE]) ExprMul(v TYPE) clause.Expr

ExprMul creates a GORM expression when doing multiplication with the column and a value. ExprMul: 创建一个 GORM 表达式,将列乘以一个值。

func (ColumnName[TYPE]) ExprReplace

func (columnName ColumnName[TYPE]) ExprReplace(oldValue, newValue TYPE) clause.Expr

ExprReplace creates a GORM expression to replace text in the column. ExprReplace: 创建一个 GORM 表达式,替换列中的文本。

func (ColumnName[TYPE]) ExprSub

func (columnName ColumnName[TYPE]) ExprSub(v TYPE) clause.Expr

ExprSub creates a GORM expression to subtract a value from the column. ExprSub: 创建一个 GORM 表达式,从列中减去一个值。

func (ColumnName[TYPE]) Gt

func (columnName ColumnName[TYPE]) Gt(x TYPE) (string, TYPE)

Gt creates a SQL statement to check if the column is more than a given value. Gt 创建一个 SQL 语句来判断列是否大于给定的值。

func (ColumnName[TYPE]) Gte

func (columnName ColumnName[TYPE]) Gte(x TYPE) (string, TYPE)

Gte creates a SQL statement to check if the column value at least equals the given value. Gte 创建一个 SQL 语句来判断列是否大于等于给定的值。

func (ColumnName[TYPE]) IFNULLFN

func (columnName ColumnName[TYPE]) IFNULLFN() *CoalesceNonNullGuardian

IFNULLFN creates an IFNULL function wrapper for MySQL-specific NULL handling MySQL-specific function, may not be supported in other database systems IFNULLFN 为 MySQL 特定的 NULL 处理创建 IFNULL 函数包装器 MySQL 特定函数,在其他数据库系统中可能不受支持

func (ColumnName[TYPE]) In

func (columnName ColumnName[TYPE]) In(x []TYPE) (string, []TYPE)

In creates a SQL statement to check if the column's value is in a given list of values. In 创建一个 SQL 语句来判断列的值是否在给定的值列表中。

func (ColumnName[TYPE]) IsFALSE

func (columnName ColumnName[TYPE]) IsFALSE() string

IsFALSE creates a SQL statement to check if the column's value is FALSE. IsFALSE 创建一个 SQL 语句来判断列的值是否为 FALSE。

func (ColumnName[TYPE]) IsFalse

func (columnName ColumnName[TYPE]) IsFalse() string

IsFalse creates a SQL statement to check if the column's value is FALSE. IsFalse 创建一个 SQL 语句来判断列的值是否为 FALSE。

func (ColumnName[TYPE]) IsNULL

func (columnName ColumnName[TYPE]) IsNULL() string

IsNULL creates a SQL statement to check if the column is NULL. IsNULL 创建一个 SQL 语句来判断列是否为 NULL。

func (ColumnName[TYPE]) IsNotNULL

func (columnName ColumnName[TYPE]) IsNotNULL() string

IsNotNULL creates a SQL statement to check if the column is not NULL. IsNotNULL 创建一个 SQL 语句来判断列是否不为 NULL。

func (ColumnName[TYPE]) IsNotNull

func (columnName ColumnName[TYPE]) IsNotNull() string

IsNotNull creates a SQL statement to check if the column is not NULL. IsNotNull 创建一个 SQL 语句来判断列是否不为 NULL。

func (ColumnName[TYPE]) IsNull

func (columnName ColumnName[TYPE]) IsNull() string

IsNull creates a SQL statement to check if the column is NULL. IsNull 创建一个 SQL 语句来判断列是否为 NULL。

func (ColumnName[TYPE]) IsTRUE

func (columnName ColumnName[TYPE]) IsTRUE() string

IsTRUE creates a SQL statement to check if the column's value is TRUE. IsTRUE 创建一个 SQL 语句来判断列的值是否为 TRUE。

func (ColumnName[TYPE]) IsTrue

func (columnName ColumnName[TYPE]) IsTrue() string

IsTrue creates a SQL statement to check if the column's value is TRUE. IsTrue 创建一个 SQL 语句来判断列的值是否为 TRUE。

func (ColumnName[TYPE]) KeAdd

func (columnName ColumnName[TYPE]) KeAdd(x TYPE) (string, clause.Expr)

KeAdd is used in updates where a value is added to the field (e.g., incrementing a value). Returns (columnName, gorm.Expr) tuple to use in UpdateColumns operations.

With Gorm:

db.UpdateColumns(map[string]interface{}{"price": gorm.Expr("price + ?", 10)})

With KeAdd:

db.UpdateColumns(map[string]interface{}{cls.Price.KeAdd(10)})

Both generate: "UPDATE ... SET price = price + 10"

KeAdd: 用于更新字段时,将一个值加到字段上(例如递增一个值)。 返回 (列名, gorm.Expr) 元组,用于 UpdateColumns 操作。

传统写法:

db.UpdateColumns(map[string]interface{}{"price": gorm.Expr("price + ?", 10)})

使用 KeAdd:

db.UpdateColumns(map[string]interface{}{cls.Price.KeAdd(10)})

都生成:"UPDATE ... SET price = price + 10"

func (ColumnName[TYPE]) KeConcat

func (columnName ColumnName[TYPE]) KeConcat(x TYPE) (string, clause.Expr)

KeConcat is used in updates where a string is concatenated to the field (e.g., appending text). KeConcat: 用于更新字段时,将字符串连接到字段(例如追加文本)。

func (ColumnName[TYPE]) KeDiv

func (columnName ColumnName[TYPE]) KeDiv(x TYPE) (string, clause.Expr)

KeDiv is used in updates where a field is divided by a value (e.g., splitting a value). KeDiv: 用于更新字段时,将字段除以一个值(例如分割一个值)。

func (ColumnName[TYPE]) KeExp

func (columnName ColumnName[TYPE]) KeExp(x clause.Expr) (string, clause.Expr)

KeExp extends Kv by returning a column-expression mapping, works with GORM's Update function with expressions. KeExp: 扩展 Kv,返回键表达式对,适用于 GORM 的 Update 函数,支持表达式。

func (ColumnName[TYPE]) KeMul

func (columnName ColumnName[TYPE]) KeMul(x TYPE) (string, clause.Expr)

KeMul is used in updates where a field is multiplied by a value (e.g., scaling a value). KeMul: 用于更新字段时,将字段乘以一个值(例如缩放一个值)。

func (ColumnName[TYPE]) KeReplace

func (columnName ColumnName[TYPE]) KeReplace(oldValue, newValue TYPE) (string, clause.Expr)

KeReplace is used in updates where text in the field is replaced (e.g., updating patterns). KeReplace: 用于更新字段时,替换字段中的文本(例如更新模式)。

func (ColumnName[TYPE]) KeSub

func (columnName ColumnName[TYPE]) KeSub(x TYPE) (string, clause.Expr)

KeSub is used in updates where a value is subtracted from the field (e.g., decrementing a value). Returns (columnName, gorm.Expr) tuple to use in UpdateColumns operations.

With Gorm:

db.UpdateColumns(map[string]interface{}{"stock": gorm.Expr("stock - ?", 1)})

With KeSub:

db.UpdateColumns(map[string]interface{}{cls.Stock.KeSub(1)})

Both generate: "UPDATE ... SET stock = stock - 1"

KeSub: 用于更新字段时,将一个值从字段中减去(例如递减一个值)。 返回 (列名, gorm.Expr) 元组,用于 UpdateColumns 操作。

传统写法:

db.UpdateColumns(map[string]interface{}{"stock": gorm.Expr("stock - ?", 1)})

使用 KeSub:

db.UpdateColumns(map[string]interface{}{cls.Stock.KeSub(1)})

都生成:"UPDATE ... SET stock = stock - 1"

func (ColumnName[TYPE]) Kv

func (columnName ColumnName[TYPE]) Kv(x TYPE) (string, TYPE)

Kv returns a column-value mapping, works with GORM's Update function. Kv: 返回键值对,适用于 GORM 的 Update 函数。

func (ColumnName[TYPE]) Kw

func (columnName ColumnName[TYPE]) Kw(x TYPE) ColumnValueMap

Kw creates a map with a single column-value mapping. Kw: 创建一个包含单个键值对的 map。

func (ColumnName[TYPE]) Like

func (columnName ColumnName[TYPE]) Like(x TYPE) (string, TYPE)

Like creates a SQL statement to check if the column's value matches a given pattern. Like 创建一个 SQL 语句来判断列的值是否匹配给定的模式。

func (ColumnName[TYPE]) Lt

func (columnName ColumnName[TYPE]) Lt(x TYPE) (string, TYPE)

Lt creates a SQL statement to check if the column is less than a given value. Lt 创建一个 SQL 语句来判断列是否小于给定的值。

func (ColumnName[TYPE]) Lte

func (columnName ColumnName[TYPE]) Lte(x TYPE) (string, TYPE)

Lte creates a SQL statement to check if the column value at most equals the given value. Lte 创建一个 SQL 语句来判断列是否小于等于给定的值。

func (ColumnName[TYPE]) Max

func (columnName ColumnName[TYPE]) Max(alias string) string

Max creates a MAX aggregate statement on the column. Max: 创建一个 MAX 聚合查询,获取列的最大值。

func (ColumnName[TYPE]) Min

func (columnName ColumnName[TYPE]) Min(alias string) string

Min creates a MIN aggregate statement on the column. Min: 创建一个 MIN 聚合查询,获取列的最小值。

func (ColumnName[TYPE]) Name

func (columnName ColumnName[TYPE]) Name() string

Name returns the raw column name. Name 返回原始的列名。

func (ColumnName[TYPE]) Ne

func (columnName ColumnName[TYPE]) Ne(x TYPE) (string, TYPE)

Ne creates a SQL statement to check if the column is not the same as a given value. Ne 创建一个 SQL 语句来判断列是否不等于给定的值。

func (ColumnName[TYPE]) NotBetween

func (columnName ColumnName[TYPE]) NotBetween(arg1, arg2 TYPE) (string, TYPE, TYPE)

NotBetween creates a SQL statement to check if the column's value is NOT between two given values. Auto provides the counterpart to Between operation, completing range queries functions Most often used to exclude specific value ranges from the results

NotBetween 创建一个 SQL 语句来判断列的值是否不在两个给定的值之间。 自动提供与 Between 操作对应的反向操作,完善范围查询功能 最常用于从查询结果中排除特定的值范围

func (ColumnName[TYPE]) NotEq

func (columnName ColumnName[TYPE]) NotEq(x TYPE) (string, TYPE)

NotEq creates a SQL statement to check if the column is not the same as a given value. NotEq 创建一个 SQL 语句来判断列是否不等于给定的值。

func (ColumnName[TYPE]) NotIn

func (columnName ColumnName[TYPE]) NotIn(x []TYPE) (string, []TYPE)

NotIn creates a SQL statement to check if the column's value is not in a given list of values. NotIn 创建一个 SQL 语句来判断列的值是否不在给定的值列表中。

func (ColumnName[TYPE]) NotLike

func (columnName ColumnName[TYPE]) NotLike(x TYPE) (string, TYPE)

NotLike creates a SQL statement to check if the column's value does not match a given pattern. NotLike 创建一个 SQL 语句来判断列的值是否不匹配给定的模式。

func (ColumnName[TYPE]) Ob

func (columnName ColumnName[TYPE]) Ob(direction string) OrderByBottle

Ob creates an ordering clause with the specified direction (ASC or DESC) when using this column. Ob: 创建一个带有指定方向(ASC 或 DESC)的 ORDER BY 子句。

func (ColumnName[TYPE]) OnEq

func (columnName ColumnName[TYPE]) OnEq(name ColumnName[TYPE]) string

OnEq creates a SQL statement to check if the column matches a second column in an ON clause. OnEq 创建一个 SQL 语句来判断列是否在 ON 子句中等于另一列。

func (ColumnName[TYPE]) OnNe

func (columnName ColumnName[TYPE]) OnNe(name ColumnName[TYPE]) string

OnNe creates a SQL statement to check if the column differs from a second column in an ON clause. OnNe 创建一个 SQL 语句来判断列是否在 ON 子句中不等于另一列。

func (ColumnName[TYPE]) Op

func (columnName ColumnName[TYPE]) Op(op string, x TYPE) (string, TYPE)

Op creates a SQL statement with an op and a param. Returns both SQL fragment and param value as a tuple used in GORM operations Auto handles param binding and type-safe operations when using custom ops Most flexible method when using custom SQL operations with param values

With GORM:

db.Where("name = ?", "abc").Where("rank > ?", 100)

With Op:

const (
	columnName = ColumnName[string]("name")  // Demo definition here
	columnRank = ColumnName[int]("rank")     // Use github.com/yylego/gormcngen auto generation in projects
)
db.Where(columnName.Op("= ?", "abc")).Where(columnRank.Op("> ?", 100))

Both generate: "WHERE name = ? AND rank > ?"

Op 创建一个带有操作符和参数的 SQL 语句。 返回 SQL 片段和参数值元组,用于 GORM 操作 自动处理参数绑定和自定义操作符的类型安全 最灵活的带参数值自定义 SQL 操作方法

传统写法:

db.Where("name = ?", "abc").Where("rank > ?", 100)

使用 Op:

const (
	columnName = ColumnName[string]("name")  // 演示用定义
	columnRank = ColumnName[int]("rank")     // 项目中使用 github.com/yylego/gormcngen 自动生成
)
db.Where(columnName.Op("= ?", "abc")).Where(columnRank.Op("> ?", 100))

都生成:"WHERE name = ? AND rank > ?"

func (ColumnName[TYPE]) OrderByBottle

func (columnName ColumnName[TYPE]) OrderByBottle(direction string) OrderByBottle

OrderByBottle creates an ordering clause with the given direction (ASC or DESC) when using this column. OrderByBottle: 创建一个带有给定方向(ASC 或 DESC)的 ORDER BY 子句。

func (ColumnName[TYPE]) Qc

func (columnName ColumnName[TYPE]) Qc(op string) QsConjunction

Qc creates a condition when using the provided op (e.g., '=', '>', etc.) with this column. Qc: 使用提供的运算符(例如 '=', '>', 等)为列创建条件。

func (ColumnName[TYPE]) Qs

func (columnName ColumnName[TYPE]) Qs(op string) string

Qs creates a SQL statement with a given op. Returns the SQL fragment without param placeholders, used in raw SQL construction Most often used when building complex WHERE clauses with multiple conditions

With GORM:

db.Where("name = ?", "abc").Where("type = ?", "xyz")

With Qs:

const (
	columnName = ColumnName[string]("name")  // Demo definition here
	columnType = ColumnName[string]("type")  // Use github.com/yylego/gormcngen auto generation in projects
)
db.Where(columnName.Qs("= ?"), "abc").Where(columnType.Qs("= ?"), "xyz")

Both generate: "WHERE name = ? AND type = ?"

Qs 创建一个带有指定操作符的 SQL 语句。 返回不带参数占位符的 SQL 片段,用于原始 SQL 构建 最常用于构建带有多个条件的复杂 WHERE 子句

传统写法:

db.Where("name = ?", "abc").Where("type = ?", "xyz")

使用 Qs:

const (
	columnName = ColumnName[string]("name")  // 演示用定义
	columnType = ColumnName[string]("type")  // 项目中使用 github.com/yylego/gormcngen 自动生成
)
db.Where(columnName.Qs("= ?"), "abc").Where(columnType.Qs("= ?"), "xyz")

都生成:"WHERE name = ? AND type = ?"

func (ColumnName[TYPE]) Qx

func (columnName ColumnName[TYPE]) Qx(op string, x TYPE) *QxConjunction

Qx creates a condition with an op and a value when using this column, designed to build complex queries. Qx: 创建带有运算符和值的条件,用于构建复杂的查询。

func (ColumnName[TYPE]) RawName

func (columnName ColumnName[TYPE]) RawName() string

RawName returns the raw column name. RawName 返回原始的列名。

func (ColumnName[TYPE]) SafeCnm

func (columnName ColumnName[TYPE]) SafeCnm(quote string) ColumnName[TYPE]

SafeCnm returns a safe column name, enclosing it in backticks. SafeCnm 返回一个安全的列名,将其用反引号括起来。 If the column name conflicts with a SQL keyword (e.g., "create"), enclosing it in backticks ensures correct execution. 如果列名与 SQL 关键字(例如 "create")冲突,使用反引号将其括起来,确保正确执行。 Usage example: db.Select("`type`").Find(&one) demonstrates the standard pattern. 使用示例:db.Select("`type`").Find(&one) 展示了标准使用模式。

func (ColumnName[TYPE]) Sum

func (columnName ColumnName[TYPE]) Sum(alias string) string

Sum creates a SUM aggregate statement on the column. Sum: 创建一个 SUM 聚合查询,计算列值的总和。

func (ColumnName[TYPE]) TB

func (columnName ColumnName[TYPE]) TB(tab utils.GormTableNameFace) *TableColumn[TYPE]

TB creates a TableColumn through associating this column with a table interface TB 通过将此列与表接口关联创建 TableColumn

func (ColumnName[TYPE]) TC

func (columnName ColumnName[TYPE]) TC(tab utils.GormTableNameFace) *TableColumn[TYPE]

TC creates a TableColumn through associating this column with a table interface (alias of TB) TC 通过将此列与表接口关联创建 TableColumn(TB 的别名)

func (ColumnName[TYPE]) TN

func (columnName ColumnName[TYPE]) TN(tableName string) *TableColumn[TYPE]

TN creates a TableColumn through associating this column with a table name string TN 通过将此列与表名字符串关联创建 TableColumn

func (ColumnName[TYPE]) WithTable

func (columnName ColumnName[TYPE]) WithTable(tab utils.GormTableNameFace) *TableColumn[TYPE]

WithTable associates the column with a table interface and returns a TableColumn WithTable 将列与表接口关联并返回 TableColumn

func (ColumnName[TYPE]) WithTableName

func (columnName ColumnName[TYPE]) WithTableName(tableName string) *TableColumn[TYPE]

WithTableName associates the column with a table name string and returns a TableColumn WithTableName 将列与表名字符串关联并返回 TableColumn

type ColumnNameDecoration

type ColumnNameDecoration interface {
	DecorateColumnName(name string) string
}

ColumnNameDecoration defines an interface to decorate column names ColumnNameDecoration 定义装饰列名的接口

func NewCustomDecoration

func NewCustomDecoration(decorateFunc func(name string) string) ColumnNameDecoration

NewCustomDecoration creates a new CustomDecoration with the provided function NewCustomDecoration 使用提供的函数创建一个新的 CustomDecoration

func NewPlainDecoration

func NewPlainDecoration() ColumnNameDecoration

NewPlainDecoration creates a new PlainDecoration instance NewPlainDecoration 创建一个新的 PlainDecoration 实例

func NewTableDecoration

func NewTableDecoration(tableName string) ColumnNameDecoration

NewTableDecoration creates a new TableDecoration with the specified table name NewTableDecoration 使用指定的表名创建一个新的 TableDecoration

type ColumnOperationClass

type ColumnOperationClass struct{}

ColumnOperationClass provides a set of common methods to handle column operations in database queries. ColumnOperationClass 提供一组常用的数据库列操作工具函数。

func (*ColumnOperationClass) CROSSJOIN

func (common *ColumnOperationClass) CROSSJOIN(tableName string) *TableJoin

CROSSJOIN creates a cross join operation on the specified table. CROSSJOIN 给指定表创建一个交叉连接操作。

func (*ColumnOperationClass) CombineColumnNames

func (common *ColumnOperationClass) CombineColumnNames(a ...utils.ColumnNameInterface) string

CombineColumnNames combines the names of the provided ColumnNameInterfaces into a single string. CombineColumnNames 将提供的 ColumnNameInterface 的名称组合成一个字符串。

func (*ColumnOperationClass) CombineNamesSlices

func (common *ColumnOperationClass) CombineNamesSlices(a ...[]string) string

CombineNamesSlices combines multiple string slices into a single comma-separated string CombineNamesSlices 将多个字符串切片组合成一个逗号分隔的字符串

func (*ColumnOperationClass) CombineSelectStatements

func (common *ColumnOperationClass) CombineSelectStatements(cs ...SelectStatement) *SelectStatement

CombineSelectStatements combines multiple SelectStatements into a single SelectStatement. CombineSelectStatements 将多个 SelectStatement 组合成一个 SelectStatement。

func (*ColumnOperationClass) CombineStatements

func (common *ColumnOperationClass) CombineStatements(a ...string) string

CombineStatements combines the provided SQL statements into a single string. CombineStatements 将提供的 SQL 语句组合成一个字符串。

func (*ColumnOperationClass) CombineSxs

func (common *ColumnOperationClass) CombineSxs(cs ...SelectStatement) *SelectStatement

CombineSxs combines multiple SelectStatements into a single SelectStatement. CombineSxs 将多个 SelectStatement 组合成一个 SelectStatement。

func (*ColumnOperationClass) CountCaseWhenQxSx

func (common *ColumnOperationClass) CountCaseWhenQxSx(qx *QxConjunction, alias string) *SelectStatement

CountCaseWhenQxSx returns a SelectStatement with a COUNT CASE WHEN condition applied, using the provided QxConjunction and alias. CountCaseWhenQxSx 返回一个带有 COUNT CASE WHEN 条件的 SelectStatement,使用提供的 QxConjunction 和别名。

func (*ColumnOperationClass) CountCaseWhenStmt

func (common *ColumnOperationClass) CountCaseWhenStmt(condition string, alias string) string

CountCaseWhenStmt returns a SQL statement that counts the records with a CASE WHEN condition, applying the alias. CountCaseWhenStmt 返回一个计算记录数量的 SQL 语句,带有 CASE WHEN 条件,并应用别名。

func (*ColumnOperationClass) CountStmt

func (common *ColumnOperationClass) CountStmt(alias string) string

CountStmt returns a SQL statement that counts the records, applying the alias. CountStmt 返回一个计算记录数量的 SQL 语句,并应用别名。

func (*ColumnOperationClass) CreateColumnValueMap

func (common *ColumnOperationClass) CreateColumnValueMap(columnName string, value interface{}) ColumnValueMap

CreateColumnValueMap creates a ColumnValueMap using the provided column name and value. CreateColumnValueMap 根据提供的列名和值创建一个 ColumnValueMap。

func (*ColumnOperationClass) CreateCondition

func (common *ColumnOperationClass) CreateCondition(stmt string, args ...interface{}) *QxConjunction

CreateCondition creates a new QxConjunction with the provided statement and arguments. CreateCondition 根据提供的语句和参数创建一个新的 QxConjunction。

func (*ColumnOperationClass) CreateSelect

func (common *ColumnOperationClass) CreateSelect(stmt string, args ...interface{}) *SelectStatement

CreateSelect creates a new SelectStatement with the provided statement and arguments. CreateSelect 根据提供的语句和参数创建一个新的 SelectStatement。

func (*ColumnOperationClass) INNERJOIN

func (common *ColumnOperationClass) INNERJOIN(tableName string) *TableJoin

INNERJOIN creates an INNER join operation on the specified table. INNERJOIN 给指定表创建一个内连接操作。

func (*ColumnOperationClass) Kw

func (common *ColumnOperationClass) Kw(columnName string, value interface{}) ColumnValueMap

Kw creates a ColumnValueMap using the provided column name and value. Kw 根据提供的列名和值创建一个 ColumnValueMap。

func (*ColumnOperationClass) LEFTJOIN

func (common *ColumnOperationClass) LEFTJOIN(tableName string) *TableJoin

LEFTJOIN creates a left join operation on the specified table. LEFTJOIN 给指定表创建一个左连接操作。

func (*ColumnOperationClass) MergeNames

func (common *ColumnOperationClass) MergeNames(a ...utils.ColumnNameInterface) string

MergeNames combines the names of the provided ColumnNameInterfaces into a single string. MergeNames 将提供的 ColumnNameInterface 的名称组合成一个字符串。

func (*ColumnOperationClass) MergeSlices

func (common *ColumnOperationClass) MergeSlices(a ...[]string) string

MergeSlices combines multiple string slices into a single comma-separated string MergeSlices 将多个字符串切片组合成一个逗号分隔的字符串

func (*ColumnOperationClass) MergeStmts

func (common *ColumnOperationClass) MergeStmts(a ...string) string

MergeStmts combines the provided SQL statements into a single string. MergeStmts 将提供的 SQL 语句组合成一个字符串。

func (*ColumnOperationClass) NewColumnValueMap

func (common *ColumnOperationClass) NewColumnValueMap() ColumnValueMap

NewColumnValueMap creates a new ColumnValueMap using the NewKw function. NewColumnValueMap 使用 NewKw 函数创建一个新的 ColumnValueMap。

func (*ColumnOperationClass) NewKw

func (common *ColumnOperationClass) NewKw() ColumnValueMap

NewKw creates a new ColumnValueMap using the Kw function. NewKw 使用 Kw 函数创建一个新的 ColumnValueMap。

func (*ColumnOperationClass) NewQx

func (common *ColumnOperationClass) NewQx(stmt string, args ...interface{}) *QxConjunction

NewQx creates a new QxConjunction with the provided statement and arguments. NewQx 根据提供的语句和参数创建一个新的 QxConjunction。

func (*ColumnOperationClass) NewSx

func (common *ColumnOperationClass) NewSx(stmt string, args ...interface{}) *SelectStatement

NewSx creates a new SelectStatement with the provided statement and arguments. NewSx 根据提供的语句和参数创建一个新的 SelectStatement。

func (*ColumnOperationClass) OK

func (common *ColumnOperationClass) OK() bool

OK always returns true and provides a simple condition. Its main purpose is to provide a compact scope in which variables exist just within the condition block. Scope limitation keeps code clean and makes the logic simple to understand.

OK 始终返回 true,提供一个简单的条件。 主要目的是提供一个紧凑的作用域,变量仅在条件块内有效。 作用域限制使代码整洁,逻辑易于理解。

func (*ColumnOperationClass) OrderByColumns

func (common *ColumnOperationClass) OrderByColumns(db *gorm.DB, obs ...OrderByBottle) *gorm.DB

OrderByColumns applies the provided OrderByBottle objects to the given gorm.DB statement. OrderByColumns 将提供的 OrderByBottle 对象应用到给定的 gorm.DB 语句。

func (*ColumnOperationClass) Qx

func (common *ColumnOperationClass) Qx(stmt string, args ...interface{}) *QxConjunction

Qx returns a new QxConjunction with the provided statement and arguments. Qx 返回一个新的 QxConjunction,使用提供的语句和参数。

func (*ColumnOperationClass) RIGHTJOIN

func (common *ColumnOperationClass) RIGHTJOIN(tableName string) *TableJoin

RIGHTJOIN creates a right join operation on the specified table. RIGHTJOIN 给指定表创建一个右连接操作。

func (*ColumnOperationClass) Select

func (common *ColumnOperationClass) Select(db *gorm.DB, qxs ...*SelectStatement) *gorm.DB

Select applies the provided SelectStatements to the given gorm.DB statement. Select 将提供的 SelectStatement 应用到给定的 gorm.DB 语句。

func (*ColumnOperationClass) Sx

func (common *ColumnOperationClass) Sx(stmt string, args ...interface{}) *SelectStatement

Sx returns a new SelectStatement with the provided statement and arguments. Sx 返回一个新的 SelectStatement,使用提供的语句和参数。

func (*ColumnOperationClass) UpdateColumns

func (common *ColumnOperationClass) UpdateColumns(db *gorm.DB, kws ...ColumnValueMap) *gorm.DB

UpdateColumns updates the columns of the given gorm.DB statement with the provided ColumnValueMaps. UpdateColumns 使用提供的 ColumnValueMap 更新给定的 gorm.DB 语句的列。

func (*ColumnOperationClass) Where

func (common *ColumnOperationClass) Where(db *gorm.DB, qxs ...*QxConjunction) *gorm.DB

Where applies the provided QxConjunctions to the given gorm.DB statement. Where 将提供的 QxConjunction 应用到给定的 gorm.DB 语句。

type ColumnValueMap

type ColumnValueMap map[string]interface{}

ColumnValueMap is a map type used for GORM update logic to represent column-value mappings. This type is used when calling gormrepo.Updates, gormrepo.UpdatesM, or GORM native db.Updates. It provides type-safe column-value assignments with chainable Kw() method.

ColumnValueMap 是一个用于 GORM 更新逻辑的映射类型,用于表示列与值的对应关系表。 该类型在调用 gormrepo.Updates、gormrepo.UpdatesM 或 GORM 原生 db.Updates 时使用。 提供类型安全的列值赋值,支持链式调用 Kw() 方法。

Usage with gormrepo.Updates (requires AsMap() conversion): 使用 gormrepo.Updates 时(需要 AsMap() 转换):

repo.Updates(where, func(cls *AccountColumns) map[string]interface{} {
    return cls.
        Kw(cls.Nickname.Kv(newNickname)).
        Kw(cls.Password.Kv(newPassword)).
        AsMap() // Convert to map[string]interface{} // 转换为 map[string]interface{} 类型
})

Usage with gormrepo.UpdatesM (no AsMap() needed): 使用 gormrepo.UpdatesM 时(无需 AsMap()):

repo.UpdatesM(where, func(cls *AccountColumns) gormcnm.ColumnValueMap {
    return cls.
        Kw(cls.Nickname.Kv(newNickname)).
        Kw(cls.Password.Kv(newPassword))
    // No AsMap() needed! // 不需要 AsMap()!
})

func Kw

func Kw(columnName string, value interface{}) ColumnValueMap

Kw creates a new ColumnValueMap and adds a key-value. Kw 创建一个新的 ColumnValueMap 并添加一个键值对。

func NewKw

func NewKw() ColumnValueMap

NewKw initializes a new ColumnValueMap. NewKw 初始化一个新的 ColumnValueMap。

func (ColumnValueMap) AsMap

func (mp ColumnValueMap) AsMap() map[string]interface{}

AsMap converts ColumnValueMap to map[string]interface{} for GORM. Required when using gormrepo.Updates, not needed when using gormrepo.UpdatesM. This is the recommended conversion method with clear semantics.

AsMap 将 ColumnValueMap 转换为 map[string]interface{}。 使用 gormrepo.Updates 时需要调用,使用 gormrepo.UpdatesM 时不需要。 这是推荐的转换方法,语义清晰明确。

func (ColumnValueMap) Kw

func (mp ColumnValueMap) Kw(columnName string, value interface{}) ColumnValueMap

Kw adds a key-value pair to ColumnValueMap and supports chaining. Kw 向 ColumnValueMap 添加键值对并支持链式调用。

func (ColumnValueMap) Kws

func (mp ColumnValueMap) Kws() map[string]interface{}

Kws converts ColumnValueMap to map[string]interface{} for GORM. Required when using gormrepo.Updates, not needed when using gormrepo.UpdatesM. Recommend using AsMap() instead, as it has cleaner semantics and avoids naming conflicts.

Kws 将 ColumnValueMap 转换为 GORM 的 map[string]interface{}。 使用 gormrepo.Updates 时需要调用,使用 gormrepo.UpdatesM 时不需要。 推荐使用 AsMap(),语义更明确且不易与其他名称冲突。

func (ColumnValueMap) Map

func (mp ColumnValueMap) Map() map[string]interface{}

Map converts ColumnValueMap to map[string]interface{} for GORM. Required when using gormrepo.Updates, not needed when using gormrepo.UpdatesM. Recommend using AsMap() instead, as it has cleaner semantics and avoids naming conflicts.

Map 将 ColumnValueMap 转换为 map[string]interface{}。 使用 gormrepo.Updates 时需要调用,使用 gormrepo.UpdatesM 时不需要。 推荐使用 AsMap(),语义更明确且不易与其他名称冲突。

func (ColumnValueMap) ToMap

func (mp ColumnValueMap) ToMap() map[string]interface{}

ToMap converts ColumnValueMap to map[string]interface{} for GORM. Required when using gormrepo.Updates, not needed when using gormrepo.UpdatesM. Recommend using AsMap() instead, as it has cleaner semantics and avoids naming conflicts.

ToMap 将 ColumnValueMap 转换为 map[string]interface{}。 使用 gormrepo.Updates 时需要调用,使用 gormrepo.UpdatesM 时不需要。 推荐使用 AsMap(),语义更明确且不易与其他名称冲突。

type CustomDecoration

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

CustomDecoration allows custom decoration logic via a function CustomDecoration 允许通过函数实现自定义装饰逻辑

func (*CustomDecoration) DecorateColumnName

func (D *CustomDecoration) DecorateColumnName(name string) string

DecorateColumnName applies the custom decoration function to the column name DecorateColumnName 将自定义装饰函数应用到列名上

type OrderByBottle

type OrderByBottle string

OrderByBottle represents a sort statement construction toolkit, designed with a unique naming style that reflects a materials science focus. OrderByBottle 代表排序语句构建器,使用了与材料学相关的命名风格。

func (OrderByBottle) Ob

Ob concatenates the current OrderByBottle with the next one, forming a combined ordering string. Ob 将当前的 OrderByBottle 与下一个 OrderByBottle 连接,形成一个组合的排序字符串。

func (OrderByBottle) OrderByBottle

func (ob OrderByBottle) OrderByBottle(next OrderByBottle) OrderByBottle

OrderByBottle concatenates the current OrderByBottle with the next one, forming a combined ordering string. OrderByBottle 将当前的 OrderByBottle 与下一个 OrderByBottle 连接,形成一个组合的排序字符串。

func (OrderByBottle) Orders

func (ob OrderByBottle) Orders() string

Orders converts the OrderByBottle to a string. Note that if the type is not specific, it could be ignored by GORM's logic. Orders 将 OrderByBottle 转换为字符串。请注意,如果类型不明确,它可能会被 GORM 的逻辑忽略。

func (OrderByBottle) Ox

func (ob OrderByBottle) Ox() string

Ox converts the OrderByBottle to a string. Note that if the type is not specific, it could be ignored by GORM's logic. Ox 将 OrderByBottle 转换为字符串。请注意,如果类型不明确,它可能会被 GORM 的逻辑忽略。 This is an unavoidable limitation due to GORM's handling of the Order field logic. 这是由于 GORM 对 Order 字段逻辑的处理所造成的无法避免的限制。 Developers might forget to convert this to a string before passing it to GORM, so it is important to do this step. 开发者可能会忘记在传递给 GORM 之前将其转换为字符串,因此需要记住这一点。 There is no elegant solution to this limitation now, but it should work fine in most cases. 现在没有优雅的解决方案,但在大多数情况下应该没有问题。

func (OrderByBottle) Scope

func (ob OrderByBottle) Scope() ScopeFunction

Scope converts the OrderByBottle to a GORM ScopeFunction used with db.Scopes(). It applies the ordering defined by OrderByBottle to the GORM select. Scope 将 OrderByBottle 转换为 GORM 的 ScopeFunction,以便被 db.Scopes() 调用。 它将 OrderByBottle 定义的排序规则应用于 GORM 查询。

type PlainDecoration

type PlainDecoration struct{}

PlainDecoration provides simple decoration that returns the name unchanged PlainDecoration 提供简单的装饰,返回不变的名称

func (*PlainDecoration) DecorateColumnName

func (D *PlainDecoration) DecorateColumnName(name string) string

DecorateColumnName returns the column name without any modification DecorateColumnName 返回未经任何修改的列名

type QsConjunction

type QsConjunction string

QsConjunction means gorm queries conjunction. example: OR AND NOT QsConjunction 表示 GORM 查询语句中的连接词,例如 OR、AND、NOT 就是表示 "或"、"且"、"非" 的连接词 在语法学中,conjunction(连词)是一种词类,用来连接词、短语、语句

func NewQsConjunction

func NewQsConjunction(stmt string) QsConjunction

NewQsConjunction creates a new QsConjunction instance from the given SQL statement string NewQsConjunction 从给定的 SQL 语句字符串创建一个新的 QsConjunction 实例

func (QsConjunction) AND

func (qsConjunction QsConjunction) AND(qcs ...QsConjunction) QsConjunction

AND constructs a conjunction using "AND" between QsConjunction instances. AND 使用 "AND" 在多个 QsConjunction 实例之间构造连接语句。

func (QsConjunction) NOT

func (qsConjunction QsConjunction) NOT() QsConjunction

NOT negates the QsConjunction instance by wrapping it with "NOT". NOT 通过添加 "NOT" 来对 QsConjunction 实例进行逻辑取反。

func (QsConjunction) OR

func (qsConjunction QsConjunction) OR(qcs ...QsConjunction) QsConjunction

OR constructs a conjunction using "OR" between QsConjunction instances. OR 使用 "OR" 在多个 QsConjunction 实例之间构造连接语句。

func (QsConjunction) Qs

func (qsConjunction QsConjunction) Qs() string

Qs convert the QsConjunction instance into a string representation. Qs 将 QsConjunction 实例转换为字符串表示。

func (QsConjunction) Qx

func (qsConjunction QsConjunction) Qx() *QxConjunction

Qx converts the QsConjunction instance into a QxConjunction object with arguments. Qx 将 QsConjunction 实例转换为带参数的 QxConjunction 对象。

func (QsConjunction) Value

func (qsConjunction QsConjunction) Value() (driver.Value, error)

Value prevents GORM from using QsConjunction as value by causing a panic. Value 阻止 GORM 把 QsConjunction 当值使用,通过触发 panic 实现。 当你定义了一个类型为 type xxx string 的自定义类型,并尝试将其用作查询条件时,GORM 会将整个自定义类型作为一个值来处理,而不是将其展开为 SQL 语句中的占位符。 因此也就是说 db.Where(xxx("name = ? AND type = ?")) 这个是不行的 基本的结论是: 当你执行 db.Where(xxx("name = ? AND type = ?")) 时,GORM 会将 xxx("name = ? AND type = ?") 视为一个单独的值,再将其传递给查询条件,而不会将其展开为具体的 SQL 语句。 这时,给 type xxx string 增加 Value 函数,而且里面报 panic,就能避免用错 这就是这里给出 Value { panic } 的原因 这样,假如你不把结果转换为 string,而是直接往 where 条件里传递,就会在 where 条件中触发 value 异常

type QsType

type QsType = QsConjunction

QsType is an alias when using QsConjunction as a short type name QsType 是 QsConjunction 的别名,用作简短的类型名称

func NewQs

func NewQs(stmt string) QsType

NewQs creates a new QsConjunction instance from the given SQL statement string NewQs 从给定的 SQL 语句字符串创建一个新的 QsConjunction 实例

type QxConjunction

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

QxConjunction is used to construct WHERE queries (AND, OR, NOT) and associated arguments. QxConjunction 用于构造关系查询语句(AND、OR、NOT)以及其对应的参数,以供 db.Where 使用。 Example: When combining conditions like a.Eq("xyz") and b.Eq("uvw"), this class concatenates statements with (---) AND (---) and merges arguments into a new list. 示例:当需要组合条件如 a.Eq("xyz") 和 b.Eq("uvw") 时,该工具类将语句用 (---) AND (---) 连接,并将参数列表合并为新的列表。

func NewQxConjunction

func NewQxConjunction(stmt string, args ...interface{}) *QxConjunction

NewQxConjunction creates a new instance of QxConjunction with the provided statement and arguments. NewQxConjunction 使用提供的语句和参数创建一个新的 QxConjunction 实例。

func Qx

func Qx(stmt string, args ...interface{}) *QxConjunction

Qx is shorthand for creating a new QxConjunction instance. Qx 是创建 QxConjunction 实例的简写形式。

func (*QxConjunction) AND

func (qx *QxConjunction) AND(cs ...*QxConjunction) *QxConjunction

AND combines the current QxConjunction instance with multiple QxConjunction instances using "AND". AND 使用 "AND" 将当前 QxConjunction 实例与多个 QxConjunction 实例组合在一起。

func (*QxConjunction) AND1

func (qx *QxConjunction) AND1(stmt string, args ...interface{}) *QxConjunction

AND1 creates a new QxConjunction instance with the given statement and arguments, then combines it with the current instance using "AND". AND1 使用给定的语句和参数创建一个新的 QxConjunction 实例,然后使用 "AND" 将其与当前实例组合。

func (QxConjunction) Args

func (qx QxConjunction) Args() []interface{}

Args return the arguments list of the current statementArgumentsTuple instance. Args 返回当前 statementArgumentsTuple 实例的参数列表。

func (*QxConjunction) NOT

func (qx *QxConjunction) NOT() *QxConjunction

NOT negates the current QxConjunction instance by wrapping the statement with "NOT". NOT 通过在语句外包裹 "NOT" 来对当前 QxConjunction 实例进行逻辑取反。

func (*QxConjunction) OR

func (qx *QxConjunction) OR(cs ...*QxConjunction) *QxConjunction

OR combines the current QxConjunction instance with multiple QxConjunction instances using "OR". OR 使用 "OR" 将当前 QxConjunction 实例与多个 QxConjunction 实例组合在一起。

func (*QxConjunction) OR1

func (qx *QxConjunction) OR1(stmt string, args ...interface{}) *QxConjunction

OR1 creates a new QxConjunction instance with the given statement and arguments, then combines it with the current instance using "OR". OR1 使用给定的语句和参数创建一个新的 QxConjunction 实例,然后使用 "OR" 将其与当前实例组合。

func (QxConjunction) Qs

func (qx QxConjunction) Qs() string

Qs return the statement string of the current statementArgumentsTuple instance. Qs 返回当前 statementArgumentsTuple 实例的语句字符串。

func (QxConjunction) Qx0

func (qx QxConjunction) Qx0() string

Qx0 returns the statement string when there are no arguments in the statementArgumentsTuple instance. Qx0 在 statementArgumentsTuple 实例没有参数时返回语句字符串。

func (QxConjunction) Qx1

func (qx QxConjunction) Qx1() (string, interface{})

Qx1 returns the statement string and the first argument in the statementArgumentsTuple instance. Qx1 返回 statementArgumentsTuple 实例的语句字符串和第一个参数。

func (QxConjunction) Qx2

func (qx QxConjunction) Qx2() (string, interface{}, interface{})

Qx2 returns the statement string and the first two arguments in the statementArgumentsTuple instance. Qx2 返回 statementArgumentsTuple 实例的语句字符串和前两个参数。

func (QxConjunction) Qx3

func (qx QxConjunction) Qx3() (string, interface{}, interface{}, interface{})

Qx3 returns the statement string and three arguments in the statementArgumentsTuple instance. Qx3 返回 statementArgumentsTuple 实例的语句字符串和三个参数。

func (QxConjunction) Qx4

func (qx QxConjunction) Qx4() (string, interface{}, interface{}, interface{}, interface{})

Qx4 returns the statement string and four arguments in the statementArgumentsTuple instance. Qx4 返回 statementArgumentsTuple 实例的语句字符串和四个参数。

func (QxConjunction) Qx5

func (qx QxConjunction) Qx5() (string, interface{}, interface{}, interface{}, interface{}, interface{})

Qx5 returns the statement string and five arguments in the statementArgumentsTuple instance. Qx5 返回 statementArgumentsTuple 实例的语句字符串和五个参数。

func (QxConjunction) Qx6

func (qx QxConjunction) Qx6() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx6 returns the statement string and six arguments in the statementArgumentsTuple instance. Qx6 返回 statementArgumentsTuple 实例的语句字符串和六个参数。

func (QxConjunction) Qx7

func (qx QxConjunction) Qx7() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx7 returns the statement string and seven arguments in the statementArgumentsTuple instance. Qx7 返回 statementArgumentsTuple 实例的语句字符串和七个参数。

func (QxConjunction) Qx8

func (qx QxConjunction) Qx8() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx8 returns the statement string and eight arguments in the statementArgumentsTuple instance. Qx8 返回 statementArgumentsTuple 实例的语句字符串和八个参数。

func (QxConjunction) Qx9

func (qx QxConjunction) Qx9() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx9 returns the statement string and nine arguments in the statementArgumentsTuple instance. Qx9 返回 statementArgumentsTuple 实例的语句字符串和九个参数。

func (QxConjunction) Qx10

func (qx QxConjunction) Qx10() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx10 returns the statement string and ten arguments in the statementArgumentsTuple instance. Qx10 返回 statementArgumentsTuple 实例的语句字符串和十个参数。

func (QxConjunction) Qx11

func (qx QxConjunction) Qx11() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx11 returns the statement string and eleven arguments in the statementArgumentsTuple instance. Qx11 返回 statementArgumentsTuple 实例的语句字符串和十一个参数。

func (QxConjunction) Qx12

func (qx QxConjunction) Qx12() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx12 returns the statement string and twelve arguments in the statementArgumentsTuple instance. Qx12 返回 statementArgumentsTuple 实例的语句字符串和十二个参数。

func (*QxConjunction) Scope

func (qx *QxConjunction) Scope() ScopeFunction

Scope converts the QxConjunction to a GORM ScopeFunction used with db.Scopes(). It applies the SELECT conditions defined by QxConjunction to the GORM select. Scope 将 QxConjunction 转换为 GORM 的 ScopeFunction,以便于被 db.Scopes() 调用。 它将 QxConjunction 定义的查询条件应用于 GORM 查询。

func (QxConjunction) Value

func (qx QxConjunction) Value() (driver.Value, error)

Value panics to prevent direct use of this structure in GORM, as it is not callable in this context. Value 会触发 panic,以防止在 GORM 中直接使用此结构,因为在此上下文中无法调用该函数。

type QxType

type QxType = QxConjunction

QxType is an alias when using QxConjunction as a short type name QxType 是 QxConjunction 的别名,用作简短的类型名称

func NewQx

func NewQx(stmt string, args ...interface{}) *QxType

NewQx creates a new QxConjunction instance with the provided statement and arguments NewQx 使用提供的语句和参数创建一个新的 QxConjunction 实例

type ScopeFunction

type ScopeFunction = func(db *gorm.DB) *gorm.DB

ScopeFunction is a type alias, representing a function that modifies a GORM DB instance, used with db.Scopes() to use custom GORM conditions. See: https://github.com/go-gorm/gorm/blob/c44405a25b0fb15c20265e672b8632b8774793ca/chainable_api.go#L376 ScopeFunction 是用于修改 GORM DB 实例的函数类型别名, 主要是和 db.Scopes() 配合使用,以应用自定义查询条件。 详见:https://github.com/go-gorm/gorm/blob/c44405a25b0fb15c20265e672b8632b8774793ca/chainable_api.go#L376

type SelectStatement

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

SelectStatement represents a SELECT statement with arguments used in GORM db.Select operations Handles complex SELECT scenarios where conditions and arguments are needed Auto combines multiple select statements with comma separation to form multi-column queries

Usage scenarios: - 99% of cases db.Select requires no parameters - However, with complex queries such as: SELECT COUNT(CASE WHEN condition THEN 1 END) as cnt - Need to merge multiple column select statements and corresponding parameters - Columns are separated using commas

SelectStatement 表示用于 GORM db.Select 操作的 SELECT 语句及参数 处理需要条件和参数的复杂 SELECT 场景 自动使用逗号分隔合并多个 SELECT 语句进行多列查询

使用场景说明: - 99%的情况下 db.Select 不需要参数 - 但对于复杂查询如:SELECT COUNT(CASE WHEN condition THEN 1 END) as cnt - 需要合并多个列的 SELECT 语句和对应参数 - 各列之间使用逗号分隔

func NewSelectStatement

func NewSelectStatement(stmt string, args ...interface{}) *SelectStatement

NewSelectStatement creates a new SelectStatement with the provided query string and arguments. NewSelectStatement 使用提供的查询字符串和参数创建一个新的 SelectStatement 实例。

func (SelectStatement) Args

func (qx SelectStatement) Args() []interface{}

Args return the arguments list of the current statementArgumentsTuple instance. Args 返回当前 statementArgumentsTuple 实例的参数列表。

func (*SelectStatement) Combine

func (sx *SelectStatement) Combine(cs ...*SelectStatement) *SelectStatement

Combine combines the current SelectStatement with other SelectStatements by merging their query strings and arguments. Combine 将当前的 SelectStatement 与其他 SelectStatement 合并,通过合并它们的查询字符串和参数。

func (SelectStatement) Qs

func (qx SelectStatement) Qs() string

Qs return the statement string of the current statementArgumentsTuple instance. Qs 返回当前 statementArgumentsTuple 实例的语句字符串。

func (SelectStatement) Qx0

func (qx SelectStatement) Qx0() string

Qx0 returns the statement string when there are no arguments in the statementArgumentsTuple instance. Qx0 在 statementArgumentsTuple 实例没有参数时返回语句字符串。

func (SelectStatement) Qx1

func (qx SelectStatement) Qx1() (string, interface{})

Qx1 returns the statement string and the first argument in the statementArgumentsTuple instance. Qx1 返回 statementArgumentsTuple 实例的语句字符串和第一个参数。

func (SelectStatement) Qx2

func (qx SelectStatement) Qx2() (string, interface{}, interface{})

Qx2 returns the statement string and the first two arguments in the statementArgumentsTuple instance. Qx2 返回 statementArgumentsTuple 实例的语句字符串和前两个参数。

func (SelectStatement) Qx3

func (qx SelectStatement) Qx3() (string, interface{}, interface{}, interface{})

Qx3 returns the statement string and three arguments in the statementArgumentsTuple instance. Qx3 返回 statementArgumentsTuple 实例的语句字符串和三个参数。

func (SelectStatement) Qx4

func (qx SelectStatement) Qx4() (string, interface{}, interface{}, interface{}, interface{})

Qx4 returns the statement string and four arguments in the statementArgumentsTuple instance. Qx4 返回 statementArgumentsTuple 实例的语句字符串和四个参数。

func (SelectStatement) Qx5

func (qx SelectStatement) Qx5() (string, interface{}, interface{}, interface{}, interface{}, interface{})

Qx5 returns the statement string and five arguments in the statementArgumentsTuple instance. Qx5 返回 statementArgumentsTuple 实例的语句字符串和五个参数。

func (SelectStatement) Qx6

func (qx SelectStatement) Qx6() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx6 returns the statement string and six arguments in the statementArgumentsTuple instance. Qx6 返回 statementArgumentsTuple 实例的语句字符串和六个参数。

func (SelectStatement) Qx7

func (qx SelectStatement) Qx7() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx7 returns the statement string and seven arguments in the statementArgumentsTuple instance. Qx7 返回 statementArgumentsTuple 实例的语句字符串和七个参数。

func (SelectStatement) Qx8

func (qx SelectStatement) Qx8() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx8 returns the statement string and eight arguments in the statementArgumentsTuple instance. Qx8 返回 statementArgumentsTuple 实例的语句字符串和八个参数。

func (SelectStatement) Qx9

func (qx SelectStatement) Qx9() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx9 returns the statement string and nine arguments in the statementArgumentsTuple instance. Qx9 返回 statementArgumentsTuple 实例的语句字符串和九个参数。

func (SelectStatement) Qx10

func (qx SelectStatement) Qx10() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx10 returns the statement string and ten arguments in the statementArgumentsTuple instance. Qx10 返回 statementArgumentsTuple 实例的语句字符串和十个参数。

func (SelectStatement) Qx11

func (qx SelectStatement) Qx11() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx11 returns the statement string and eleven arguments in the statementArgumentsTuple instance. Qx11 返回 statementArgumentsTuple 实例的语句字符串和十一个参数。

func (SelectStatement) Qx12

func (qx SelectStatement) Qx12() (string, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{})

Qx12 returns the statement string and twelve arguments in the statementArgumentsTuple instance. Qx12 返回 statementArgumentsTuple 实例的语句字符串和十二个参数。

func (*SelectStatement) Scope

func (sx *SelectStatement) Scope() ScopeFunction

Scope converts the SelectStatement to a GORM ScopeFunction used with db.Scopes(). It applies the SELECT operation defined by SelectStatement to the GORM select. Scope 将 SelectStatement 转换为 GORM 的 ScopeFunction,以便于被 db.Scopes() 调用。 它将 SelectStatement 定义的查询语句应用于 GORM 查询。

func (SelectStatement) Value

func (qx SelectStatement) Value() (driver.Value, error)

Value panics to prevent direct use of this structure in GORM, as it is not callable in this context. Value 会触发 panic,以防止在 GORM 中直接使用此结构,因为在此上下文中无法调用该函数。

type SxType

type SxType = SelectStatement

SxType is an alias when using SelectStatement as a short type name SxType 是 SelectStatement 的别名,用作简短的类型名称

func NewSx

func NewSx(stmt string, args ...interface{}) *SxType

NewSx creates a new SelectStatement instance with the provided statement and arguments NewSx 使用提供的语句和参数创建一个新的 SelectStatement 实例

type TableColumn

type TableColumn[TYPE any] struct {
	// contains filtered or unexported fields
}

TableColumn represents a combination of a table and a column. TableColumn 表示表和列的组合。

func (*TableColumn[TYPE]) AsAlias

func (tc *TableColumn[TYPE]) AsAlias(alias string) string

AsAlias generates a SQL alias to the column in the format "table.column AS alias". AsAlias 生成列的 SQL 别名,格式为 "table.column AS alias"。

func (*TableColumn[TYPE]) AsName

func (tc *TableColumn[TYPE]) AsName(alias ColumnName[TYPE]) string

AsName generates a SQL alias for the column using another ColumnName as the alias. AsName 使用另一个 ColumnName 作为别名生成列的 SQL 别名。

func (*TableColumn[TYPE]) Cnm

func (tc *TableColumn[TYPE]) Cnm() ColumnName[TYPE]

Cnm retrieves the column name in a ColumnName format, representing the combination of the table and column. Cnm 获取以 ColumnName 格式表示的列名,代表表和列的组合。

func (*TableColumn[TYPE]) ColumnName

func (tc *TableColumn[TYPE]) ColumnName() ColumnName[TYPE]

ColumnName retrieves the column name in a ColumnName format, representing the combination of the table and column. ColumnName 获取以 ColumnName 格式表示的列名,代表表和列的组合。

func (*TableColumn[TYPE]) Eq

func (tc *TableColumn[TYPE]) Eq(xc *TableColumn[TYPE]) string

Eq generates an equivalence condition in SQL format, ensuring type uniformity between two columns. Eq 生成 SQL 格式的相等条件,确保两列之间的类型一致。

func (*TableColumn[TYPE]) Name

func (tc *TableColumn[TYPE]) Name() string

Name returns the complete name of the column in the format "table.column". Name 返回列的完全限定名称,格式为 "table.column"。

func (*TableColumn[TYPE]) Ne

func (tc *TableColumn[TYPE]) Ne(xc *TableColumn[TYPE]) string

Ne generates a SQL non-equivalence condition, ensuring type uniformity between two columns. Ne 生成 SQL 格式的不等条件,确保两列之间的类型一致。

func (*TableColumn[TYPE]) Ob

func (tc *TableColumn[TYPE]) Ob(direction string) OrderByBottle

Ob creates an OrderByBottle object to specify ordering based on the column name and direction. Ob 基于列名和方向创建一个 OrderByBottle 对象用于指定排序。

func (*TableColumn[TYPE]) Op

func (tc *TableColumn[TYPE]) Op(op string, xc *TableColumn[TYPE]) string

Op generates a custom SQL operation between two columns using the specified operator. Op 使用指定的 operand 生成两列之间的自定义 SQL 操作。

type TableDecoration

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

TableDecoration adds table prefix to column names TableDecoration 为列名添加表前缀

func (*TableDecoration) DecorateColumnName

func (D *TableDecoration) DecorateColumnName(name string) string

DecorateColumnName adds table prefix to the column name when table name is not a blank string DecorateColumnName 如果表名不为空,则为列名添加表前缀

type TableJoin

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

TableJoin represents a join operation on a table, including its type and name Supports every standard SQL join type: LEFT, RIGHT, INNER, and CROSS joins Auto generates correct SQL JOIN syntax with ON clause conditions

TableJoin 表示表上的连接操作,包括连接类型和表名 支持所有标准 SQL 连接类型:LEFT、RIGHT、INNER 和 CROSS 连接 自动生成适当的 SQL JOIN 语法和 ON 子句条件

func (*TableJoin) On

func (op *TableJoin) On(stmts ...string) string

On generates the SQL ON clause for the join, combining multiple statements with "AND". On 给连接生成 SQL 的 ON 子句,将多个语句用 "AND" 组合。

Directories

Path Synopsis
Package gormcnmjson enables type-safe JSON column operations within GORM Supports SQLite JSON functions with compile-time type checking Works with both string and []byte JSON column types
Package gormcnmjson enables type-safe JSON column operations within GORM Supports SQLite JSON functions with compile-time type checking Works with both string and []byte JSON column types
Package gormcnmstub provides stub implementations and shared instances used in gormcnm operations Auto exposes ColumnOperationClass instance with common operations like JOIN, COALESCE Supports testing and development with pre-configured column operation patterns
Package gormcnmstub provides stub implementations and shared instances used in gormcnm operations Auto exposes ColumnOperationClass instance with common operations like JOIN, COALESCE Supports testing and development with pre-configured column operation patterns
internal
demos/demo1x command
Package main demonstrates basic gormcnm usage with Account CRUD operations Auto shows column definitions, WHERE queries, UPDATE operations, and expression updates Runs with SQLite IN-MEMORY database to showcase type-safe column operations
Package main demonstrates basic gormcnm usage with Account CRUD operations Auto shows column definitions, WHERE queries, UPDATE operations, and expression updates Runs with SQLite IN-MEMORY database to showcase type-safe column operations
demos/demo2x command
Package main demonstrates advanced gormcnm usage with multi-condition WHERE queries Auto shows comparison with traditional GORM queries vs type-safe column operations Runs with SQLite IN-MEMORY database to showcase Gt, Lt, Eq operations
Package main demonstrates advanced gormcnm usage with multi-condition WHERE queries Auto shows comparison with traditional GORM queries vs type-safe column operations Runs with SQLite IN-MEMORY database to showcase Gt, Lt, Eq operations
examples/example1
Package example1 provides a placeholder package used in gormcnm test structure Auto reserved as namespace definition during test execution
Package example1 provides a placeholder package used in gormcnm test structure Auto reserved as namespace definition during test execution
examples/example2
Package example2 provides a placeholder package used in gormcnm test structure Auto reserved as namespace definition during test execution
Package example2 provides a placeholder package used in gormcnm test structure Auto reserved as namespace definition during test execution
examples/example3
Package example3 demonstrates namespace pattern and manual column definition with gormcnm Auto shows User and Order models with Columns() methods returning column name collections Supports avoiding column name conflicts across multiple tables
Package example3 demonstrates namespace pattern and manual column definition with gormcnm Auto shows User and Order models with Columns() methods returning column name collections Supports avoiding column name conflicts across multiple tables
examples/example4
Package example4 demonstrates decoration pattern and dynamic column generation with gormcnm Auto shows User and Order models with TableColumns() methods using decoration pattern Supports dynamic column name prefixing and flexible column name transformations
Package example4 demonstrates decoration pattern and dynamic column generation with gormcnm Auto shows User and Order models with TableColumns() methods using decoration pattern Supports dynamic column name prefixing and flexible column name transformations
utils
Package utils provides utility types and interfaces for GORM table operations Auto discover and handle column names with type safety and interface abstractions Support both direct table name strings and GORM table interface implementations
Package utils provides utility types and interfaces for GORM table operations Auto discover and handle column names with type safety and interface abstractions Support both direct table name strings and GORM table interface implementations

Jump to

Keyboard shortcuts

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