constant

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:03:27 * @FilePath: \go-sqlbuilder\constant\adapter.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:03:33 * @FilePath: \go-sqlbuilder\constant\config.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:03:15 * @FilePath: \go-sqlbuilder\constant\error.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-14 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-14 00:00:00 * @FilePath: \go-sqlbuilder\constant\field.go * @Description: 数据库字段名常量 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-14 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-14 00:00:00 * @FilePath: \go-sqlbuilder\constant\hook.go * @Description: 钩子事件常量 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:03:58 * @FilePath: \go-sqlbuilder\constant\logger.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:03:15 * @FilePath: \go-sqlbuilder\constant\error.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:03:15 * @FilePath: \go-sqlbuilder\constant\error.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-14 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-14 00:00:00 * @FilePath: \go-sqlbuilder\constant\operation.go * @Description: 数据库操作类型常量 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:04:19 * @FilePath: \go-sqlbuilder\constant\operator.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:04:25 * @FilePath: \go-sqlbuilder\constant\query.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:04:30 * @FilePath: \go-sqlbuilder\constant\sort.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:03:15 * @FilePath: \go-sqlbuilder\constant\error.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:03:15 * @FilePath: \go-sqlbuilder\constant\error.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

Index

Constants

View Source
const (
	AdapterTypeGORM     = "gorm"
	AdapterTypeSQLX     = "sqlx"
	AdapterTypeDatabase = "database"
	AdapterTypeCustom   = "custom"
)
View Source
const (
	DialectMySQL     = "mysql"
	DialectPostgres  = "postgres"
	DialectSQLite    = "sqlite"
	DialectSQLServer = "sqlserver"
)
View Source
const (
	ParameterPlaceholder = "?"
	ParameterStyle       = "question"
)
View Source
const (
	DefaultPageSize      = 10
	DefaultTimeout       = 30 // seconds
	DefaultMaxPoolSize   = 100
	DefaultMaxIdleConns  = 10
	DefaultCacheTTL      = 3600 // seconds
	DefaultSlowQueryTime = 100  // milliseconds
)

Default configuration constants

View Source
const (
	ConfigKeyShowSQL      = "show_sql"
	ConfigKeyLogLevel     = "log_level"
	ConfigKeyLogFile      = "log_file"
	ConfigKeyMaxRetries   = "max_retries"
	ConfigKeyCacheEnabled = "cache_enabled"
)

Configuration keys

View Source
const (
	// Operator errors
	ErrUnknownOperator = "unknown operator: %s"

	// Filter errors
	ErrInvalidFilterField = "invalid filter field: %s"
	ErrInvalidFilterValue = "invalid filter value for operator %s"

	// Query errors
	ErrEmptyTable        = "table name cannot be empty"
	ErrInvalidPagination = "invalid pagination parameters"

	// Database errors
	ErrNoDatabaseConnection = "no database connection available"
	ErrTransactionFailed    = "transaction failed: %w"

	// Cache errors
	ErrCacheKeyNotFound = "cache key not found"
	ErrCacheFailed      = "cache operation failed: %w"
)

Error message constants

View Source
const (
	// 时间戳字段
	FieldCreatedAt = "created_at"
	FieldUpdatedAt = "updated_at"
	FieldDeletedAt = "deleted_at"

	// 用户信息字段
	FieldCreatedBy = "created_by"
	FieldUpdatedBy = "updated_by"
	FieldDeletedBy = "deleted_by"

	// 版本控制字段
	FieldVersion  = "version"
	FieldRevision = "revision"

	// 通用字段
	FieldID          = "id"
	FieldName        = "name"
	FieldStatus      = "status"
	FieldIsDeleted   = "is_deleted"
	FieldIsActive    = "is_active"
	FieldRemark      = "remark"
	FieldDescription = "description"
)

审计字段名常量

View Source
const (
	DefaultDeletedValue    = 1
	DefaultNotDeletedValue = 0
	DefaultActiveValue     = 1
	DefaultInactiveValue   = 0
)

默认字段值常量

View Source
const (
	// 创建操作钩子
	HookEventBeforeCreate = "before_create"
	HookEventAfterCreate  = "after_create"

	// 更新操作钩子
	HookEventBeforeUpdate = "before_update"
	HookEventAfterUpdate  = "after_update"

	// 删除操作钩子
	HookEventBeforeDelete = "before_delete"
	HookEventAfterDelete  = "after_delete"

	// 查询操作钩子
	HookEventBeforeQuery = "before_query"
	HookEventAfterQuery  = "after_query"

	// 保存操作钩子 (upsert)
	HookEventBeforeSave = "before_save"
	HookEventAfterSave  = "after_save"

	// 批量操作钩子
	HookEventBeforeBatch = "before_batch"
	HookEventAfterBatch  = "after_batch"

	// 事务钩子
	HookEventBeforeTransaction = "before_transaction"
	HookEventAfterTransaction  = "after_transaction"
	HookEventBeforeCommit      = "before_commit"
	HookEventAfterCommit       = "after_commit"
	HookEventBeforeRollback    = "before_rollback"
	HookEventAfterRollback     = "after_rollback"
)

