gormcnm

package module
v1.0.45 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 9 Imported by: 1

README

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

gormcnm - A Progressive, Type-Safe Approach to GORM Column Names Using Generics

Overview

gormcnm is a cutting-edge generic package designed to transform how you use GORM in Go. By leveraging the full power of Go’s generics, it offers a type-safe, efficient, and highly productive way to reference database columns in your models. This eliminates the risks associated with hardcoded column names, enhancing refactoring safety, maintainability, and enabling faster development with fewer bugs.

gormcnm resembles MyBatis Plus in the Java ecosystem, which allows developers to dynamically retrieve column names using expressions like Example::getName. Similarly, gormcnm brings type-safe column referencing to Go. By using gormcnm, developers can easily perform database queries with compile-time validation and avoid hardcoding strings in queries.

gormcnm works like SQLAlchemy in the Python ecosystem, where developers can reference model attributes like Example.name for dynamic column access, enabling type-safe column referencing in Go. Similarly, gormcnm enables type-safe dynamic column references in Go, like cls.Name.Eq("abc").

gormcnm keeps your column references consistent and type-safe, ensuring that your code is cleaner, more robust, and easier to maintain. With gormcnm, any changes in your model definitions are effortlessly reflected across your application without breaking queries, making it the ultimate safety net for your database interactions.

With gormcnm, you unlock the full potential of Go’s generics, achieving type-safe, refactor-proof, and developer-friendly database interactions effortlessly. No more brittle hardcoded strings or runtime surprises—gormcnm acts as your ultimate safety net, ensuring database queries remain consistent, scalable, and easy to refactor as your application evolves.

As a progressive package, gormcnm seamlessly integrates into your existing GORM workflow, allowing developers to adopt it incrementally and at their own pace. You can decide when and where to leverage its type-safe features while continuing to benefit from the simplicity and familiarity of GORM’s core API, ensuring that adopting gormcnm requires minimal learning effort and no disruption to your current projects.

CHINESE README

中文说明

Installation

go get github.com/yyle88/gormcnm

Features

  • Generics-based Type Safety: Harness Go's generics to create type-safe column names, ensuring that column references are validated at compile-time.
  • Seamless Refactoring: Changing model field names or types automatically updates all references, reducing errors and making refactoring effortless.
  • Progressive Adoption: Designed to be integrated incrementally, allowing developers to adopt its features at their own pace without disrupting existing workflows.
  • MyBatis Plus-like Column References: gormcnm enables type-safe dynamic column references in Go, like cls.Name.Eq("abc").
  • SQLAlchemy-like Access: Like SQLAlchemy in Python, gormcnm enables type-safe dynamic column references in Go, making queries cleaner and less error-prone.
  • Compile-time Validation: Prevent runtime errors caused by incorrect column names or mismatched types with robust compile-time validation.
  • Improved Developer Experience: Enjoy full IDE support with auto-completion, linting, and refactoring tools tailored for generics.
  • Minimized Human Error: Eliminate typos and hardcoded magic strings with well-defined constants for column names.
  • Self-documenting Code: Queries written with gormcnm are explicit and readable, making it easier to understand and maintain the codebase.
  • Reduced Boilerplate: Automatically generate type-safe column definitions with the gormcngen package, saving time and effort.

Example Usage

Suppose you have a GORM model defined as follows:

type Example struct {
    Name string `gorm:"primary_key;type:varchar(100);"`
    Type string `gorm:"column:type;"`
    Rank int    `gorm:"column:rank;"`
}

In Java, the MyBatis Plus tool can obtain the column name through Example::getName, assemble the query statement, fetch the result, and then use result.getName() to get the value of the field:

@Autowired
private ExampleMapper exampleMapper;

public void test() {
    Example result = exampleMapper.selectOne(
        new LambdaQueryWrapper<Example>().eq(Example::getName, "abc")
    );

    if (result != null) {
        System.out.println(result.getName());
        System.out.println(result.getRank());
    }
}

In Python, the SQLAlchemy tool can obtain the column name through Example.name, assemble the query statement, fetch the result, and then use result.name to get the value of the field:

def test():
    result = session.query(Example).filter(Example.name == "abc").first()

    if result:
        print(result.name)
        print(result.rank)

In Go, there's no equivalent to Example::Name; instead, example.Name directly retrieves the field value, requiring hard-coded queries.

Traditional Query with Hardcoded Field Names

Typically, you would write a query with hardcoded column names like this:

err := db.Where("name=?", "abc").First(&res).Error

While this works, hardcoding column names introduces risks during refactoring or type changes. A simple oversight could lead to runtime errors or type mismatches.

Safe Query with gormcnm

With gormcnm, you can define type-safe columns like this:

const (
    columnName = gormcnm.ColumnName[string]("name")
    columnType = gormcnm.ColumnName[string]("type")
    columnRank = gormcnm.ColumnName[int]("rank")
)
Type-Safe Queries

This allows you to write type-safe queries with compile-time validation:

var res Example
if err := db.Where(columnName.Eq("abc")).
    Where(columnType.Eq("xyz")).
    Where(columnRank.Gt(100)).
    Where(columnRank.Lt(200)).
    First(&res).Error; err != nil {
    panic(errors.WithMessage(err, "wrong"))
}
fmt.Println(res)

This approach ensures that column types and names are consistent, reducing the risk of bugs.

Demos

Simple demo

Advantages

  • Effortless Refactoring: Column names and types are strongly typed with generics. Renaming fields or changing column types updates all references automatically.
  • Compile-time Type Safety: Catch issues like type mismatches or incorrect column references during compilation, reducing debugging time.
  • Progressive Integration: Start using gormcnm in specific parts of your codebase and expand its use as needed, ensuring a smooth and non-disruptive transition.
  • Cleaner Code: Replace magic strings with constants, making your queries more readable, maintainable, and understandable.
  • Faster Development: IDE features like auto-completion and refactoring tools speed up coding and reduce the chance of human errors.
  • MyBatis Plus-like Syntax: gormcnm uses a type-safe column referencing pattern like MyBatis Plus in Java, enabling dynamic column access and safe queries.
  • SQLAlchemy-like Access: Similar to SQLAlchemy in Python, gormcnm provides type-safe dynamic column references in Go.
  • Self-documenting Queries: Type-safe column references make your queries clearer and more descriptive, aiding collaboration and future maintenance.
  • Reduced Debugging Effort: Locating column-related bugs is easier since all references use well-defined constants.
  • Minimized Human Error: Avoid typos and hardcoded values that lead to runtime errors by centralizing column definitions.
  • Seamless Model Synchronization: Model changes are consistently reflected in your queries, ensuring your application always uses up-to-date column definitions.

Example Usage

In addition to the type-safe queries previously shown, gormcnm also supports complex and flexible operations such as updating multiple columns with conditions. Here's a comprehensive example:

Updating Columns with Conditions
result := db.Model(&Example{}).Where(
    Qx(columnName.Eq("aaa")).
        AND(
            Qx(columnType.Eq("xxx")),
            Qx(columnRank.Eq(123)),
        ).Qx3(),
).UpdateColumns(columnRank.Kw(100).Kw(columnType.Kv("zzz")).AsMap())
require.NoError(t, result.Error)
require.Equal(t, int64(1), result.RowsAffected)

Automatically Generated Column Definitions

To make things even more efficient, you can use the gormcngen package to automatically generate column definitions for your models. The generated code might look like this:

type ExampleColumns struct {
    Name gormcnm.ColumnName[string]
    Type gormcnm.ColumnName[string]
    Rank gormcnm.ColumnName[int]
}

func (*Example) Columns() *ExampleColumns {
    return &ExampleColumns{
        Name: "name",
        Type: "type",
        Rank: "rank",
    }
}

From now on, you can retrieve the column name like Example::getName in MyBatis Plus, obtain the column name class object with cls = res.Columns(), and then use cls.Name.Eq("abc") for the query in GORM.

Using Auto-Generated Column Definitions in Queries

Once the columns are generated, you can use them in your queries:

var res models.Example
var cls = res.Columns()
if err := db.Where(cls.Name.Eq("abc")).
    Where(cls.Type.Eq("xyz")).
    Where(cls.Rank.Gt(100)).
    Where(cls.Rank.Lt(200)).
    First(&res).Error; err != nil {
    panic(errors.WithMessage(err, "wrong"))
}
fmt.Println(res)
Retrieving Data with Conditions Using gormcnm

Here’s an example demonstrating how to use gormcnm for retrieving data based on complex conditions:

var res models.Example
var cls = res.Columns()
require.NoError(t, db.Where(
    Qx(cls.Name.BetweenAND("aba", "abd")).
        AND(
            Qx(cls.Type.IsNotNULL()),
        ).Qx2(),
).First(&one).Error)
require.Equal(t, "abc", res.Name)

Usage

Simply import the package:

import "github.com/yyle88/gormcnm"

Why Use gormcnm?

  1. Reliable Refactoring: Confidently rename fields or change types knowing that all column references will remain consistent.
  2. Enhanced Safety: Compile-time validation ensures no mismatches or incorrect references.
  3. Productivity Boost: Type-safe column references and IDE auto-completion save development time and reduce errors.
  4. Progressive Adoption: Designed for gradual integration, letting you start small and scale as needed without disrupting your workflow.
  5. Clean and Maintainable Code: Queries are more readable and self-explanatory, improving collaboration and future modifications.
  6. Fewer Runtime Bugs: Centralized column definitions reduce the chances of human error.
  7. Automatic Code Generation: The gormcngen package simplifies setup, automating column definition generation.