钩子事件常量

View Source
const (
	ComponentCore       = "core"
	ComponentExecutor   = "executor"
	ComponentCompiler   = "compiler"
	ComponentAdapter    = "adapter"
	ComponentRepository = "repository"
	ComponentCache      = "cache"
	ComponentMiddleware = "middleware"
)

Logger component names

View Source
const (
	EventQueryStart          = "query_start"
	EventQueryComplete       = "query_complete"
	EventQueryError          = "query_error"
	EventTransactionStart    = "transaction_start"
	EventTransactionCommit   = "transaction_commit"
	EventTransactionRollback = "transaction_rollback"
	EventCacheHit            = "cache_hit"
	EventCacheMiss           = "cache_miss"
)

Logger event names

View Source
const (
	ContextKeySQL          = "sql"
	ContextKeyDuration     = "duration"
	ContextKeyRowsAffected = "rows_affected"
	ContextKeyError        = "error"
	ContextKeyComponent    = "component"
)

Logger context keys

View Source
const (
	MsgQueryExecuted         = "query executed successfully"
	MsgTransactionStarted    = "transaction started"
	MsgTransactionCommitted  = "transaction committed"
	MsgTransactionRolledback = "transaction rolled back"
	MsgCacheMiss             = "cache miss for key: %s"
	MsgCacheHit              = "cache hit for key: %s"
)

Operation messages

View Source
const (
	MiddlewareTypeLogging        = "logging"
	MiddlewareTypeMetrics        = "metrics"
	MiddlewareTypeRetry          = "retry"
	MiddlewareTypeTimeout        = "timeout"
	MiddlewareTypeValidation     = "validation"
	MiddlewareTypeCircuitBreaker = "circuit_breaker"
	MiddlewareTypeRateLimit      = "rate_limit"
)
View Source
const (
	HookTypeBeforeExecution = "before_execution"
	HookTypeAfterExecution  = "after_execution"
	HookTypeOnError         = "on_error"
)
View Source
const (
	DefaultRetryCount              = 3
	DefaultRetryDelay              = 100
	DefaultCircuitBreakerThreshold = 5
	DefaultRateLimit               = 1000
)
View Source
const (
	// 基本CRUD操作
	OperationTypeCreate = "create"
	OperationTypeRead   = "read"
	OperationTypeUpdate = "update"
	OperationTypeDelete = "delete"
	OperationTypeUpsert = "upsert"
	OperationTypeQuery  = "query"

	// 批量操作
	OperationTypeBatchInsert = "batch_insert"
	OperationTypeBatchUpdate = "batch_update"
	OperationTypeBatchDelete = "batch_delete"
	OperationTypeBatchUpsert = "batch_upsert"

	// 事务操作
	OperationTypeTransaction = "transaction"
	OperationTypeCommit      = "commit"
	OperationTypeRollback    = "rollback"

	// 其他操作
	OperationTypeCount     = "count"
	OperationTypeExists    = "exists"
	OperationTypeAggregate = "aggregate"
)

数据库操作类型常量

View Source
const (
	// go-core 兼容
	OP_COMPAT_LT  = "lt"
	OP_COMPAT_GT  = "gt"
	OP_COMPAT_LTE = "lte"
	OP_COMPAT_GTE = "gte"
	OP_COMPAT_EQ  = "eq"
	OP_COMPAT_NEQ = "neq"
	OP_COMPAT_LK  = "lk"
)

兼容操作符映射

View Source
const (
	ParamPage     = "page"
	ParamPageSize = "pageSize"
	ParamOffset   = "offset"
	ParamLimit    = "limit"
	ParamSort     = "sort"
	ParamOrder    = "order"
	ParamFilter   = "filter"
	ParamSearch   = "search"
	ParamFields   = "fields"
	ParamInclude  = "include"
	ParamExclude  = "exclude"
)
View Source
const (
	ConditionKeyFilters    = "filters"
	ConditionKeyOrders     = "orders"
	ConditionKeyPagination = "pagination"
)
View Source
const (
	MinPageNumber = 1
	MinPageSize   = 1
	MaxPageSize   = 1000
	DefaultPage   = 1
)
View Source
const (
	OrderASC  = "ASC"
	OrderDESC = "DESC"
)