Conclusion

gormcnm brings a simple, type-safe, and productive approach to working with GORM in Go. By removing hardcoded column names and leveraging Go's generics, it ensures that your database queries are safe, consistent, and easy to maintain. Whether you're building small applications or managing complex systems, gormcnm helps you write robust, refactor-friendly code, accelerating development and improving the quality of your work.

By adopting gormcnm, you can significantly enhance the quality of your GORM queries, reduce human error, and accelerate development—all while maintaining a clean, maintainable codebase.


Design Ideas

CREATION_IDEAS && README OLD DOC


License

gormcnm is open-source and released under the MIT License. See the LICENSE file for more information.


Support

Welcome to contribute to this project by submitting pull requests or reporting issues.

If you find this package helpful, give it a star on GitHub!

Thank you for your support!

Happy Coding with gormcnm! 🎉

Give me stars. Thank you!!!

See stars

see stars

Documentation

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
}

func NewCoalesceNonNullGuardian

func NewCoalesceNonNullGuardian(methodName string, columnName string) *CoalesceNonNullGuardian

func (*CoalesceNonNullGuardian) AvgStmt

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

AvgStmt generates a 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 a 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 a 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 a 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 a 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 for use in SQL queries ColumnName 表示一个通用的列名 可用于 SQL 查询

func Cnm added in v1.0.44

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

func New added in v1.0.44

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

func (ColumnName[TYPE]) AsAlias

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

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

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

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 for the column using the provided operator (e.g., '=', '>', etc.). ColumnCondition: 使用提供的运算符(例如 '=', '>', 等)为列创建条件。

func (ColumnName[TYPE]) ColumnConditionWithValue

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

ColumnConditionWithValue creates a condition with an operator and a value for the column, useful for building complex queries. ColumnConditionWithValue: 创建带有运算符和值的列条件,用于构建复杂的查询。

func (ColumnName[TYPE]) ColumnKeyAndValue

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

ColumnKeyAndValue returns a key-value, useful for GORM's Update function. ColumnKeyAndValue: 返回键值对,适用于GORM的Update函数。

func (ColumnName[TYPE]) Count

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

Count creates a COUNT query for 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 query for 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 key-value. 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 is equal to a given value. Eq 创建一个 SQL 语句来判断列是否等于给定的值。

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]) 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 greater 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 is greater than or equal to a given value. Gte 创建一个 SQL 语句来判断列是否大于等于给定的值。

func (ColumnName[TYPE]) IFNULLFN

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

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 for updates where a value is added to the field (e.g., incrementing a value). KeAdd: 用于更新字段时,将一个值加到字段上(例如递增一个值)。

func (ColumnName[TYPE]) KeExp

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

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

func (ColumnName[TYPE]) KeSub

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

KeSub is used for updates where a value is subtracted from the field (e.g., decrementing a value). KeSub: 用于更新字段时,将一个值从字段中减去(例如递减一个值)。

func (ColumnName[TYPE]) Kv

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

Kv returns a key-value, 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 key-value. 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 is less than or equal to a given value. Lte 创建一个 SQL 语句来判断列是否小于等于给定的值。

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 equal to a given value. Ne 创建一个 SQL 语句来判断列是否不等于给定的值。

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 equal to 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 order-by clause for the column with the specified direction (ASC or DESC). Ob: 创建一个带有指定方向(ASC或DESC)的ORDER BY子句。

func (ColumnName[TYPE]) Op

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

Op creates a SQL statement with an operator and a parameter. Op 创建一个带有操作符和参数的 SQL 语句。

func (ColumnName[TYPE]) OrderByDirection

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

OrderByDirection creates an order-by clause for the column with the given direction (ASC or DESC). OrderByDirection: 创建一个带有给定方向(ASC或DESC)的ORDER BY子句。

func (ColumnName[TYPE]) Qc

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

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

func (ColumnName[TYPE]) Qs

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

Qs creates a SQL statement with a given operator. Qs 创建一个带有指定操作符的 SQL 语句。

func (ColumnName[TYPE]) Qx

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

Qx creates a condition with an operator and a value for the column, useful for building 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 by enclosing it in backticks. SafeCnm 返回一个安全的列名,将其用反引号括起来。 If the column name conflicts with a SQL keyword (e.g., "create"), enclosing it in backticks ensures proper execution. 如果列名与SQL关键字(例如"create")冲突,使用反引号将其括起来,确保正确执行。 This function is useful when using db.Select("`type`").Find(&one) as an example. 该函数在使用 db.Select("`type`").Find(&one) 等查询时非常有用。

func (ColumnName[TYPE]) TB

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

func (ColumnName[TYPE]) TC

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

func (ColumnName[TYPE]) TN

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

func (ColumnName[TYPE]) WithTable

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

func (ColumnName[TYPE]) WithTableName

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

type ColumnOperationClass

type ColumnOperationClass struct{}

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

func (*ColumnOperationClass) CROSSJOIN

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

CROSSJOIN creates a cross join operation for 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) 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 for 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 for 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) 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 boolean condition. Its primary purpose is to offer a compact scope in which variables are valid only within the conditional block. This helps improve code clarity by limiting the scope of variables and making the logic easier to follow. 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 for 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. ColumnValueMap 是一个用于 GORM 更新逻辑的映射类型,用于表示列与值的对应关系表。

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 is an alias for converting ColumnValueMap to map[string]interface{}. AsMap 是将 ColumnValueMap 转换为 map[string]interface{} 的别名。

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. Kws 将 ColumnValueMap 转换为 GORM 的 map[string]interface{}。

func (ColumnValueMap) Map

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

Map is an alias for converting ColumnValueMap to map[string]interface{}. Map 是将 ColumnValueMap 转换为 map[string]interface{} 的别名。

func (ColumnValueMap) ToMap

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

ToMap is an alias for converting ColumnValueMap to map[string]interface{}. ToMap 是将 ColumnValueMap 转换为 map[string]interface{} 的别名。

type OrderByBottle

type OrderByBottle string

OrderByBottle represents a sort statement builder, 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) Ox

func (ob OrderByBottle) Ox() string

Ox converts the OrderByBottle to a string. Note that if the type is not specific, it may 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 字段逻辑的处理所造成的无法避免的限制。 Users may forget to convert this to a string before passing it to GORM, so it is important to remember this step. 用户可能会忘记在传递给 GORM 之前将其转换为字符串,因此需要记住这一点。 There is currently no elegant solution to this limitation, but it should work fine for personal use. 目前没有优雅的解决方案,但对于个人使用来说应该没有问题。

type QsConjunction

type QsConjunction string

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

func NewQsConjunction

func NewQsConjunction(stmt string) 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 converts 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 directly using QsConjunction 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

func NewQs

func NewQs(stmt string) QsType

type QxConjunction

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

QxConjunction is used for constructing relational query statements (AND, OR, NOT) and their arguments for db.Where. 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 a 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 returns 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 returns 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) Qx10

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

func (QxConjunction) Qx11

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

func (QxConjunction) Qx12

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

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 这块暂时没有什么好的方案,我只能这样罗列下来,很期望将来能够解决这个问题

func (QxConjunction) Qx4

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

Qx4 这块暂时没有什么好的方案,我只能这样罗列下来,很期望将来能够解决这个问题

func (QxConjunction) Qx5

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

func (QxConjunction) Qx6

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

func (QxConjunction) Qx7

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

func (QxConjunction) Qx8

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

func (QxConjunction) Qx9

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

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

func NewQx

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

type SelectStatement

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

SelectStatement 就是传给 db.Select 的语句和参数 目前 "选中返回列" 的函数的定义是这样的 func (db *DB) Select(query interface{}, args ...interface{}) (tx *DB) 在99%的场景下都是不需要传条件的 但在 SELECT COUNT(CASE WHEN (((name="abc") AND (type="xyz"))) THEN 1 END) as cnt FROM `examples` 这个语句里 很明显的 db.Select 也需要查询语句和参数 "abc" 和 "xyz" 而且这里条件有可能很长,而且有可能 db.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 returns the arguments list of the current statementArgumentsTuple instance. Args 返回当前 statementArgumentsTuple 实例的参数列表。

func (*SelectStatement) Combine

func (selectStatement *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 returns 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) Qx10

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

func (SelectStatement) Qx11

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

func (SelectStatement) Qx12

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

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 这块暂时没有什么好的方案,我只能这样罗列下来,很期望将来能够解决这个问题

func (SelectStatement) Qx4

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

Qx4 这块暂时没有什么好的方案,我只能这样罗列下来,很期望将来能够解决这个问题

func (SelectStatement) Qx5

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

func (SelectStatement) Qx6

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

func (SelectStatement) Qx7

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

func (SelectStatement) Qx8

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

func (SelectStatement) Qx9

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

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

func NewSx

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

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 for 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 equality condition in SQL format, ensuring type consistency between two columns. Eq 生成 SQL 格式的相等条件,确保两列之间的类型一致。

func (*TableColumn[TYPE]) Name

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

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

func (*TableColumn[TYPE]) Ob

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

Ob creates an OrderByBottle object for specifying 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 使用指定的操作符生成两列之间的自定义 SQL 操作。

type TableJoin added in v1.0.45

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

TableJoin represents a join operation on a table, including its type and name. TableJoin 表示表上的连接操作,包括连接类型和表名。

func (*TableJoin) On added in v1.0.45

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
internal

Jump to

Keyboard shortcuts

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