Sort order constants

View Source
const (
	SQL_SELECT   = "SELECT"
	SQL_INSERT   = "INSERT INTO"
	SQL_UPDATE   = "UPDATE"
	SQL_DELETE   = "DELETE FROM"
	SQL_WHERE    = "WHERE"
	SQL_AND      = "AND"
	SQL_OR       = "OR"
	SQL_ORDER_BY = "ORDER BY"
	SQL_LIMIT    = "LIMIT"
	SQL_OFFSET   = "OFFSET"
	SQL_DISTINCT = "DISTINCT"
	SQL_GROUP_BY = "GROUP BY"
	SQL_HAVING   = "HAVING"
	SQL_JOIN     = "JOIN"
	SQL_INNER    = "INNER"
	SQL_LEFT     = "LEFT"
	SQL_RIGHT    = "RIGHT"
	SQL_FULL     = "FULL"
)

SQL keyword constants

View Source
const (
	ErrFilterFieldEmpty    = "filter field cannot be empty"
	ErrFilterValueNil      = "filter value cannot be nil"
	ErrFilterOperatorEmpty = "filter operator cannot be empty"
)

Filter error messages

View Source
const (
	ErrOrderFieldEmpty   = "order field cannot be empty"
	ErrOrderValueInvalid = "invalid order value"
)

Order error messages

View Source
const (
	ErrPaginationLimitInvalid  = "pagination limit must be positive"
	ErrPaginationOffsetInvalid = "pagination offset must be non-negative"
	ErrPaginationPageInvalid   = "invalid page number (must be positive)"
	ErrPaginationSizeInvalid   = "invalid page size (must be positive)"
)

Pagination error messages

View Source
const (
	ErrQueryNil          = "query cannot be nil"
	ErrQueryFieldEmpty   = "query field cannot be empty"
	ErrQueryConditionNil = "query condition cannot be nil"
)

Query error messages

View Source
const (
	ErrOperatorEmpty        = "operator cannot be empty"
	ErrOperatorNotSupported = "operator not supported: %s"
)

Operator error messages

View Source
const (
	ErrValueNil          = "%s value cannot be nil"
	ErrValueEmpty        = "%s value cannot be empty"
	ErrValueInvalid      = "%s value is invalid"
	ErrValueTypeMismatch = "value type mismatch: expected %s, got %s"
)

Value validation error messages

View Source
const (
	ErrInputInvalid  = "invalid input parameter"
	ErrParamRequired = "parameter %s is required"
	ErrParamInvalid  = "parameter %s is invalid"
)

General error messages

View Source
const DefaultSortOrder = OrderASC

Default sort order

View Source
const SortFieldPlaceholder = "%s %s"

Sort field placeholder

Variables

CompatOperatorMap 兼容操作符映射

View Source
var OperatorMap = map[string]Operator{
	"=":           OP_EQ,
	"!=":          OP_NEQ,
	">":           OP_GT,
	">=":          OP_GTE,
	"<":           OP_LT,
	"<=":          OP_LTE,
	"LIKE":        OP_LIKE,
	"NOT LIKE":    OP_NOT_LIKE,
	"IN":          OP_IN,
	"NOT IN":      OP_NOT_IN,
	"BETWEEN":     OP_BETWEEN,
	"IS NULL":     OP_IS_NULL,
	"IS NOT NULL": OP_IS_NOT_NULL,
	"FIND_IN_SET": OP_FIND_IN_SET,
}

OperatorMap 操作符映射表

Functions

This section is empty.

Types

type Operator

type Operator string

Operator 操作符常量

const (
	// 比较操作符
	OP_EQ  Operator = "="
	OP_NEQ Operator = "!="
	OP_GT  Operator = ">"
	OP_GTE Operator = ">="
	OP_LT  Operator = "<"
	OP_LTE Operator = "<="

	// 字符串操作符
	OP_LIKE     Operator = "LIKE"
	OP_NOT_LIKE Operator = "NOT LIKE"

	// 集合操作符
	OP_IN      Operator = "IN"
	OP_NOT_IN  Operator = "NOT IN"
	OP_BETWEEN Operator = "BETWEEN"

	// 空值操作符
	OP_IS_NULL     Operator = "IS NULL"
	OP_IS_NOT_NULL Operator = "IS NOT NULL"

	// MySQL 特定
	OP_FIND_IN_SET Operator = "FIND_IN_SET"

	// 逻辑操作符
	LOGIC_AND Operator = "AND"
	LOGIC_OR  Operator = "OR"
)

Jump to

Keyboard shortcuts

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