db

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SqlParamParserDefaultParamBefore = "\\${"
	SqlParamParserDefaultParamAfter  = "}"
)
View Source
var (
	DefaultModelOption = NewModelOption()
)
View Source
var (
	DefaultSqlOption = NewSqlOption()
)
View Source
var (
	ErrorHasMoreRows = errors.New("has more rows by query one")
)
View Source
var (
	ErrorNotSupportCreateTable = errors.New("not support create table")
)

Functions

func AddDialectByConfigDir

func AddDialectByConfigDir(configDir string) (err error)

func AddDialectByConfigFile

func AddDialectByConfigFile(configFile string) (err error)

func DoExec

func DoExec(ctx context.Context, sqlConn SqlConn, sqlInfo string, args []interface{}, showSql bool) (result sql.Result, err error)

func DoExecBatch

func DoExecBatch(ctx context.Context, sqlConn SqlConn, sqlInfo string, argsList [][]interface{}, showSql bool) (res []sql.Result, err error)

func DoExecs

func DoExecs(ctx context.Context, sqlConn SqlConn, sqlList []string, argsList [][]interface{}, showSql bool) (resultList []sql.Result, errSql string, errArgs []interface{}, err error)

func DoQuery

func DoQuery(ctx context.Context, sqlConn SqlConn, sqlInfo string, args []interface{}, showSql bool, getSqlValue GetSqlValueType) (list []map[string]interface{}, err error)

func DoQueryCount

func DoQueryCount(ctx context.Context, sqlConn SqlConn, sqlInfo string, args []interface{}, showSql bool) (count int64, err error)

func DoQueryListStruct

func DoQueryListStruct[S any](ctx context.Context, sqlConn SqlConn, sqlInfo string, args []interface{}, showSql bool, modelOption *ModelOption) (list []S, err error)

func DoQueryListStructWithService

func DoQueryListStructWithService[S any](ctx context.Context, service IService, sqlInfo string, args []interface{}) (res []S, err error)

func DoQueryListWithModel

func DoQueryListWithModel[S any](ctx context.Context, s IModelSql) (res []S, err error)

func DoQueryListWithSql

func DoQueryListWithSql[S any](ctx context.Context, service IService, sqlInfo string, sqlArgs []any) (res []S, err error)

func DoQueryOne

func DoQueryOne(ctx context.Context, sqlConn SqlConn, sqlInfo string, args []interface{}, showSql bool, getSqlValue GetSqlValueType) (data map[string]interface{}, err error)

func DoQueryOneStruct

func DoQueryOneStruct[S any](ctx context.Context, sqlConn SqlConn, sqlInfo string, args []interface{}, showSql bool, modelOption *ModelOption) (res S, err error)

func DoQueryOneStructWithService

func DoQueryOneStructWithService[S any](ctx context.Context, service IService, sqlInfo string, args []interface{}) (res S, err error)

func DoQueryOneWithModel

func DoQueryOneWithModel[S any](ctx context.Context, s IModelSql) (res S, err error)

func DoQueryOneWithSql

func DoQueryOneWithSql[S any](ctx context.Context, service IService, sqlInfo string, sqlArgs []any) (res S, err error)

func DoQueryPageWithModel

func DoQueryPageWithModel[S any](ctx context.Context, s IModelSql, pageSize int64, pageNo int64) (res []S, err error)

func DoQueryPageWithSql

func DoQueryPageWithSql[S any](ctx context.Context, service IService, sqlInfo string, sqlArgs []any, pageSize int64, pageNo int64) (res []S, err error)

func DoQueryWithColumnTypes

func DoQueryWithColumnTypes(ctx context.Context, sqlConn SqlConn, sqlInfo string, args []interface{}, showSql bool, getSqlValue GetSqlValueType) (columns []string, columnTypes []*sql.ColumnType, list []map[string]any, err error)

func DoTxExec

func DoTxExec(ctx context.Context, sqlConn SqlConn, sqlInfo string, args []interface{}, showSql bool) (result sql.Result, err error)

func DoTxExecs

func DoTxExecs(ctx context.Context, sqlConn SqlConn, sqlList []string, argsList [][]interface{}, showSql bool) (resultList []sql.Result, errSql string, errArgs []interface{}, err error)

func FormatColumnType

func FormatColumnType(columnType string) (dataType string, length int, precision int, scale int)

func FormatDriverDSN

func FormatDriverDSN(driverDSN string, dbCfg *Config, isUrl bool, paramSpaceChar string, canPathEscape bool, defaultParams map[string]string, params map[string]string) string

func GetBaseTypeValue

func GetBaseTypeValue(data any) (res any, is bool)

func GetInsertOrUpdateColumnValues

func GetInsertOrUpdateColumnValues(list []*InsertOrUpdateValue) (columns []string, values []*util.FieldValue)

func GetParamValue

func GetParamValue(dbCfg *Config, name string) string

func GetSqlValue

func GetSqlValue(columnType *sql.ColumnType, data any) (value any)

func GetStringValue

func GetStringValue(value any) (valueString string)

func HasNewLine

func HasNewLine(str string) bool
func IsWhiteSpace(char string) bool {
	switch char {
	case " ", "\t", "\v", "\u00a0", "'\ufeff'":
		return true
	case "\n", "\r":
		return true
	}
	return false
}

func IsFloat

func IsFloat(s string) bool

func IsIdentifier

func IsIdentifier(s string) bool

func IsInt

func IsInt(s string) bool

func IsInt64Value

func IsInt64Value(value any) (res int64, ok bool)

func IsNumber

func IsNumber(s string) bool

func IsTrue

func IsTrue(arg any) bool

func IsWhiteSpace

func IsWhiteSpace(s string) bool

func NewSqlDb

func NewSqlDb(cfg *Config) (sqlDb *sql.DB, err error)

func ParserToFormat

func ParserToFormat(str string) (formatStr string, names []string)

ParserToFormat 解析 字符串参数 将 `xx{name}xx{xx}` 转为 `xx{0}xx{1}` 如:{user}:{password}@tcp({host}:{port})/{database}?charset=utf8&parseTime=true&{urlParams}

func SqlParamParse

func SqlParamParse(sqlInfo string, param any) (string, []any, error)

func SqlTemplateHasContent

func SqlTemplateHasContent(t *SqlTemplate) bool

func TableColumnAdd

func TableColumnAdd(dbService IService, moduleName, version, tableName string, column *Column) (err error)

func TableColumnDrop

func TableColumnDrop(dbService IService, moduleName, version, tableName string, columnName string) (err error)

func TableCreate

func TableCreate(dbService IService, moduleName, version, tableName string, table *Table) (err error)

func TableIndexAdd

func TableIndexAdd(dbService IService, moduleName, version, tableName string, index *Index) (err error)

func TableIndexDrop

func TableIndexDrop(dbService IService, moduleName, version, tableName string, indexName string) (err error)

func ToInt64Value

func ToInt64Value(value any) (res int64, err error)

func ToIntValue

func ToIntValue(value any) (res int, err error)

func ToKeyValueParams

func ToKeyValueParams(params map[string]string, paramSpaceChar string) (res string)

func ToUrlParams

func ToUrlParams(params map[string]string) (res string)

Types

type ChangeSqlReader

type ChangeSqlReader func(r *SqlReader)

type Column

type Column struct {
	DatabaseName string `json:"databaseName,omitempty"`
	SchemaName   string `json:"schemaName,omitempty"`
	TableName    string `json:"tableName,omitempty"`

	Name      string `json:"name,omitempty"`
	Comment   string `json:"comment,omitempty"`
	Type      string `json:"type,omitempty"`
	DataType  string `json:"dataType,omitempty"`
	Default   string `json:"default,omitempty"`
	Length    int    `json:"length,omitempty"`
	Precision int    `json:"precision,omitempty"`
	Scale     int    `json:"scale,omitempty"`

	Key bool `json:"key,omitempty"`

	AutoIncrement       bool   `json:"autoIncrement,omitempty"`
	AutoIncrementStart  int64  `json:"autoIncrementStart,omitempty"`
	AutoIncrementName   string `json:"autoIncrementName,omitempty"`
	AutoIncrementCreate bool   `json:"autoIncrementCreate,omitempty"`

	NotNull bool `json:"notNull,omitempty"`

	// 扩展属性
	Extend map[string]any `json:"extend,omitempty"`
}

func ColumnByMap

func ColumnByMap(data map[string]any) (res *Column)

func (*Column) Init

func (this_ *Column) Init(handler DDLHandler, databaseName string, schemaName string, tableName string)

type Condition

type Condition struct {
	WhereSql string
	Field    string
	Op       Op
	Value    any
	// 用于嵌套的子条件(AND/OR 组)
	Children *Conditions
	IsOr     bool // true 表示 OR 组,false 表示 AND 组(仅在有Children时有效)
}

Condition 表示一个条件(字段 + 操作符 + 值)

type Conditions

type Conditions []*Condition

func NewConditions

func NewConditions() *Conditions

func (*Conditions) And

func (cs *Conditions) And(field string, op Op, value any) *Conditions

And 添加 AND 条件(最常用)

func (*Conditions) AndGroup

func (cs *Conditions) AndGroup(sub *Conditions) *Conditions

AndGroup 添加一组 AND 条件(嵌套)

func (*Conditions) AndWhereSql

func (cs *Conditions) AndWhereSql(whereSql string) *Conditions

func (*Conditions) Build

func (cs *Conditions) Build(b *OrmSqlBuilder, s IService) (string, []any)

Build 构建 WHERE 子句和参数 返回:WHERE 字符串(不含 "WHERE" 关键字),参数切片

func (*Conditions) Custom

func (cs *Conditions) Custom(custom string, values []any) *Conditions

func (*Conditions) Eq

func (cs *Conditions) Eq(field string, value any) *Conditions

func (*Conditions) Gt

func (cs *Conditions) Gt(field string, value any) *Conditions

func (*Conditions) Gte

func (cs *Conditions) Gte(field string, value any) *Conditions

func (*Conditions) In

func (cs *Conditions) In(field string, values any) *Conditions

func (*Conditions) IsNotNull

func (cs *Conditions) IsNotNull(field string) *Conditions

func (*Conditions) IsNull

func (cs *Conditions) IsNull(field string) *Conditions

func (*Conditions) Like

func (cs *Conditions) Like(field string, pattern any) *Conditions

func (*Conditions) Lt

func (cs *Conditions) Lt(field string, value any) *Conditions

func (*Conditions) Lte

func (cs *Conditions) Lte(field string, value any) *Conditions

func (*Conditions) Ne

func (cs *Conditions) Ne(field string, value any) *Conditions

func (*Conditions) NotIn

func (cs *Conditions) NotIn(field string, values any) *Conditions

func (*Conditions) NotLike

func (cs *Conditions) NotLike(field string, pattern any) *Conditions

func (*Conditions) Or

func (cs *Conditions) Or(field string, op Op, value any) *Conditions

Or 添加 OR 条件(单条件)

func (*Conditions) OrCustom

func (cs *Conditions) OrCustom(custom string, values []any) *Conditions

func (*Conditions) OrEq

func (cs *Conditions) OrEq(field string, value any) *Conditions

func (*Conditions) OrGroup

func (cs *Conditions) OrGroup(sub *Conditions) *Conditions

OrGroup 添加一组 OR 条件(嵌套)

func (*Conditions) OrGt

func (cs *Conditions) OrGt(field string, value any) *Conditions

func (*Conditions) OrGte

func (cs *Conditions) OrGte(field string, value any) *Conditions

func (*Conditions) OrIn

func (cs *Conditions) OrIn(field string, values any) *Conditions

func (*Conditions) OrIsNotNull

func (cs *Conditions) OrIsNotNull(field string) *Conditions

func (*Conditions) OrIsNull

func (cs *Conditions) OrIsNull(field string) *Conditions

func (*Conditions) OrLike

func (cs *Conditions) OrLike(field string, pattern any) *Conditions

func (*Conditions) OrLt

func (cs *Conditions) OrLt(field string, value any) *Conditions

func (*Conditions) OrLte

func (cs *Conditions) OrLte(field string, value any) *Conditions

func (*Conditions) OrNe

func (cs *Conditions) OrNe(field string, value any) *Conditions

func (*Conditions) OrNotIn

func (cs *Conditions) OrNotIn(field string, values any) *Conditions

func (*Conditions) OrNotLike

func (cs *Conditions) OrNotLike(field string, pattern any) *Conditions

func (*Conditions) OrWhereSql

func (cs *Conditions) OrWhereSql(whereSql string) *Conditions

func (*Conditions) Where

func (cs *Conditions) Where(field string, value any) *Conditions

Where 快捷方式,等价于 And(field, Eq, value)

type Config

type Config struct {
	// Disabled 禁用 上层 初始化服务时候 可以判断该属性 如果为 配置 true 则不去初始化服务
	Disabled bool `json:"disabled,omitempty" yaml:"disabled,omitempty"`

	Type        string `json:"type,omitempty" yaml:"type,omitempty"`
	DialectType string `json:"dialectType,omitempty" yaml:"dialectType,omitempty"`

	Host     string `json:"host,omitempty" yaml:"host,omitempty"`
	Port     int    `json:"port,omitempty" yaml:"port,omitempty"`
	Address  string `json:"address,omitempty" yaml:"address,omitempty"`
	Username string `json:"username,omitempty" yaml:"username,omitempty"`
	Password string `json:"password,omitempty" yaml:"password,omitempty"`
	Database string `json:"database,omitempty" yaml:"database,omitempty"`
	Schema   string `json:"schema,omitempty" yaml:"schema,omitempty"`

	DatabasePath string `json:"databasePath,omitempty" yaml:"databasePath,omitempty"`

	ServerName string `json:"serverName,omitempty" yaml:"serverName,omitempty"`

	Dsn       string `json:"dsn,omitempty" yaml:"dsn,omitempty"`
	DsnAppend string `json:"dsnAppend,omitempty" yaml:"dsnAppend,omitempty"`

	MaxIdleConn int `json:"maxIdleConn,omitempty" yaml:"maxIdleConn,omitempty"`
	MaxOpenConn int `json:"maxOpenConn,omitempty" yaml:"maxOpenConn,omitempty"`

	TlsConfig     string `json:"tlsConfig,omitempty" yaml:"tlsConfig,omitempty"`
	TlsRootCert   string `json:"tlsRootCert,omitempty" yaml:"tlsRootCert,omitempty"`
	TlsClientCert string `json:"tlsClientCert,omitempty" yaml:"tlsClientCert,omitempty"`
	TlsClientKey  string `json:"tlsClientKey,omitempty" yaml:"tlsClientKey,omitempty"`
	// contains filtered or unexported fields
}

func (*Config) Clone

func (this_ *Config) Clone() (res *Config)

func (*Config) GetConnProxy

func (this_ *Config) GetConnProxy() ConnProxy

func (*Config) SetConnProxy

func (this_ *Config) SetConnProxy(connProxy ConnProxy)

func (*Config) SetGetDatabasePath

func (this_ *Config) SetGetDatabasePath(getDatabasePath func(cfg *Config) string)

type ConnProxy

type ConnProxy interface {
	Dial(n string, addr string) (net.Conn, error)
}

type Constraint

type Constraint struct {
	DatabaseName string `json:"databaseName,omitempty"`
	SchemaName   string `json:"schemaName,omitempty"`
	TableName    string `json:"tableName,omitempty"`

	Name        string   `json:"name,omitempty"`
	Comment     string   `json:"comment,omitempty"`
	Type        string   `json:"type,omitempty"`
	ColumnNames []string `json:"columnNames,omitempty"`

	// 引用表所在库
	ReferencedDatabaseName string `json:"referencedDatabaseName,omitempty"`
	// 引用表
	ReferencedTableName string `json:"referencedTableName,omitempty"`
	// 引用字段
	ReferencedColumnNames []string `json:"referencedColumnNames,omitempty"`

	IsPrimary bool `json:"isPrimary,omitempty"`
	IsUnique  bool `json:"isUnique,omitempty"`
	IsForeign bool `json:"isForeign,omitempty"`

	// 扩展属性
	Extend map[string]any `json:"extend,omitempty"`
	// contains filtered or unexported fields
}

func ConstraintListByColumns

func ConstraintListByColumns(columns []*ConstraintColumn) (res []*Constraint)

func (*Constraint) GenName

func (this_ *Constraint) GenName(databaseName string, schemaName string, tableName string) string

func (*Constraint) Init

func (this_ *Constraint) Init(handler DDLHandler, databaseName string, schemaName string, tableName string)

type ConstraintColumn

type ConstraintColumn struct {
	DatabaseName string `json:"databaseName,omitempty"`
	SchemaName   string `json:"schemaName,omitempty"`
	TableName    string `json:"tableName,omitempty"`

	Name        string `json:"name,omitempty"`
	Comment     string `json:"comment,omitempty"`
	Type        string `json:"type,omitempty"`
	ColumnName  string `json:"columnName,omitempty"`
	ColumnOrder int    `json:"columnOrder,omitempty"`

	// 引用表所在库
	ReferencedDatabaseName string `json:"referencedDatabaseName,omitempty"`
	// 引用表
	ReferencedTableName string `json:"referencedTableName,omitempty"`
	// 引用字段
	ReferencedColumnName string `json:"referencedColumnName,omitempty"`

	// 扩展属性
	Extend map[string]any `json:"extend,omitempty"`
}

func ConstraintColumnByMap

func ConstraintColumnByMap(data map[string]any) (res *ConstraintColumn)

type DDLHandler

type DDLHandler interface {
	WrapUserName(userName string) (res string)
	IsAppendDatabaseName() (res bool)
	WrapDatabaseName(databaseName string) (res string)
	IsAppendSchemaName() (res bool)
	WrapSchemaName(schemaName string) (res string)
	WrapTableName(tableName string) (res string)
	WrapColumnName(columnName string) (res string)
	WrapConstraintName(constraintName string) (res string)
	WrapIndexName(indexName string) (res string)
	WrapSequenceName(sequenceName string) (res string)
	WrapName(name string) (res string)
	WrapString(str string) (res string)
}

type DDLOption

type DDLOption struct {
	WrapOption
	// 是否 包装 用户名称 该配置 > NameWrap
	WrapUserNameOpen *bool `json:"wrapUserNameOpen,omitempty"`
	// 是否 包装 数据库名称 该配置 > NameWrap
	WrapDatabaseNameOpen *bool `json:"wrapDatabaseNameOpen,omitempty"`
	// 是否 包装 模式名称 该配置 > NameWrap
	WrapSchemaNameOpen *bool `json:"wrapSchemaNameOpen,omitempty"`
	// 是否 包装 约束名称 该配置 > NameWrap
	WrapConstraintNameOpen *bool `json:"wrapConstraintNameOpen,omitempty"`
	// 是否 包装 索引名称 该配置 > NameWrap
	WrapIndexNameOpen *bool `json:"wrapIndexNameOpen,omitempty"`
	// 是否 包装 序列名称 该配置 > NameWrap
	WrapSequenceNameOpen *bool `json:"wrapSequenceNameOpen,omitempty"`

	// 是否 追加 库名
	AppendDatabaseName *bool `json:"appendDatabaseName,omitempty"`
	// 是否 追加 模式名
	AppendSchemaName *bool `json:"appendSchemaName,omitempty"`
}

func NewDDLOption

func NewDDLOption() (res *DDLOption)

func (*DDLOption) IsAppendDatabaseName

func (this_ *DDLOption) IsAppendDatabaseName() bool

func (*DDLOption) IsAppendSchemaName

func (this_ *DDLOption) IsAppendSchemaName() bool

func (*DDLOption) IsWrapConstraintName

func (this_ *DDLOption) IsWrapConstraintName() bool

func (*DDLOption) IsWrapDatabaseName

func (this_ *DDLOption) IsWrapDatabaseName() bool

func (*DDLOption) IsWrapIndexName

func (this_ *DDLOption) IsWrapIndexName() bool

func (*DDLOption) IsWrapSchemaName

func (this_ *DDLOption) IsWrapSchemaName() bool

func (*DDLOption) IsWrapSequenceName

func (this_ *DDLOption) IsWrapSequenceName() bool

func (*DDLOption) IsWrapUserName

func (this_ *DDLOption) IsWrapUserName() bool

func (*DDLOption) WrapConstraintName

func (this_ *DDLOption) WrapConstraintName(name string) string

func (*DDLOption) WrapDatabaseName

func (this_ *DDLOption) WrapDatabaseName(name string) string

func (*DDLOption) WrapIndexName

func (this_ *DDLOption) WrapIndexName(name string) string

func (*DDLOption) WrapSchemaName

func (this_ *DDLOption) WrapSchemaName(name string) string

func (*DDLOption) WrapSequenceName

func (this_ *DDLOption) WrapSequenceName(name string) string

func (*DDLOption) WrapUserName

func (this_ *DDLOption) WrapUserName(name string) string

type Database

type Database struct {
	Name string `json:"name,omitempty"`

	IsSystem bool `json:"isSystem,omitempty"`

	IfNotExists bool `json:"ifNotExists,omitempty"`
	// 多数用于删除时候 串联删除相关内容
	Cascade bool `json:"cascade,omitempty"`
	// 扩展属性
	Extend map[string]any `json:"param,omitempty"`
}

func DatabaseByMap

func DatabaseByMap(data map[string]any) (res *Database)

type Dialect

type Dialect interface {
	Type() string
	Match() []string

	WrapNameChar() string
	WrapStringChar() string
	EscapeStringChar() string
	ArgChar() string

	FormatSqlArgChar(sqlInfo string) (res string)
	FormatPageSql(sqlInfo string, pageSize int64, pageNo int64) (res string)

	GetDriverName() string
	GetDriverDSN(dbCfg *Config, params map[string]string) string

	Open(dbCfg *Config, params map[string]string) (sqlDb *sql.DB, err error)

	Info() (info *Info)

	UserChange(sqlConn SqlConn, userName string, password string) (ok bool, err error)
	UserSelectSql(userName string) (sqlInfo string, sqlArgs []any)
	UserList(sqlConn SqlConn) (userList []*User, err error)
	User(sqlConn SqlConn, userName string) (user *User, err error)
	UserCreateFieldList() (sqlList []*Field)
	UserCreateSql(handler DDLHandler, user *User) (sqlList []string, sqlArgsList [][]any)
	UserCreate(sqlConn SqlConn, handler DDLHandler, user *User) (err error)
	UserDeleteSql(handler DDLHandler, userName string) (sqlList []string, sqlArgsList [][]any)
	UserDelete(sqlConn SqlConn, handler DDLHandler, userName string) (err error)

	DatabaseChange(sqlConn SqlConn, databaseName string) (ok bool, err error)
	DatabaseSelectSql(databaseName string) (sqlInfo string, sqlArgs []any)
	DatabaseList(sqlConn SqlConn) (databaseList []*Database, err error)
	Database(sqlConn SqlConn, databaseName string) (database *Database, err error)
	DatabaseCreateFieldList() (sqlList []*Field)
	DatabaseCreateSql(handler DDLHandler, database *Database) (sqlList []string, sqlArgsList [][]any)
	DatabaseCreate(sqlConn SqlConn, handler DDLHandler, database *Database) (err error)
	DatabaseDeleteSql(handler DDLHandler, databaseName string, cascade bool) (sqlList []string, sqlArgsList [][]any)
	DatabaseDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, cascade bool) (err error)

	SchemaChange(sqlConn SqlConn, schemaName string) (ok bool, err error)
	SchemaSelectSql(databaseName string, schemaName string) (sqlInfo string, sqlArgs []any)
	SchemaList(sqlConn SqlConn, databaseName string) (schemaList []*Schema, err error)
	Schema(sqlConn SqlConn, databaseName string, schemaName string) (schema *Schema, err error)
	SchemaCreateFieldList() (sqlList []*Field)
	SchemaCreateSql(handler DDLHandler, databaseName string, schema *Schema) (sqlList []string, sqlArgsList [][]any)
	SchemaCreate(sqlConn SqlConn, handler DDLHandler, databaseName string, schema *Schema) (err error)
	SchemaDeleteSql(handler DDLHandler, databaseName string, schemaName string, cascade bool) (sqlList []string, sqlArgsList [][]any)
	SchemaDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, cascade bool) (err error)

	SequenceSelectSql(databaseName string, schemaName string, sequenceName string) (sqlInfo string, sqlArgs []any)
	SequenceList(sqlConn SqlConn, databaseName string, schemaName string) (sequenceList []*Sequence, err error)
	Sequence(sqlConn SqlConn, databaseName string, schemaName string, sequenceName string) (sequence *Sequence, err error)
	SequenceCreateFieldList() (sqlList []*Field)
	SequenceCreateSql(handler DDLHandler, databaseName string, schemaName string, sequence *Sequence) (sqlList []string, sqlArgsList [][]any)
	SequenceCreate(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, sequence *Sequence) (err error)
	SequenceDeleteSql(handler DDLHandler, databaseName string, schemaName string, sequenceName string) (sqlList []string, sqlArgsList [][]any)
	SequenceDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, sequenceName string) (err error)

	TableCheckExists(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (exists bool)
	TableSelectSql(databaseName string, schemaName string, tableName string) (sqlInfo string, sqlArgs []any)
	TableList(sqlConn SqlConn, databaseName string, schemaName string) (tableList []*Table, err error)
	Table(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (table *Table, err error)
	TableDetail(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (table *Table, err error)
	TableCreateFieldList() (sqlList []*Field)
	TableCreateSql(handler DDLHandler, databaseName string, schemaName string, table *Table) (sqlList []string, sqlArgsList [][]any)
	TableCreate(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, table *Table) (err error)
	TableDeleteSql(handler DDLHandler, databaseName string, schemaName string, tableName string) (sqlList []string, sqlArgsList [][]any)
	TableDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string) (err error)

	ColumnCheckExists(sqlConn SqlConn, databaseName string, schemaName string, tableName string, columnName string) (exists bool)
	ColumnSelectSql(databaseName string, schemaName string, tableName string, columnName string) (sqlInfo string, sqlArgs []any)
	ColumnList(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (columnList []*Column, err error)
	Column(sqlConn SqlConn, databaseName string, schemaName string, tableName string, columnName string) (column *Column, err error)
	ColumnAddSql(handler DDLHandler, databaseName string, schemaName string, tableName string, column *Column) (sqlList []string, sqlArgsList [][]any)
	ColumnAdd(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, column *Column) (err error)
	ColumnUpdateSql(handler DDLHandler, databaseName string, schemaName string, tableName string, oldColumn *Column, column *Column) (sqlList []string, sqlArgsList [][]any)
	ColumnUpdate(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, oldColumn *Column, column *Column) (err error)
	ColumnDeleteSql(handler DDLHandler, databaseName string, schemaName string, tableName string, columnName string) (sqlList []string, sqlArgsList [][]any)
	ColumnDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, columnName string) (err error)

	ConstraintSelectSql(databaseName string, schemaName string, tableName string, constraintName string) (sqlInfo string, sqlArgs []any)
	ConstraintList(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (constraintList []*Constraint, err error)
	Constraint(sqlConn SqlConn, databaseName string, schemaName string, tableName string, constraintName string) (constraint *Constraint, err error)
	ConstraintAddSql(handler DDLHandler, databaseName string, schemaName string, tableName string, constraint *Constraint) (sqlList []string, sqlArgsList [][]any)
	ConstraintAdd(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, constraint *Constraint) (err error)
	ConstraintDeleteSql(handler DDLHandler, databaseName string, schemaName string, tableName string, constraintName string) (sqlList []string, sqlArgsList [][]any)
	ConstraintDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, constraintName string) (err error)

	IndexCheckExists(sqlConn SqlConn, databaseName string, schemaName string, tableName string, checkIndex *Index) (exists bool)
	IndexSelectSql(databaseName string, schemaName string, tableName string, indexName string) (sqlInfo string, sqlArgs []any)
	IndexList(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (indexList []*Index, err error)
	Index(sqlConn SqlConn, databaseName string, schemaName string, tableName string, indexName string) (index *Index, err error)
	IndexAddSql(handler DDLHandler, databaseName string, schemaName string, tableName string, index *Index) (sqlList []string, sqlArgsList [][]any)
	IndexAdd(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, index *Index) (err error)
	IndexDeleteSql(handler DDLHandler, databaseName string, schemaName string, tableName string, indexName string) (sqlList []string, sqlArgsList [][]any)
	IndexDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, indexName string) (err error)

	SqlConcat(args ...string) (res string)
}

func AddByDialectConfigBase64

func AddByDialectConfigBase64(dialectType string, cfgContent string) (dia Dialect, err error)

func AddDialect

func AddDialect(dia Dialect) Dialect

func GetDialect

func GetDialect(name string) Dialect

func NewDialect

func NewDialect(cfg *DialectConfig) Dialect

type DialectColumnConfig

type DialectColumnConfig struct {
	// 查询 SQL 字段:databaseName、schemaName、tableName;参数:databaseName、schemaName、tableName
	Select string `yaml:"select,omitempty"`
	// 创建 SQL 参数:databaseName、schemaName、tableName、加上表单字段
	Add           string `yaml:"add,omitempty"`
	Comment       string `yaml:"comment,omitempty"`
	Update        string `yaml:"update,omitempty"`
	UpdateRename  string `yaml:"updateRename,omitempty"`
	UpdateType    string `yaml:"updateType,omitempty"`
	UpdateNotNull string `yaml:"updateNotNull,omitempty"`
	UpdateDefault string `yaml:"updateDefault,omitempty"`
	// 删除 SQL 参数:databaseName、schemaName、tableName
	Delete string `yaml:"delete,omitempty"`
}

type DialectConfig

type DialectConfig struct {

	// 方言类型
	Type string `yaml:"type,omitempty"`
	// 查找方言 传入的类型 匹配 type 或 以下配置的字符 则使用该方言
	Match []string `yaml:"match,omitempty"`
	// 使用 其它方言作为基础数据,可以配置覆盖
	Extend string `yaml:"extend,omitempty"`
	// 驱动
	Driver *DialectDriverConfig `yaml:"driver,omitempty"`
	// 名称包裹字符 如:`name_1`、"name_1"
	NameWrapChar string `yaml:"nameWrapChar,omitempty"`
	// 名称 没有包装 则自动转大写
	NameNoWrapIsUpper bool `yaml:"nameNoWrapIsUpper,omitempty"`
	// 字符串包裹字符 如:'string_1'
	StringWrapChar string `yaml:"stringWrapChar,omitempty"`
	/// 字符串转义字符 如:'xx\'x'
	StringEscapeChar string `yaml:"stringEscapeChar,omitempty"`
	// 变量占位符 如:?、$num、:name、?num
	ArgChar string `yaml:"argChar,omitempty"`
	// 结构关系 如:database = schema
	Relation string `yaml:"relation,omitempty"`
	// 表单
	FormList []*Form `yaml:"formList,omitempty"`

	// 树形配置
	Tree []*DialectNodeConfig `yaml:"tree,omitempty"`

	// 用户
	User *DialectUserConfig `yaml:"user,omitempty"`
	// 库
	Database *DialectDatabaseConfig `yaml:"database,omitempty"`
	// 模式
	Schema *DialectSchemaConfig `yaml:"schema,omitempty"`
	// 序列
	Sequence *DialectSequenceConfig `yaml:"sequence,omitempty"`
	// 表
	Table *DialectTableConfig `yaml:"table,omitempty"`
	// 字段
	Column *DialectColumnConfig `yaml:"column,omitempty"`
	// 约束
	Constraint *DialectConstraintConfig `yaml:"constraint,omitempty"`
	// 索引
	Index *DialectIndexConfig `yaml:"index,omitempty"`

	TypeExtend bool                 `yaml:"typeExtend,omitempty"`
	TypeList   []*DialectTypeConfig `yaml:"typeList,omitempty"`

	FuncExtend bool                      `yaml:"funcExtend,omitempty"`
	FuncList   map[string]map[string]any `yaml:"funcList,omitempty"`
	// contains filtered or unexported fields
}

func AddDialectConfig

func AddDialectConfig(cfg *DialectConfig) *DialectConfig

func GetDialectConfig

func GetDialectConfig(name string) *DialectConfig

func LoadDialectConfigByFile

func LoadDialectConfigByFile(configFile string) (cfg *DialectConfig, err error)

func ToDialectConfigByBytes

func ToDialectConfigByBytes(configFile string, bs []byte) (cfg *DialectConfig, err error)

func (*DialectConfig) CreateUserAutoCreateDatabase

func (this_ *DialectConfig) CreateUserAutoCreateDatabase() bool

func (*DialectConfig) CreateUserAutoCreateSchema

func (this_ *DialectConfig) CreateUserAutoCreateSchema() bool

func (*DialectConfig) FindFunc

func (this_ *DialectConfig) FindFunc(name string) (r map[string]any)

func (*DialectConfig) FindType

func (this_ *DialectConfig) FindType(name string) (r *DialectTypeConfig)

func (*DialectConfig) GetArgChar

func (this_ *DialectConfig) GetArgChar() string

func (*DialectConfig) GetColumnAdd

func (this_ *DialectConfig) GetColumnAdd() (t *SqlTemplate)

func (*DialectConfig) GetColumnComment

func (this_ *DialectConfig) GetColumnComment() (t *SqlTemplate)

func (*DialectConfig) GetColumnDelete

func (this_ *DialectConfig) GetColumnDelete() (t *SqlTemplate)

func (*DialectConfig) GetColumnSelect

func (this_ *DialectConfig) GetColumnSelect() (t *SqlTemplate)

func (*DialectConfig) GetColumnUpdate

func (this_ *DialectConfig) GetColumnUpdate() (t *SqlTemplate)

func (*DialectConfig) GetColumnUpdateDefault

func (this_ *DialectConfig) GetColumnUpdateDefault() (t *SqlTemplate)

func (*DialectConfig) GetColumnUpdateNotNull

func (this_ *DialectConfig) GetColumnUpdateNotNull() (t *SqlTemplate)

func (*DialectConfig) GetColumnUpdateRename

func (this_ *DialectConfig) GetColumnUpdateRename() (t *SqlTemplate)

func (*DialectConfig) GetColumnUpdateType

func (this_ *DialectConfig) GetColumnUpdateType() (t *SqlTemplate)

func (*DialectConfig) GetConstraintAdd

func (this_ *DialectConfig) GetConstraintAdd() (t *SqlTemplate)

func (*DialectConfig) GetConstraintComment

func (this_ *DialectConfig) GetConstraintComment() (t *SqlTemplate)

func (*DialectConfig) GetConstraintDelete

func (this_ *DialectConfig) GetConstraintDelete() (t *SqlTemplate)

func (*DialectConfig) GetConstraintSelect

func (this_ *DialectConfig) GetConstraintSelect() (t *SqlTemplate)

func (*DialectConfig) GetDatabaseChange

func (this_ *DialectConfig) GetDatabaseChange() (t *SqlTemplate)

func (*DialectConfig) GetDatabaseCreate

func (this_ *DialectConfig) GetDatabaseCreate() (t *SqlTemplate)

func (*DialectConfig) GetDatabaseCreateFieldList

func (this_ *DialectConfig) GetDatabaseCreateFieldList() (res []*Field)

func (*DialectConfig) GetDatabaseDelete

func (this_ *DialectConfig) GetDatabaseDelete() (t *SqlTemplate)

func (*DialectConfig) GetDatabaseSelect

func (this_ *DialectConfig) GetDatabaseSelect() (t *SqlTemplate)

func (*DialectConfig) GetDriver

func (this_ *DialectConfig) GetDriver() *DialectDriverConfig

func (*DialectConfig) GetIndexAdd

func (this_ *DialectConfig) GetIndexAdd() (t *SqlTemplate)

func (*DialectConfig) GetIndexComment

func (this_ *DialectConfig) GetIndexComment() (t *SqlTemplate)

func (*DialectConfig) GetIndexDelete

func (this_ *DialectConfig) GetIndexDelete() (t *SqlTemplate)

func (*DialectConfig) GetIndexSelect

func (this_ *DialectConfig) GetIndexSelect() (t *SqlTemplate)

func (*DialectConfig) GetNameNoWrapIsUpper

func (this_ *DialectConfig) GetNameNoWrapIsUpper() bool

func (*DialectConfig) GetNameWrapChar

func (this_ *DialectConfig) GetNameWrapChar() string

func (*DialectConfig) GetSchemaChange

func (this_ *DialectConfig) GetSchemaChange() (t *SqlTemplate)

func (*DialectConfig) GetSchemaCreate

func (this_ *DialectConfig) GetSchemaCreate() (t *SqlTemplate)

func (*DialectConfig) GetSchemaCreateFieldList

func (this_ *DialectConfig) GetSchemaCreateFieldList() (res []*Field)

func (*DialectConfig) GetSchemaDelete

func (this_ *DialectConfig) GetSchemaDelete() (t *SqlTemplate)

func (*DialectConfig) GetSchemaSelect

func (this_ *DialectConfig) GetSchemaSelect() (t *SqlTemplate)

func (*DialectConfig) GetSequenceCreate

func (this_ *DialectConfig) GetSequenceCreate() (t *SqlTemplate)

func (*DialectConfig) GetSequenceCreateFieldList

func (this_ *DialectConfig) GetSequenceCreateFieldList() (res []*Field)

func (*DialectConfig) GetSequenceDelete

func (this_ *DialectConfig) GetSequenceDelete() (t *SqlTemplate)

func (*DialectConfig) GetSequenceSelect

func (this_ *DialectConfig) GetSequenceSelect() (t *SqlTemplate)

func (*DialectConfig) GetStringEscapeChar

func (this_ *DialectConfig) GetStringEscapeChar() string

func (*DialectConfig) GetStringWrapChar

func (this_ *DialectConfig) GetStringWrapChar() string

func (*DialectConfig) GetTableCreate

func (this_ *DialectConfig) GetTableCreate() (t *SqlTemplate)

func (*DialectConfig) GetTableCreateColumn

func (this_ *DialectConfig) GetTableCreateColumn() (t *SqlTemplate)

func (*DialectConfig) GetTableCreateColumnComment

func (this_ *DialectConfig) GetTableCreateColumnComment() (t *SqlTemplate)

func (*DialectConfig) GetTableCreateComment

func (this_ *DialectConfig) GetTableCreateComment() (t *SqlTemplate)

func (*DialectConfig) GetTableCreateConstraint

func (this_ *DialectConfig) GetTableCreateConstraint() (t *SqlTemplate)

func (*DialectConfig) GetTableCreateConstraintComment

func (this_ *DialectConfig) GetTableCreateConstraintComment() (t *SqlTemplate)

func (*DialectConfig) GetTableCreateFieldList

func (this_ *DialectConfig) GetTableCreateFieldList() (res []*Field)

func (*DialectConfig) GetTableCreateIndex

func (this_ *DialectConfig) GetTableCreateIndex() (t *SqlTemplate)

func (*DialectConfig) GetTableCreateIndexComment

func (this_ *DialectConfig) GetTableCreateIndexComment() (t *SqlTemplate)

func (*DialectConfig) GetTableCreateSequenceTrigger

func (this_ *DialectConfig) GetTableCreateSequenceTrigger() (t *SqlTemplate)

func (*DialectConfig) GetTableDelete

func (this_ *DialectConfig) GetTableDelete() (t *SqlTemplate)

func (*DialectConfig) GetTableSelect

func (this_ *DialectConfig) GetTableSelect() (t *SqlTemplate)

func (*DialectConfig) GetUserChange

func (this_ *DialectConfig) GetUserChange() (t *SqlTemplate)

func (*DialectConfig) GetUserCreate

func (this_ *DialectConfig) GetUserCreate() (t *SqlTemplate)

func (*DialectConfig) GetUserCreateFieldList

func (this_ *DialectConfig) GetUserCreateFieldList() (res []*Field)

func (*DialectConfig) GetUserDelete

func (this_ *DialectConfig) GetUserDelete() (t *SqlTemplate)

func (*DialectConfig) GetUserSelect

func (this_ *DialectConfig) GetUserSelect() (t *SqlTemplate)

func (*DialectConfig) Init

func (this_ *DialectConfig) Init() (err error)

func (*DialectConfig) IsSystemDatabase

func (this_ *DialectConfig) IsSystemDatabase(name string) bool

func (*DialectConfig) IsSystemSchema

func (this_ *DialectConfig) IsSystemSchema(name string) bool

func (*DialectConfig) IsSystemUser

func (this_ *DialectConfig) IsSystemUser(name string) bool

func (*DialectConfig) MatchType

func (this_ *DialectConfig) MatchType(dataType string, length, precision, scale int) (r *DialectTypeConfig)

func (*DialectConfig) NewPlaceSqlTemplate

func (this_ *DialectConfig) NewPlaceSqlTemplate(place string, sqlInfo string) (res *SqlTemplate, err error)

type DialectConstraintConfig

type DialectConstraintConfig struct {
	// 查询 SQL 字段:databaseName、schemaName、tableName;参数:databaseName、schemaName、tableName
	Select string `yaml:"select,omitempty"`
	// 创建 SQL 参数:databaseName、schemaName、tableName、加上表单字段
	Add     string `yaml:"add,omitempty"`
	Comment string `yaml:"comment,omitempty"`
	// 删除 SQL 参数:databaseName、schemaName、tableName
	Delete string `yaml:"delete,omitempty"`
}

type DialectDatabaseConfig

type DialectDatabaseConfig struct {
	Change string `yaml:"change,omitempty"`
	// 查询 SQL 字段:databaseName;参数:databaseName
	Select string `yaml:"select,omitempty"`
	// 创建 SQL 参数:databaseName、加上表单字段
	Create string `yaml:"create,omitempty"`
	// 创建 SQL 附件 字段
	CreateFieldList []*Field `yaml:"createFieldList,omitempty"`
	// 删除 SQL 参数:databaseName
	Delete string `yaml:"delete,omitempty"`

	// 需要切换用户
	ShouldChangeUser bool `yaml:"shouldChangeUser,omitempty"`
	// 需要切换数据库
	ShouldChangeDatabase bool `yaml:"shouldChangeDatabase,omitempty"`
	// 需要切换模式
	ShouldChangeSchema bool `yaml:"shouldChangeSchema,omitempty"`

	Systems []string `yaml:"systems,omitempty"`
}

type DialectDriverConfig

type DialectDriverConfig struct {
	Name  string `yaml:"name,omitempty"`
	Dsn   string `yaml:"dsn,omitempty"`
	IsUrl bool   `yaml:"isUrl,omitempty"`

	// 驱动连接中 是否可以包含 数据库
	HasDatabase bool `yaml:"hasDatabase,omitempty"`
	// 驱动连接中 是否可以包含 模式
	HasSchema bool `yaml:"hasSchema,omitempty"`

	// 值是否可以 编码 用于特殊字符
	CanPathEscape bool `yaml:"canPathEscape,omitempty"`

	// 参数间隔 字符 非 url 使用,默认为 " "
	ParamSpaceChar string `yaml:"paramSpaceChar,omitempty"`

	Params map[string]string `yaml:"params,omitempty"`
}

type DialectIndexConfig

type DialectIndexConfig struct {
	// 查询 SQL 字段:databaseName、schemaName、tableName;参数:databaseName、schemaName、tableName
	Select string `yaml:"select,omitempty"`
	// 创建 SQL 参数:databaseName、schemaName、tableName、加上表单字段
	Add     string `yaml:"add,omitempty"`
	Comment string `yaml:"comment,omitempty"`
	// 删除 SQL 参数:databaseName、schemaName、tableName
	Delete string `yaml:"delete,omitempty"`
}

type DialectNodeConfig

type DialectNodeConfig struct {
	Name    string `yaml:"name,omitempty"`
	Comment string `yaml:"comment,omitempty"`
	Rule    string `yaml:"rule,omitempty"`

	// 需要切换用户
	ShouldChangeUser bool `yaml:"shouldChangeUser,omitempty"`
	// 需要切换数据库
	ShouldChangeDatabase bool `yaml:"shouldChangeDatabase,omitempty"`
	// 需要切换模式
	ShouldChangeSchema bool `yaml:"shouldChangeSchema,omitempty"`

	Children []*DialectNodeConfig `yaml:"children,omitempty"`
}

type DialectSchemaConfig

type DialectSchemaConfig struct {
	Change string `yaml:"change,omitempty"`
	// 查询 SQL 字段:databaseName、schemaName;参数:databaseName、schemaName
	Select string `yaml:"select,omitempty"`
	// 创建 SQL 参数:databaseName、schemaName、加上表单字段
	Create string `yaml:"create,omitempty"`
	// 创建 SQL 附件 字段
	CreateFieldList []*Field `yaml:"createFieldList,omitempty"`
	// 删除 SQL 参数:databaseName、schemaName
	Delete string `yaml:"delete,omitempty"`

	// 需要切换用户
	ShouldChangeUser bool `yaml:"shouldChangeUser,omitempty"`
	// 需要切换数据库
	ShouldChangeDatabase bool `yaml:"shouldChangeDatabase,omitempty"`
	// 需要切换模式
	ShouldChangeSchema bool `yaml:"shouldChangeSchema,omitempty"`

	Systems []string `yaml:"systems,omitempty"`
}

type DialectSequenceConfig

type DialectSequenceConfig struct {
	// 查询 SQL 字段:databaseName、schemaName;参数:databaseName、schemaName
	Select string `yaml:"select,omitempty"`
	// 创建 SQL 参数:databaseName、schemaName、加上表单字段
	Create string `yaml:"create,omitempty"`
	// 创建 SQL 附件 字段
	CreateFieldList []*Field `yaml:"createFieldList,omitempty"`
	// 删除 SQL 参数:databaseName、schemaName
	Delete string `yaml:"delete,omitempty"`
}

type DialectService

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

func (*DialectService) AppendParam

func (this_ *DialectService) AppendParam(handler DDLHandler, param map[string]any, obj any, ignoreNames ...string)

func (*DialectService) AppendParamExtend

func (this_ *DialectService) AppendParamExtend(handler DDLHandler, param map[string]any, extend map[string]any)

func (*DialectService) AppendParamTableName

func (this_ *DialectService) AppendParamTableName(handler DDLHandler, param map[string]any, databaseName string, schemaName string, tableName string)

func (*DialectService) ArgChar

func (this_ *DialectService) ArgChar() string

func (*DialectService) Column

func (this_ *DialectService) Column(sqlConn SqlConn, databaseName string, schemaName string, tableName string, columnName string) (column *Column, err error)

func (*DialectService) ColumnAdd

func (this_ *DialectService) ColumnAdd(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, column *Column) (err error)

func (*DialectService) ColumnAddSql

func (this_ *DialectService) ColumnAddSql(handler DDLHandler, databaseName string, schemaName string, tableName string, column *Column) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) ColumnCheckExists

func (this_ *DialectService) ColumnCheckExists(sqlConn SqlConn, databaseName string, schemaName string, tableName string, columnName string) (exists bool)

func (*DialectService) ColumnComment

func (this_ *DialectService) ColumnComment(handler DDLHandler, databaseName string, schemaName string, tableName string, column *Column) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) ColumnCommentSql

func (this_ *DialectService) ColumnCommentSql(handler DDLHandler, databaseName string, schemaName string, tableName string, column *Column) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) ColumnDelete

func (this_ *DialectService) ColumnDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, columnName string) (err error)

func (*DialectService) ColumnDeleteSql

func (this_ *DialectService) ColumnDeleteSql(handler DDLHandler, databaseName string, schemaName string, tableName string, columnName string) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) ColumnFull

func (this_ *DialectService) ColumnFull(sqlConn SqlConn, databaseName string, schemaName string, tableName string, column *Column) (err error)

func (*DialectService) ColumnList

func (this_ *DialectService) ColumnList(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (columnList []*Column, err error)

func (*DialectService) ColumnParam

func (this_ *DialectService) ColumnParam(handler DDLHandler, databaseName string, schemaName string, tableName string, column *Column) (param map[string]any)

func (*DialectService) ColumnSelectSql

func (this_ *DialectService) ColumnSelectSql(databaseName string, schemaName string, tableName string, columnName string) (sqlInfo string, sqlArgs []any)

func (*DialectService) ColumnUpdate

func (this_ *DialectService) ColumnUpdate(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, oldColumn *Column, column *Column) (err error)

func (*DialectService) ColumnUpdateSql

func (this_ *DialectService) ColumnUpdateSql(handler DDLHandler, databaseName string, schemaName string, tableName string, oldColumn *Column, column *Column) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) Constraint

func (this_ *DialectService) Constraint(sqlConn SqlConn, databaseName string, schemaName string, tableName string, constraintName string) (constraint *Constraint, err error)

func (*DialectService) ConstraintAdd

func (this_ *DialectService) ConstraintAdd(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, constraint *Constraint) (err error)

func (*DialectService) ConstraintAddSql

func (this_ *DialectService) ConstraintAddSql(handler DDLHandler, databaseName string, schemaName string, tableName string, constraint *Constraint) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) ConstraintComment

func (this_ *DialectService) ConstraintComment(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, constraint *Constraint) (err error)

func (*DialectService) ConstraintCommentSql

func (this_ *DialectService) ConstraintCommentSql(handler DDLHandler, databaseName string, schemaName string, tableName string, constraint *Constraint) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) ConstraintDelete

func (this_ *DialectService) ConstraintDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, constraintName string) (err error)

func (*DialectService) ConstraintDeleteSql

func (this_ *DialectService) ConstraintDeleteSql(handler DDLHandler, databaseName string, schemaName string, tableName string, constraintName string) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) ConstraintList

func (this_ *DialectService) ConstraintList(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (constraintList []*Constraint, err error)

func (*DialectService) ConstraintParam

func (this_ *DialectService) ConstraintParam(handler DDLHandler, databaseName string, schemaName string, tableName string, constraint *Constraint) (param map[string]any)

func (*DialectService) ConstraintSelectSql

func (this_ *DialectService) ConstraintSelectSql(databaseName string, schemaName string, tableName string, constraintName string) (sqlInfo string, sqlArgs []any)

func (*DialectService) Database

func (this_ *DialectService) Database(sqlConn SqlConn, databaseName string) (database *Database, err error)

func (*DialectService) DatabaseChange

func (this_ *DialectService) DatabaseChange(sqlConn SqlConn, databaseName string) (ok bool, err error)

func (*DialectService) DatabaseCreate

func (this_ *DialectService) DatabaseCreate(sqlConn SqlConn, handler DDLHandler, database *Database) (err error)

func (*DialectService) DatabaseCreateFieldList

func (this_ *DialectService) DatabaseCreateFieldList() (sqlList []*Field)

func (*DialectService) DatabaseCreateSql

func (this_ *DialectService) DatabaseCreateSql(handler DDLHandler, database *Database) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) DatabaseDelete

func (this_ *DialectService) DatabaseDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, cascade bool) (err error)

func (*DialectService) DatabaseDeleteSql

func (this_ *DialectService) DatabaseDeleteSql(handler DDLHandler, databaseName string, cascade bool) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) DatabaseList

func (this_ *DialectService) DatabaseList(sqlConn SqlConn) (databaseList []*Database, err error)

func (*DialectService) DatabaseParam

func (this_ *DialectService) DatabaseParam(handler DDLHandler, database *Database) (param map[string]any)

func (*DialectService) DatabaseSelectSql

func (this_ *DialectService) DatabaseSelectSql(databaseName string) (sqlInfo string, sqlArgs []any)

func (*DialectService) EscapeStringChar

func (this_ *DialectService) EscapeStringChar() string

func (*DialectService) Exec

func (this_ *DialectService) Exec(sqlConn SqlConn, sqlInfo string, sqlArgs []any) (err error)

func (*DialectService) Execs

func (this_ *DialectService) Execs(sqlConn SqlConn, sqlList []string, sqlArgsList [][]any) (err error)

func (*DialectService) FormatPageSql

func (this_ *DialectService) FormatPageSql(sqlInfo string, pageSize int64, pageNo int64) (res string)

func (*DialectService) FormatSqlArgChar

func (this_ *DialectService) FormatSqlArgChar(sqlInfo string) (res string)

func (*DialectService) GetColumnDefault

func (this_ *DialectService) GetColumnDefault(handler DDLHandler, column *Column) (res string)

func (*DialectService) GetColumnType

func (this_ *DialectService) GetColumnType(handler DDLHandler, column *Column) (columnType string)

func (*DialectService) GetDDLHandler

func (this_ *DialectService) GetDDLHandler(handler DDLHandler) DDLHandler

func (*DialectService) GetDriverDSN

func (this_ *DialectService) GetDriverDSN(dbCfg *Config, params map[string]string) string

func (*DialectService) GetDriverName

func (this_ *DialectService) GetDriverName() string

func (*DialectService) GetParam

func (this_ *DialectService) GetParam(handler DDLHandler, obj any) (param map[string]any)

func (*DialectService) Index

func (this_ *DialectService) Index(sqlConn SqlConn, databaseName string, schemaName string, tableName string, indexName string) (index *Index, err error)

func (*DialectService) IndexAdd

func (this_ *DialectService) IndexAdd(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, index *Index) (err error)

func (*DialectService) IndexAddSql

func (this_ *DialectService) IndexAddSql(handler DDLHandler, databaseName string, schemaName string, tableName string, index *Index) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) IndexCheckExists

func (this_ *DialectService) IndexCheckExists(sqlConn SqlConn, databaseName string, schemaName string, tableName string, checkIndex *Index) (exists bool)

func (*DialectService) IndexComment

func (this_ *DialectService) IndexComment(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, index *Index) (err error)

func (*DialectService) IndexCommentSql

func (this_ *DialectService) IndexCommentSql(handler DDLHandler, databaseName string, schemaName string, tableName string, index *Index) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) IndexDelete

func (this_ *DialectService) IndexDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string, indexName string) (err error)

func (*DialectService) IndexDeleteSql

func (this_ *DialectService) IndexDeleteSql(handler DDLHandler, databaseName string, schemaName string, tableName string, indexName string) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) IndexList

func (this_ *DialectService) IndexList(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (indexList []*Index, err error)

func (*DialectService) IndexParam

func (this_ *DialectService) IndexParam(handler DDLHandler, databaseName string, schemaName string, tableName string, index *Index) (param map[string]any)

func (*DialectService) IndexSelectSql

func (this_ *DialectService) IndexSelectSql(databaseName string, schemaName string, tableName string, indexName string) (sqlInfo string, sqlArgs []any)

func (*DialectService) Info

func (this_ *DialectService) Info() (info *Info)

func (*DialectService) IsAppendDatabaseName

func (this_ *DialectService) IsAppendDatabaseName() bool

func (*DialectService) IsAppendSchemaName

func (this_ *DialectService) IsAppendSchemaName() bool

func (*DialectService) Match

func (this_ *DialectService) Match() []string

func (*DialectService) Names

func (this_ *DialectService) Names(names ...string) (res string)

func (*DialectService) Open

func (this_ *DialectService) Open(dbCfg *Config, params map[string]string) (sqlDb *sql.DB, err error)

func (*DialectService) Query

func (this_ *DialectService) Query(sqlConn SqlConn, sqlInfo string, sqlArgs []any) (res []map[string]any, err error)

func (*DialectService) QueryOne

func (this_ *DialectService) QueryOne(sqlConn SqlConn, sqlInfo string, sqlArgs []any) (res map[string]any, err error)

func (*DialectService) Schema

func (this_ *DialectService) Schema(sqlConn SqlConn, databaseName string, schemaName string) (schema *Schema, err error)

func (*DialectService) SchemaChange

func (this_ *DialectService) SchemaChange(sqlConn SqlConn, schemaName string) (ok bool, err error)

func (*DialectService) SchemaCreate

func (this_ *DialectService) SchemaCreate(sqlConn SqlConn, handler DDLHandler, databaseName string, schema *Schema) (err error)

func (*DialectService) SchemaCreateFieldList

func (this_ *DialectService) SchemaCreateFieldList() (sqlList []*Field)

func (*DialectService) SchemaCreateSql

func (this_ *DialectService) SchemaCreateSql(handler DDLHandler, databaseName string, schema *Schema) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) SchemaDelete

func (this_ *DialectService) SchemaDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, cascade bool) (err error)

func (*DialectService) SchemaDeleteSql

func (this_ *DialectService) SchemaDeleteSql(handler DDLHandler, databaseName string, schemaName string, cascade bool) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) SchemaList

func (this_ *DialectService) SchemaList(sqlConn SqlConn, databaseName string) (schemaList []*Schema, err error)

func (*DialectService) SchemaParam

func (this_ *DialectService) SchemaParam(handler DDLHandler, databaseName string, schema *Schema) (param map[string]any)

func (*DialectService) SchemaSelectSql

func (this_ *DialectService) SchemaSelectSql(databaseName string, schemaName string) (sqlInfo string, sqlArgs []any)

func (*DialectService) Sequence

func (this_ *DialectService) Sequence(sqlConn SqlConn, databaseName string, schemaName string, sequenceName string) (sequence *Sequence, err error)

func (*DialectService) SequenceCreate

func (this_ *DialectService) SequenceCreate(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, sequence *Sequence) (err error)

func (*DialectService) SequenceCreateFieldList

func (this_ *DialectService) SequenceCreateFieldList() (sqlList []*Field)

func (*DialectService) SequenceCreateSql

func (this_ *DialectService) SequenceCreateSql(handler DDLHandler, databaseName string, schemaName string, sequence *Sequence) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) SequenceDelete

func (this_ *DialectService) SequenceDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, sequenceName string) (err error)

func (*DialectService) SequenceDeleteSql

func (this_ *DialectService) SequenceDeleteSql(handler DDLHandler, databaseName string, schemaName string, sequenceName string) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) SequenceList

func (this_ *DialectService) SequenceList(sqlConn SqlConn, databaseName string, schemaName string) (sequenceList []*Sequence, err error)

func (*DialectService) SequenceParam

func (this_ *DialectService) SequenceParam(handler DDLHandler, databaseName string, schemaName string, sequence *Sequence) (param map[string]any)

func (*DialectService) SequenceSelectSql

func (this_ *DialectService) SequenceSelectSql(databaseName string, schemaName string, sequenceName string) (sqlInfo string, sqlArgs []any)

func (*DialectService) SqlConcat

func (this_ *DialectService) SqlConcat(args ...string) (res string)

func (*DialectService) Table

func (this_ *DialectService) Table(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (table *Table, err error)

func (*DialectService) TableCheckExists

func (this_ *DialectService) TableCheckExists(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (exists bool)

func (*DialectService) TableCreate

func (this_ *DialectService) TableCreate(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, table *Table) (err error)

func (*DialectService) TableCreateFieldList

func (this_ *DialectService) TableCreateFieldList() (sqlList []*Field)

func (*DialectService) TableCreateSql

func (this_ *DialectService) TableCreateSql(handler DDLHandler, databaseName string, schemaName string, table *Table) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) TableDelete

func (this_ *DialectService) TableDelete(sqlConn SqlConn, handler DDLHandler, databaseName string, schemaName string, tableName string) (err error)

func (*DialectService) TableDeleteSql

func (this_ *DialectService) TableDeleteSql(handler DDLHandler, databaseName string, schemaName string, tableName string) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) TableDetail

func (this_ *DialectService) TableDetail(sqlConn SqlConn, databaseName string, schemaName string, tableName string) (table *Table, err error)

func (*DialectService) TableDetailList

func (this_ *DialectService) TableDetailList(sqlConn SqlConn, databaseName string, schemaName string) (tableList []*Table, err error)

func (*DialectService) TableList

func (this_ *DialectService) TableList(sqlConn SqlConn, databaseName string, schemaName string) (tableList []*Table, err error)

func (*DialectService) TableParam

func (this_ *DialectService) TableParam(handler DDLHandler, databaseName string, schemaName string, table *Table) (param map[string]any)

func (*DialectService) TableSelectSql

func (this_ *DialectService) TableSelectSql(databaseName string, schemaName string, tableName string) (sqlInfo string, sqlArgs []any)

func (*DialectService) TemplateSql

func (this_ *DialectService) TemplateSql(t *SqlTemplate, param map[string]any) (sqlInfo string, sqlArgs []any)

func (*DialectService) TemplateSqlList

func (this_ *DialectService) TemplateSqlList(t *SqlTemplate, param map[string]any) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) Type

func (this_ *DialectService) Type() string

func (*DialectService) User

func (this_ *DialectService) User(sqlConn SqlConn, userName string) (user *User, err error)

func (*DialectService) UserChange

func (this_ *DialectService) UserChange(sqlConn SqlConn, userName string, password string) (ok bool, err error)

func (*DialectService) UserCreate

func (this_ *DialectService) UserCreate(sqlConn SqlConn, handler DDLHandler, user *User) (err error)

func (*DialectService) UserCreateFieldList

func (this_ *DialectService) UserCreateFieldList() (sqlList []*Field)

func (*DialectService) UserCreateSql

func (this_ *DialectService) UserCreateSql(handler DDLHandler, user *User) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) UserDelete

func (this_ *DialectService) UserDelete(sqlConn SqlConn, handler DDLHandler, userName string) (err error)

func (*DialectService) UserDeleteSql

func (this_ *DialectService) UserDeleteSql(handler DDLHandler, userName string) (sqlList []string, sqlArgsList [][]any)

func (*DialectService) UserList

func (this_ *DialectService) UserList(sqlConn SqlConn) (userList []*User, err error)

func (*DialectService) UserParam

func (this_ *DialectService) UserParam(handler DDLHandler, user *User) (param map[string]any)

func (*DialectService) UserSelectSql

func (this_ *DialectService) UserSelectSql(userName string) (sqlInfo string, sqlArgs []any)

func (*DialectService) WrapColumnName

func (this_ *DialectService) WrapColumnName(name string) string

func (*DialectService) WrapConstraintName

func (this_ *DialectService) WrapConstraintName(name string) string

func (*DialectService) WrapDatabaseName

func (this_ *DialectService) WrapDatabaseName(name string) string

func (*DialectService) WrapIndexName

func (this_ *DialectService) WrapIndexName(name string) string

func (*DialectService) WrapName

func (this_ *DialectService) WrapName(name string) (res string)

func (*DialectService) WrapNameChar

func (this_ *DialectService) WrapNameChar() string

func (*DialectService) WrapNames

func (this_ *DialectService) WrapNames(wrapName func(name string) (res string), names ...string) (res string)

func (*DialectService) WrapSchemaName

func (this_ *DialectService) WrapSchemaName(name string) string

func (*DialectService) WrapSequenceName

func (this_ *DialectService) WrapSequenceName(name string) string

func (*DialectService) WrapString

func (this_ *DialectService) WrapString(str string) (res string)

func (*DialectService) WrapStringChar

func (this_ *DialectService) WrapStringChar() string

func (*DialectService) WrapTableName

func (this_ *DialectService) WrapTableName(name string) string

func (*DialectService) WrapUserName

func (this_ *DialectService) WrapUserName(name string) string

type DialectTableConfig

type DialectTableConfig struct {
	// 查询 SQL 字段:databaseName、schemaName、tableName;参数:databaseName、schemaName、tableName
	Select string `yaml:"select,omitempty"`
	// 创建 SQL 参数:databaseName、schemaName、tableName、加上表单字段
	Create        string `yaml:"create,omitempty"`
	CreateComment string `yaml:"createComment,omitempty"`
	// 创建 SQL 附件 字段
	CreateFieldList []*Field `yaml:"createFieldList,omitempty"`
	// 建表 字段 SQL 参数:columnName、columnType、notNull、
	CreateColumn        string `yaml:"createColumn,omitempty"`
	CreateColumnComment string `yaml:"createColumnComment,omitempty"`
	// 建表 约束 SQL 参数:columnName、columnType、notNull、
	CreateConstraint        string `yaml:"createConstraint,omitempty"`
	CreateConstraintComment string `yaml:"createConstraintComment,omitempty"`

	CreateSequenceTrigger string `yaml:"createSequenceTrigger,omitempty"`

	// 建表 索引 SQL 参数:columnName、columnType、notNull、
	CreateIndex        string `yaml:"createIndex,omitempty"`
	CreateIndexComment string `yaml:"createIndexComment,omitempty"`
	Comment            string `yaml:"comment,omitempty"`
	// 删除 SQL 参数:databaseName、schemaName、tableName
	Delete string `yaml:"delete,omitempty"`

	// 需要切换用户
	ShouldChangeUser bool `yaml:"shouldChangeUser,omitempty"`
	// 需要切换数据库
	ShouldChangeDatabase bool `yaml:"shouldChangeDatabase,omitempty"`
	// 需要切换模式
	ShouldChangeSchema bool `yaml:"shouldChangeSchema,omitempty"`
}

type DialectTypeConfig

type DialectTypeConfig struct {
	Name   string   `yaml:"name,omitempty"`
	Format string   `yaml:"format,omitempty"`
	Args   []string `yaml:"args,omitempty"`
	Match  []string `yaml:"match,omitempty"`
}

func (*DialectTypeConfig) FormatColumnType

func (this_ *DialectTypeConfig) FormatColumnType(length, precision, scale int) (columnType string)

type DialectUserConfig

type DialectUserConfig struct {
	// 创建用户 会自动创建 数据库
	AutoCreateDatabase bool `yaml:"autoCreateDatabase,omitempty"`
	// 创建用户 会自动创建 模式
	AutoCreateSchema bool `yaml:"autoCreateSchema,omitempty"`

	Change string `yaml:"change,omitempty"`
	// 查询 SQL 字段:userName;参数:userName
	Select string `yaml:"select,omitempty"`
	// 创建 SQL 参数:userName、password、加上表单指定
	Create string `yaml:"create,omitempty"`
	// 字段
	CreateFieldList []*Field `yaml:"createFieldList,omitempty"`
	// 删除 SQL 参数:userName
	Delete string `yaml:"delete,omitempty"`

	Systems []string `yaml:"systems,omitempty"`
}

type DmBlobType

type DmBlobType interface {
	Read(dest []byte) (n int, err error)
	ReadAt(pos int, dest []byte) (n int, err error)
	Write(pos int, src []byte) (n int, err error)
	Truncate(length int64) error
	Scan(src interface{}) error
}

type DmClobType

type DmClobType interface {
	GetLength() (int64, error)
	ReadString(pos int, length int) (result string, err error)
	WriteString(pos int, s string) (n int, err error)
	Truncate(length int64) error
	Scan(src interface{}) error
}

type Field

type Field struct {
	// 字段名称
	Name string `yaml:"name,omitempty"`
	// 标签
	Label string `yaml:"label,omitempty"`
	// 类型 text、password、select、redis、checkbox、json字符串,form
	Type string `yaml:"type,omitempty"`
	// 多个值
	List bool `yaml:"list,omitempty"`
	// 必填
	Required bool `yaml:"required,omitempty"`
	// 子表单
	FormName string `yaml:"formName,omitempty"`
	// 默认值
	Default   string `json:"default,omitempty"`
	IsInteger bool   `json:"isInteger,omitempty"`
}

type FieldSetterType

type FieldSetterType func(model reflect.Value, modelField *ModelField, fieldValue reflect.Value, receiver any) (err error)

type FiledGetColumn

type FiledGetColumn func() string

type FiledGetValue

type FiledGetValue func(columnName string, columnValue *util.FieldValue) any

type Form

type Form struct {
	// 表单名称
	Name string `yaml:"name,omitempty"`
	// 字段
	FieldList []*Field `yaml:"fieldList,omitempty"`
}

type GetSqlValueType

type GetSqlValueType func(columnType *sql.ColumnType, data any) (res any)

type HasStringFuncType

type HasStringFuncType interface {
	String() string
}

type IDynamicService

type IDynamicService interface {
	// RealService 真实服务 根据 表名 和 参数 获取正则
	RealService(param *SqlParam, tableName string) IService
}

type IGetObjectField

type IGetObjectField interface {
	GetObjectField(b *SqlBuilder, object any) (res any)
}

type IGetPrimaryKey

type IGetPrimaryKey interface {
	GetPrimaryKey() []string
}

type IGetSql added in v1.0.3

type IGetSql interface {
	GetSql() (sqlInfo string, args []any, err error)
}

type IGetTableName

type IGetTableName interface {
	GetTableName() string
}

type IModel

type IModel interface {
	IGetTableName
	IGetPrimaryKey
}

type IModelSql

type IModelSql interface {
	IGetSql
	GetService() (service IService)
}

type IService

type IService interface {
	Dialect
	// Close 关闭 db 客户端
	Close()
	// GetConfig 获取 数据库 配置
	GetConfig() Config
	// GetDialect 获取 方言
	GetDialect() Dialect
	// GetSqlConn 获取 sql.DB
	GetSqlConn() SqlConn

	SetDynamicService(dynamicService IDynamicService)

	GetDDLHandler() (handler DDLHandler)
	GetModelOption() (modelOption *ModelOption)

	ShowQuerySql() bool

	ShowExecSql() bool

	SqlHandler
	// IDynamicService 动态数据源服务相关
	IDynamicService

	// Exec 执行 SQL
	Exec(ctx context.Context, sql string, args []any) (result sql.Result, err error)
	// Execs 批量执行 SQL
	Execs(ctx context.Context, sqlList []string, argsList [][]any) (results []sql.Result, err error)
	// QueryCount 统计查询 SQL
	QueryCount(ctx context.Context, sql string, args []any) (count int64, err error)
	// QueryMapOne 查询 单个 map SQL  返回 < map >
	QueryMapOne(ctx context.Context, sql string, args []any) (one map[string]any, err error)
	// QueryMapList 查询 列表 map SQL  返回 list < map >
	QueryMapList(ctx context.Context, sql string, args []any) (list []map[string]any, err error)
	// QueryMapPage 分页查询 列表 map 列表 SQL  返回 list < map >
	QueryMapPage(ctx context.Context, sql string, args []any, pageSize int64, pageNo int64) (list []map[string]any, err error)

	ModelSelect(model any) (res *ModelSelect)
	SqlSelect(table string, columns ...string) (res *SqlSelect)

	Count(ctx context.Context, model IModel) (res int64, err error)
	ModelCount(model any) (res *ModelCount)
	SqlCount(table string) (res *SqlCount)

	Insert(ctx context.Context, model IModel) (res sql.Result, err error)
	ModelInsert(model any) (res *ModelInsert)
	SqlInsert(table string) (res *SqlInsert)

	Update(ctx context.Context, model IModel) (res sql.Result, err error)
	ModelUpdate(model any) (res *ModelUpdate)
	SqlUpdate(table string) (res *SqlUpdate)

	Delete(ctx context.Context, model IModel) (res sql.Result, err error)
	ModelDelete(model any) (res *ModelDelete)
	SqlDelete(table string) (res *SqlDelete)
}

type Index

type Index struct {
	DatabaseName string `json:"databaseName,omitempty"`
	SchemaName   string `json:"schemaName,omitempty"`
	TableName    string `json:"tableName,omitempty"`

	Name        string   `json:"name,omitempty"`
	Comment     string   `json:"comment,omitempty"`
	Type        string   `json:"type,omitempty"`
	ColumnNames []string `json:"columnNames,omitempty"`

	// 扩展属性
	Extend map[string]any `json:"extend,omitempty"`
	// contains filtered or unexported fields
}

func IndexListByColumns

func IndexListByColumns(columns []*IndexColumn) (res []*Index)

func (*Index) GenName

func (this_ *Index) GenName(databaseName string, schemaName string, tableName string) string

func (*Index) Init

func (this_ *Index) Init(handler DDLHandler, databaseName string, schemaName string, tableName string)

type IndexColumn

type IndexColumn struct {
	DatabaseName string `json:"databaseName,omitempty"`
	SchemaName   string `json:"schemaName,omitempty"`
	TableName    string `json:"tableName,omitempty"`

	Name        string `json:"name,omitempty"`
	Comment     string `json:"comment,omitempty"`
	Type        string `json:"type,omitempty"`
	ColumnName  string `json:"columnName,omitempty"`
	ColumnOrder int    `json:"columnOrder,omitempty"`

	// 扩展属性
	Extend map[string]any `json:"extend,omitempty"`
}

func IndexColumnByMap

func IndexColumnByMap(data map[string]any) (res *IndexColumn)

type Info

type Info struct {
	DriverName     string
	Dsn            string
	DsnHasDatabase bool
	DsnHasSchema   bool

	// 名称 没有包装 则自动转大写
	NameNoWrapIsUpper bool `json:"nameNoWrapIsUpper"`

	// SQL 切换用户
	SqlChangeUser bool `json:"canChangeUser"`
	// SQL 切换数据库
	SqlChangeDatabase bool `json:"canChangeDatabase"`
	// SQL 切换模式
	SqlChangeSchema bool `json:"canChangeSchema"`

	// 是否有 用户
	HasUser bool `json:"hasUser"`
	// 是否有 库
	HasDatabase bool `json:"hasDatabase"`
	// 是否有 模式
	HasSchema bool `json:"hasSchema"`
	// 是否有 序列
	HasSequence bool `json:"hasSequence"`

	// 创建用户会自动创建 同名 数据库 则 用户登录 将自动登录到 同名 数据库 中
	CreateUserAutoCreateDatabase bool `json:"createUserAutoCreateDatabase"`
	// 创建用户会自动创建 同名 模式 则 用户登录 将自动登录到 同名 模式 中
	CreateUserAutoCreateSchema bool `json:"createUserAutoCreateSchema"`
}

type InsertOrUpdateValue

type InsertOrUpdateValue struct {
	Column string `json:"column,omitempty"`
	Value  any    `json:"value,omitempty"`
}

type ModelCount

type ModelCount struct {

	// 模型 设置 如:表名、主键、包含字段、忽略字段、空值设置 等
	*ModelSetting
	// contains filtered or unexported fields
}

func NewModelCount added in v1.0.3

func NewModelCount(model any) (res *ModelCount)

func (*ModelCount) Count

func (this_ *ModelCount) Count(ctx context.Context) (res int64, err error)

func (*ModelCount) GetSql

func (this_ *ModelCount) GetSql() (sqlInfo string, args []any, err error)

func (*ModelCount) SetWhere

func (this_ *ModelCount) SetWhere(where *Conditions) *ModelCount

func (*ModelCount) Where

func (this_ *ModelCount) Where() *Conditions

type ModelDelete

type ModelDelete struct {

	// 模型 设置 如:表名、主键、包含字段、忽略字段、空值设置 等
	*ModelSetting
	// contains filtered or unexported fields
}

func NewModelDelete added in v1.0.3

func NewModelDelete(model any) (res *ModelDelete)

func (*ModelDelete) DeleteAll

func (this_ *ModelDelete) DeleteAll() *ModelDelete

DeleteAll 删除时候 必须 设置条件 除非 设置 DeleteAll

func (*ModelDelete) Exec

func (this_ *ModelDelete) Exec(ctx context.Context) (res sql.Result, err error)

func (*ModelDelete) GetSql

func (this_ *ModelDelete) GetSql() (sqlInfo string, args []any, err error)

func (*ModelDelete) SetWhere

func (this_ *ModelDelete) SetWhere(where *Conditions) *ModelDelete

func (*ModelDelete) Where

func (this_ *ModelDelete) Where() *Conditions

type ModelField

type ModelField struct {
	*util.StructField

	// 是否 实现了 sql.Scanner 接口
	ImplementsSqlScanner bool

	ColumnName string
	// contains filtered or unexported fields
}

type ModelInfo

type ModelInfo struct {
	*util.StructInfo
	// contains filtered or unexported fields
}

type ModelInsert

type ModelInsert struct {

	// 模型 设置 如:表名、主键、包含字段、忽略字段、空值设置 等
	*ModelSetting
	// contains filtered or unexported fields
}

func NewModelInsert added in v1.0.3

func NewModelInsert(model any) (res *ModelInsert)

func (*ModelInsert) Exec

func (this_ *ModelInsert) Exec(ctx context.Context) (res sql.Result, err error)

func (*ModelInsert) GetSql

func (this_ *ModelInsert) GetSql() (sqlInfo string, args []any, err error)

type ModelOption

type ModelOption struct {

	// 字段 tag 注解,默认 column 如:`column:"xx"`
	ColumnTag string `json:"columnTag,omitempty"`
	// 是否 使用json主键,如果 字段 tag 注解 未找到 使用 json 注解
	ColumnUseJsonTag bool `json:"columnUseJsonTag,omitempty"`
	// 如果 以上都未配置 使用 字段名称
	ColumnUseFieldName bool `json:"columnUseFieldName,omitempty"`

	// 字段名称 严格判断 默认 false `userId 将 匹配 Userid UserId USERID`,
	ColumnStrictCase bool `json:"columnStrictCase,omitempty"`
	// contains filtered or unexported fields
}

func NewModelOption

func NewModelOption() (res *ModelOption)

func (*ModelOption) GetColumnValue

func (this_ *ModelOption) GetColumnValue(modelV reflect.Value, columnName string) (fieldValue *util.FieldValue)

func (*ModelOption) GetColumnValues

func (this_ *ModelOption) GetColumnValues(modelV reflect.Value) (columns []string, values []*util.FieldValue)

func (*ModelOption) GetColumns

func (this_ *ModelOption) GetColumns(modelV reflect.Value) (columns []string)

func (*ModelOption) GetModelInfo

func (this_ *ModelOption) GetModelInfo(inType reflect.Type) (info *ModelInfo)

func (*ModelOption) SetGetColumn

func (this_ *ModelOption) SetGetColumn(getColumn FiledGetColumn) *ModelOption

func (*ModelOption) SetGetValue

func (this_ *ModelOption) SetGetValue(getValue FiledGetValue) *ModelOption

type ModelSelect

type ModelSelect struct {

	// 模型 设置 如:表名、主键、包含字段、忽略字段、空值设置 等
	*ModelSetting
	// contains filtered or unexported fields
}

func NewModelSelect added in v1.0.3

func NewModelSelect(model any) (res *ModelSelect)

func (*ModelSelect) GetSql

func (this_ *ModelSelect) GetSql() (sqlInfo string, args []any, err error)

func (*ModelSelect) SelectAll

func (this_ *ModelSelect) SelectAll() *ModelSelect

SelectAll 查询时候 必须 设置条件 除非 设置 SelectAll

func (*ModelSelect) SetWhere

func (this_ *ModelSelect) SetWhere(where *Conditions) *ModelSelect

func (*ModelSelect) Where

func (this_ *ModelSelect) Where() *Conditions

type ModelSetting

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

func (*ModelSetting) EmptyExcludeColumn

func (this_ *ModelSetting) EmptyExcludeColumn() *ModelSetting

func (*ModelSetting) EmptyIncludeColumn

func (this_ *ModelSetting) EmptyIncludeColumn() *ModelSetting

func (*ModelSetting) EmptyUseNull

func (this_ *ModelSetting) EmptyUseNull() *ModelSetting

EmptyUseNull 将 空字符串 值 设置为 null,需要 先设置 IncludeEmpty

func (*ModelSetting) ExcludeColumn

func (this_ *ModelSetting) ExcludeColumn(columns ...string) *ModelSetting

func (*ModelSetting) GetModelAndWhereSql

func (this_ *ModelSetting) GetModelAndWhereSql(b *OrmSqlBuilder, model any, where *Conditions) (whereSql string, whereArgs []any)

func (*ModelSetting) GetPrimaryKey

func (this_ *ModelSetting) GetPrimaryKey(model any) []string

func (*ModelSetting) GetService

func (this_ *ModelSetting) GetService() IService

func (*ModelSetting) GetTableName

func (this_ *ModelSetting) GetTableName(model any) string

func (*ModelSetting) GetValue

func (this_ *ModelSetting) GetValue(columnValue *util.FieldValue) (isNull bool, res any)

func (*ModelSetting) IncludeColumn

func (this_ *ModelSetting) IncludeColumn(columns ...string) *ModelSetting

func (*ModelSetting) IncludeEmpty

func (this_ *ModelSetting) IncludeEmpty() *ModelSetting

IncludeEmpty 设置 包含 空字符串,默认 忽略 空字符串 值

func (*ModelSetting) IncludeNull

func (this_ *ModelSetting) IncludeNull() *ModelSetting

IncludeNull 设置 包含 null,默认 忽略 null 值

func (*ModelSetting) IncludeZero

func (this_ *ModelSetting) IncludeZero() *ModelSetting

IncludeZero 设置 包含 0,默认 忽略 0 值

func (*ModelSetting) Included

func (this_ *ModelSetting) Included(columnName string, columnValue *util.FieldValue) bool

func (*ModelSetting) IsExcludeColumn

func (this_ *ModelSetting) IsExcludeColumn(column string) bool

func (*ModelSetting) IsIncludeColumn

func (this_ *ModelSetting) IsIncludeColumn(column string) bool

func (*ModelSetting) NewBuilder

func (this_ *ModelSetting) NewBuilder(model any) (res *OrmSqlBuilder)

func (*ModelSetting) SetModelOption

func (this_ *ModelSetting) SetModelOption(modelOption *ModelOption) *ModelSetting

func (*ModelSetting) SetPrimaryKey

func (this_ *ModelSetting) SetPrimaryKey(columns ...string) *ModelSetting

func (*ModelSetting) SetService

func (this_ *ModelSetting) SetService(service *Service) *ModelSetting

func (*ModelSetting) SetSqlHandler

func (this_ *ModelSetting) SetSqlHandler(sqlHandler SqlHandler) *ModelSetting

func (*ModelSetting) SetTableName

func (this_ *ModelSetting) SetTableName(tableName string) *ModelSetting

func (*ModelSetting) WhereOperator

func (this_ *ModelSetting) WhereOperator(column string, op string) *ModelSetting

func (*ModelSetting) ZeroUseNull

func (this_ *ModelSetting) ZeroUseNull() *ModelSetting

ZeroUseNull 将 0 值 设置为 null,需要 先设置 IncludeZero

type ModelUpdate

type ModelUpdate struct {

	// 模型 设置 如:表名、主键、包含字段、忽略字段、空值设置 等
	*ModelSetting
	// contains filtered or unexported fields
}

func NewModelUpdate added in v1.0.3

func NewModelUpdate(model any) (res *ModelUpdate)

func (*ModelUpdate) Exec

func (this_ *ModelUpdate) Exec(ctx context.Context) (res sql.Result, err error)

func (*ModelUpdate) GetSql

func (this_ *ModelUpdate) GetSql() (sqlInfo string, args []any, err error)

func (*ModelUpdate) SetWhere

func (this_ *ModelUpdate) SetWhere(where *Conditions) *ModelUpdate

func (*ModelUpdate) UpdateAll

func (this_ *ModelUpdate) UpdateAll() *ModelUpdate

UpdateAll 更新时候 必须 设置条件 除非 设置 UpdateAll

func (*ModelUpdate) Where

func (this_ *ModelUpdate) Where() *Conditions

type Op

type Op string

Op 操作符类型

const (
	Eq        Op = "="
	Ne        Op = "!="
	Gt        Op = ">"
	Gte       Op = ">="
	Lt        Op = "<"
	Lte       Op = "<="
	In        Op = "IN"
	NotIn     Op = "NOT IN"
	Like      Op = "LIKE"
	NotLike   Op = "NOT LIKE"
	IsNull    Op = "IS NULL"
	IsNotNull Op = "IS NOT NULL"
	Custom    Op = "CUSTOM"
)

type OrmSqlBuilder

type OrmSqlBuilder struct {
	*ModelOption
	SqlHandler
	// contains filtered or unexported fields
}

func (*OrmSqlBuilder) IsPrimaryKey

func (this_ *OrmSqlBuilder) IsPrimaryKey(column string) bool

type ReadExpression

type ReadExpression struct {
	StartExpression SqlExpression   `json:"startExpression,omitempty"`
	LastExpression  SqlExpression   `json:"lastExpression,omitempty"`
	Expressions     []SqlExpression `json:"expressions,omitempty"`
}

func (*ReadExpression) Add

func (this_ *ReadExpression) Add(e SqlExpression)

func (*ReadExpression) ReplaceLast

func (this_ *ReadExpression) ReplaceLast(replaceIndex int, e SqlExpression)

type ReadScope

type ReadScope struct {
	InSelect       bool `json:"inSelect,omitempty"`
	InSelectColumn bool `json:"inSelectColumn,omitempty"`
	InSelectFrom   bool `json:"inSelectFrom,omitempty"`
	InInsert       bool `json:"inInsert,omitempty"`
	InInsertColumn bool `json:"inInsertColumn,omitempty"`
	InInsertValue  bool `json:"inInsertValue,omitempty"`
	InUpdate       bool `json:"inUpdate,omitempty"`
	InUpdateColumn bool `json:"inUpdateColumn,omitempty"`
	InDelete       bool `json:"inDelete,omitempty"`
	InFrom         bool `json:"inFrom,omitempty"`
	InJoin         bool `json:"inJoin,omitempty"`
	InJoinOn       bool `json:"inJoinOn,omitempty"`
	InWhere        bool `json:"inWhere,omitempty"`
	InGroupBy      bool `json:"inGroupBy,omitempty"`
	InOrderBy      bool `json:"inOrderBy,omitempty"`
	InValue        bool `json:"inValue,omitempty"`
	InDDL          bool `json:"inDDL,omitempty"`

	InExpression bool `json:"inExpression,omitempty"`

	// 解析 算术运算符: + - * / %
	ArithmeticOperator bool `json:"arithmeticOperator,omitempty"`
	// 解析 比较(关系)运算符: == != > < >= <=
	RelationalOperator bool `json:"relationalOperator,omitempty"`
	// 解析 逻辑运算符: && ||
	LogicalOperator bool `json:"logicalOperator,omitempty"`
	// contains filtered or unexported fields
}

type ReadState

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

type ReadText

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

type Schema

type Schema struct {
	DatabaseName string `json:"databaseName,omitempty"`

	Name string `json:"name,omitempty"`

	IsSystem bool `json:"isSystem,omitempty"`

	IfNotExists bool `json:"ifNotExists,omitempty"`
	// 多数用于删除时候 串联删除相关内容
	Cascade bool `json:"cascade,omitempty"`
	// 扩展属性
	Extend map[string]any `json:"extend,omitempty"`
}

func SchemaByMap

func SchemaByMap(data map[string]any) (res *Schema)

type Sequence

type Sequence struct {
	DatabaseName string `json:"databaseName,omitempty"`
	SchemaName   string `json:"schemaName,omitempty"`

	Name string `json:"name,omitempty"`

	// 序列 开始值
	Start int64 `json:"start,omitempty"`
	// 序列 每次增长
	Increment int64 `json:"increment,omitempty"`
	Min       int64 `json:"min,omitempty"`
	Max       int64 `json:"max,omitempty"`

	IfNotExists bool `json:"ifNotExists,omitempty"`
	// 扩展属性
	Extend map[string]any `json:"extend,omitempty"`
}

func SequenceByMap

func SequenceByMap(data map[string]any) (res *Sequence)

func (*Sequence) GenName

func (this_ *Sequence) GenName(handler DDLHandler, databaseName string, schemaName string, tableName string, columnName string) string

func (*Sequence) Init

func (this_ *Sequence) Init(handler DDLHandler, databaseName string, schemaName string, tableName string, columnName string)

type Service

type Service struct {
	Dialect
	// contains filtered or unexported fields
}

func New

func New(cfg *Config, sqlConn SqlConn) (res *Service, err error)

func (*Service) AddColumn

func (this_ *Service) AddColumn(tableName string, column *Column) (err error)

func (*Service) CheckColumnExist

func (this_ *Service) CheckColumnExist(tableName string, columnName string) (res bool)

func (*Service) CheckIndexExist

func (this_ *Service) CheckIndexExist(tableName string, checkIndex *Index) (res bool)

func (*Service) CheckTableExist

func (this_ *Service) CheckTableExist(tableName string) (res bool)

func (*Service) Close

func (this_ *Service) Close()

func (*Service) CloseShowExecSql

func (this_ *Service) CloseShowExecSql() *Service

func (*Service) CloseShowQuerySql

func (this_ *Service) CloseShowQuerySql() *Service

func (*Service) Count

func (this_ *Service) Count(ctx context.Context, model IModel) (res int64, err error)

func (*Service) CreateIndex

func (this_ *Service) CreateIndex(tableName string, index *Index) (err error)

func (*Service) CreateTable

func (this_ *Service) CreateTable(table *Table) (err error)

func (*Service) Delete

func (this_ *Service) Delete(ctx context.Context, model IModel) (res sql.Result, err error)

func (*Service) Exec

func (this_ *Service) Exec(ctx context.Context, sqlInfo string, args []any) (res sql.Result, err error)

func (*Service) Execs

func (this_ *Service) Execs(ctx context.Context, sqlList []string, argsList [][]any) (results []sql.Result, err error)

func (*Service) GetConfig

func (this_ *Service) GetConfig() Config

func (*Service) GetDDLHandler

func (this_ *Service) GetDDLHandler() (handler DDLHandler)

func (*Service) GetDatabaseName

func (this_ *Service) GetDatabaseName() string

func (*Service) GetDialect

func (this_ *Service) GetDialect() Dialect

func (*Service) GetModelOption

func (this_ *Service) GetModelOption() (modelOption *ModelOption)

func (*Service) GetSchemaName

func (this_ *Service) GetSchemaName() string

func (*Service) GetSqlConn

func (this_ *Service) GetSqlConn() SqlConn

func (*Service) GetSqlHandler

func (this_ *Service) GetSqlHandler() (handler SqlHandler)

func (*Service) GetSqlValue

func (this_ *Service) GetSqlValue() GetSqlValueType

func (*Service) Insert

func (this_ *Service) Insert(ctx context.Context, model IModel) (res sql.Result, err error)

func (*Service) ModelCount

func (this_ *Service) ModelCount(model any) (res *ModelCount)

func (*Service) ModelDelete

func (this_ *Service) ModelDelete(model any) (res *ModelDelete)

func (*Service) ModelInsert

func (this_ *Service) ModelInsert(model any) (res *ModelInsert)

func (*Service) ModelSelect

func (this_ *Service) ModelSelect(model any) (res *ModelSelect)

func (*Service) ModelUpdate

func (this_ *Service) ModelUpdate(model any) (res *ModelUpdate)

func (*Service) OpenShowExecSql

func (this_ *Service) OpenShowExecSql() *Service

func (*Service) OpenShowQuerySql

func (this_ *Service) OpenShowQuerySql() *Service

func (*Service) QueryCount

func (this_ *Service) QueryCount(ctx context.Context, sqlInfo string, args []any) (count int64, err error)

func (*Service) QueryMapList

func (this_ *Service) QueryMapList(ctx context.Context, sqlInfo string, args []any) (list []map[string]any, err error)

func (*Service) QueryMapOne

func (this_ *Service) QueryMapOne(ctx context.Context, sqlInfo string, args []any) (one map[string]any, err error)

func (*Service) QueryMapPage

func (this_ *Service) QueryMapPage(ctx context.Context, sqlInfo string, args []any, pageSize int64, pageNo int64) (list []map[string]any, err error)

func (*Service) RealService

func (this_ *Service) RealService(param *SqlParam, tableName string) IService

func (*Service) RealTableName

func (this_ *Service) RealTableName(param *SqlParam, tableName string) (realTableName string)

func (*Service) SetDDLHandler

func (this_ *Service) SetDDLHandler(handler DDLHandler)

func (*Service) SetDynamicService

func (this_ *Service) SetDynamicService(dynamicService IDynamicService)

func (*Service) SetFieldValue

func (this_ *Service) SetFieldValue() SetFieldValueType

func (*Service) SetGetSqlValue

func (this_ *Service) SetGetSqlValue(getSqlValue GetSqlValueType)

func (*Service) SetModelOption

func (this_ *Service) SetModelOption(modelOption *ModelOption)

func (*Service) SetSetFieldValue

func (this_ *Service) SetSetFieldValue(setFieldValue SetFieldValueType)

func (*Service) SetSqlHandler

func (this_ *Service) SetSqlHandler(handler SqlHandler)

func (*Service) ShowExecSql

func (this_ *Service) ShowExecSql() bool

func (*Service) ShowQuerySql

func (this_ *Service) ShowQuerySql() bool

func (*Service) SqlCount

func (this_ *Service) SqlCount(table string) (res *SqlCount)

func (*Service) SqlDelete

func (this_ *Service) SqlDelete(table string) (res *SqlDelete)

func (*Service) SqlInsert

func (this_ *Service) SqlInsert(table string) (res *SqlInsert)

func (*Service) SqlSelect

func (this_ *Service) SqlSelect(table string, columns ...string) (res *SqlSelect)

func (*Service) SqlUpdate

func (this_ *Service) SqlUpdate(table string) (res *SqlUpdate)

func (*Service) Update

func (this_ *Service) Update(ctx context.Context, model IModel) (res sql.Result, err error)

func (*Service) WrapColumnName

func (this_ *Service) WrapColumnName(param *SqlParam, columnName string) (wrapColumnName string)

func (*Service) WrapTableName

func (this_ *Service) WrapTableName(param *SqlParam, tableName string) (wrapTableName string)

type SetFieldValueType

type SetFieldValueType func(columnType *sql.ColumnType, field reflect.StructField, fieldValue reflect.Value, value any) (err error)

type SqlBuilder

type SqlBuilder struct {
	*SqlParam
	// contains filtered or unexported fields
}

func (*SqlBuilder) Append

func (this_ *SqlBuilder) Append(s string, args ...any)

func (*SqlBuilder) GetValue

func (this_ *SqlBuilder) GetValue(e SqlExpression) (res any)

func (*SqlBuilder) Test

func (this_ *SqlBuilder) Test(test SqlExpression) (res bool)

type SqlConcatValue

type SqlConcatValue struct {
	Values []string
	Value  any
}

type SqlConfiguration

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

func NewSqlConfiguration

func NewSqlConfiguration(sets ...SqlConfigurationSet) (c *SqlConfiguration)

func (*SqlConfiguration) GetSqlHandler

func (this_ *SqlConfiguration) GetSqlHandler() SqlHandler

func (*SqlConfiguration) SetSqlHandler

func (this_ *SqlConfiguration) SetSqlHandler(sqlHandler SqlHandler) *SqlConfiguration

type SqlConfigurationSet

type SqlConfigurationSet func(c *SqlConfiguration)

type SqlConn

type SqlConn interface {
	PingContext(ctx context.Context) error
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

type SqlCount

type SqlCount struct {

	// 模型 设置 如:表名、主键、包含字段、忽略字段、空值设置 等
	*ModelSetting
	// contains filtered or unexported fields
}

func (*SqlCount) Count

func (this_ *SqlCount) Count(ctx context.Context) (res int64, err error)

func (*SqlCount) GetSql

func (this_ *SqlCount) GetSql() (sqlInfo string, args []any, err error)

func (*SqlCount) SetWhere

func (this_ *SqlCount) SetWhere(where *Conditions) *SqlCount

func (*SqlCount) Where

func (this_ *SqlCount) Where() *Conditions

type SqlDelete

type SqlDelete struct {

	// 模型 设置 如:表名、主键、包含字段、忽略字段、空值设置 等
	*ModelSetting
	// contains filtered or unexported fields
}

func (*SqlDelete) DeleteAll

func (this_ *SqlDelete) DeleteAll() *SqlDelete

DeleteAll 删除时候 必须 设置条件 除非 设置 DeleteAll

func (*SqlDelete) Exec

func (this_ *SqlDelete) Exec(ctx context.Context) (res sql.Result, err error)

func (*SqlDelete) GetSql

func (this_ *SqlDelete) GetSql() (sqlInfo string, args []any, err error)

func (*SqlDelete) SetWhere

func (this_ *SqlDelete) SetWhere(where *Conditions) *SqlDelete

func (*SqlDelete) Where

func (this_ *SqlDelete) Where() *Conditions

type SqlExpression

type SqlExpression interface {
	GetValue(b *SqlBuilder) (res any)
	// contains filtered or unexported methods
}

type SqlHandler

type SqlHandler interface {
	// RealTableName 获取真实 表名 ,SQL 中将使用返回的 表名 拼接 返回空 则不替换
	RealTableName(param *SqlParam, tableName string) (realTableName string)
	// WrapTableName 包装 表名 ,SQL 中将使用返回的 表名 拼接 返回空 则不替换
	WrapTableName(param *SqlParam, tableName string) (wrapTableName string)
	WrapColumnName(param *SqlParam, columnName string) (wrapColumnName string)
}

type SqlInsert

type SqlInsert struct {

	// 模型 设置 如:表名、主键、包含字段、忽略字段、空值设置 等
	*ModelSetting
	// contains filtered or unexported fields
}

func (*SqlInsert) Exec

func (this_ *SqlInsert) Exec(ctx context.Context) (res sql.Result, err error)

func (*SqlInsert) GetSql

func (this_ *SqlInsert) GetSql() (sqlInfo string, args []any, err error)

func (*SqlInsert) Value

func (this_ *SqlInsert) Value(column string, value any) *SqlInsert

type SqlNode

type SqlNode interface {
	Append(b *SqlBuilder)
	// contains filtered or unexported methods
}

type SqlNodeArgParam

type SqlNodeArgParam struct {
	Param SqlExpression `json:"param,omitempty"`
}

func (*SqlNodeArgParam) Append

func (this_ *SqlNodeArgParam) Append(b *SqlBuilder)

type SqlNodeArithmeticOperate

type SqlNodeArithmeticOperate struct {
	Left SqlExpression `json:"left"`
	// 算术运算符: + - * / %
	Operator string        `json:"operator"`
	Right    SqlExpression `json:"right"`
}

SqlNodeArithmeticOperate 算术运算: + - * / %

func (*SqlNodeArithmeticOperate) GetValue

func (this_ *SqlNodeArithmeticOperate) GetValue(b *SqlBuilder) (res any)

type SqlNodeBlock

type SqlNodeBlock struct {
	Children []SqlNode `json:"children"`
}

func (*SqlNodeBlock) Append

func (this_ *SqlNodeBlock) Append(b *SqlBuilder)

type SqlNodeComment

type SqlNodeComment struct {
	Comment string `json:"comment"`
}

func (*SqlNodeComment) Append

func (this_ *SqlNodeComment) Append(b *SqlBuilder)

type SqlNodeDDL

type SqlNodeDDL struct {
	*SqlNodeBlock
}

type SqlNodeDelete

type SqlNodeDelete struct {
	*SqlNodeBlock
}

type SqlNodeDotExpression

type SqlNodeDotExpression struct {
	Left  SqlExpression `json:"left"`
	Right SqlExpression `json:"right"`
}

func (*SqlNodeDotExpression) GetObjectField

func (this_ *SqlNodeDotExpression) GetObjectField(b *SqlBuilder, object any) (res any)

func (*SqlNodeDotExpression) GetValue

func (this_ *SqlNodeDotExpression) GetValue(b *SqlBuilder) (res any)

type SqlNodeElse

type SqlNodeElse struct {
	Children []SqlNode `json:"children"`
}

type SqlNodeElseIf

type SqlNodeElseIf struct {
	Test     SqlExpression `json:"test"`
	Children []SqlNode     `json:"children"`
}

type SqlNodeFloat

type SqlNodeFloat struct {
	Value  float64 `json:"value"`
	String string  `json:"string"`
}

func ToSqlNodeFloat

func ToSqlNodeFloat(str string) (res *SqlNodeFloat, err error)

func (*SqlNodeFloat) Append

func (this_ *SqlNodeFloat) Append(b *SqlBuilder)

func (*SqlNodeFloat) GetValue

func (this_ *SqlNodeFloat) GetValue(b *SqlBuilder) (res any)

type SqlNodeIdentifier

type SqlNodeIdentifier struct {
	Name string `json:"name"`
}

func (*SqlNodeIdentifier) GetObjectField

func (this_ *SqlNodeIdentifier) GetObjectField(b *SqlBuilder, object any) (res any)

func (*SqlNodeIdentifier) GetValue

func (this_ *SqlNodeIdentifier) GetValue(b *SqlBuilder) (res any)

type SqlNodeIf

type SqlNodeIf struct {
	Test     SqlExpression    `json:"test"`
	Children []SqlNode        `json:"children"`
	ElseIfs  []*SqlNodeElseIf `json:"elseIfs"`
	Else     *SqlNodeElse     `json:"else"`
}

func (*SqlNodeIf) Append

func (this_ *SqlNodeIf) Append(b *SqlBuilder)

type SqlNodeInsert

type SqlNodeInsert struct {
	*SqlNodeBlock
}

type SqlNodeInt

type SqlNodeInt struct {
	Value  int64  `json:"value"`
	String string `json:"string"`
}

func ToSqlNodeInt

func ToSqlNodeInt(str string) (res *SqlNodeInt, err error)

func (*SqlNodeInt) Append

func (this_ *SqlNodeInt) Append(b *SqlBuilder)

func (*SqlNodeInt) GetValue

func (this_ *SqlNodeInt) GetValue(b *SqlBuilder) (res any)

type SqlNodeLogicalOperate

type SqlNodeLogicalOperate struct {
	Left SqlExpression `json:"left"`
	// 逻辑运算符: && ||
	Operator string        `json:"operator"`
	Right    SqlExpression `json:"right"`
}

SqlNodeLogicalOperate 逻辑运算: && ||

func (*SqlNodeLogicalOperate) GetValue

func (this_ *SqlNodeLogicalOperate) GetValue(b *SqlBuilder) (res any)

type SqlNodeOptional

type SqlNodeOptional struct {
	Children []SqlNode `json:"children"`
	// contains filtered or unexported fields
}

func (*SqlNodeOptional) Append

func (this_ *SqlNodeOptional) Append(b *SqlBuilder)

type SqlNodeParam

type SqlNodeParam struct {
	Param SqlExpression `json:"param,omitempty"`
}

func (*SqlNodeParam) Append

func (this_ *SqlNodeParam) Append(b *SqlBuilder)

type SqlNodeParenthesis

type SqlNodeParenthesis struct {
	Expression SqlExpression `json:"expression"`
}

func (*SqlNodeParenthesis) GetValue

func (this_ *SqlNodeParenthesis) GetValue(b *SqlBuilder) (res any)

type SqlNodeRelationalOperate

type SqlNodeRelationalOperate struct {
	Left SqlExpression `json:"left"`
	// 比较(关系)运算符: == != > < >= <=
	Operator string        `json:"operator"`
	Right    SqlExpression `json:"right"`
}

SqlNodeRelationalOperate 比较(关系)运算: == != > < >= <=

func (*SqlNodeRelationalOperate) GetValue

func (this_ *SqlNodeRelationalOperate) GetValue(b *SqlBuilder) (res any)

type SqlNodeSelect

type SqlNodeSelect struct {
	*SqlNodeBlock
}

type SqlNodeSql

type SqlNodeSql struct {

	// 是 读取
	IsQuery bool `json:"isQuery,omitempty"`
	// 是 插入
	IsInsert bool `json:"isInsert,omitempty"`
	// 是 插入
	IsUpdate bool `json:"isUpdate,omitempty"`
	// 是 插入
	IsDelete bool `json:"isDelete,omitempty"`
	// 是 插入
	IsDDL bool `json:"isDDL,omitempty"`
	// 是 其它语句
	IsOther bool `json:"isOther,omitempty"`

	Root SqlNode `json:"root"`
}

func (*SqlNodeSql) Append

func (this_ *SqlNodeSql) Append(b *SqlBuilder)

func (*SqlNodeSql) GetSqlByMap

func (this_ *SqlNodeSql) GetSqlByMap(handler SqlHandler, data map[string]any) (sqlInfo string, args []any)

type SqlNodeString

type SqlNodeString struct {
	Value string `json:"value"`
}

func ToSqlNodeString

func ToSqlNodeString(str string) (res *SqlNodeString)

func (*SqlNodeString) Append

func (this_ *SqlNodeString) Append(b *SqlBuilder)

func (*SqlNodeString) GetValue

func (this_ *SqlNodeString) GetValue(b *SqlBuilder) (res any)

type SqlNodeTernary

type SqlNodeTernary struct {
	Test  SqlExpression `json:"test"`
	Left  SqlExpression `json:"left"`
	Right SqlExpression `json:"right"`
}

SqlNodeTernary 三元运算

func (*SqlNodeTernary) GetValue

func (this_ *SqlNodeTernary) GetValue(b *SqlBuilder) (res any)

type SqlNodeText

type SqlNodeText struct {
	Text string
}

func (*SqlNodeText) Append

func (this_ *SqlNodeText) Append(b *SqlBuilder)

type SqlNodeUpdate

type SqlNodeUpdate struct {
	*SqlNodeBlock
}

type SqlOption

type SqlOption struct {
	WrapOption
}

func NewSqlOption

func NewSqlOption() (res *SqlOption)

func (*SqlOption) RealTableName

func (this_ *SqlOption) RealTableName(param *SqlParam, tableName string) (realTableName string)

func (*SqlOption) Set

func (this_ *SqlOption) Set(fn func(o *SqlOption)) *SqlOption

func (*SqlOption) WrapColumnName

func (this_ *SqlOption) WrapColumnName(param *SqlParam, columnName string) (wrapColumnName string)

func (*SqlOption) WrapTableName

func (this_ *SqlOption) WrapTableName(param *SqlParam, tableName string) (wrapTableName string)

type SqlParam

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

func NewMapSqlParam

func NewMapSqlParam() (res *SqlParam)

func SqlParamByData

func SqlParamByData(data any) (res *SqlParam)

func SqlParamByMap

func SqlParamByMap(data map[string]any) (res *SqlParam)

func SqlParamByValue

func SqlParamByValue(data any, value reflect.Value) (res *SqlParam)

func (*SqlParam) FindParam

func (this_ *SqlParam) FindParam(name string) (v any, find bool)

func (*SqlParam) GetData

func (this_ *SqlParam) GetData() any

func (*SqlParam) GetObjectField

func (this_ *SqlParam) GetObjectField(obj any, name string) (res any)

func (*SqlParam) GetParam

func (this_ *SqlParam) GetParam(name string) (res any)

func (*SqlParam) GetStringParam

func (this_ *SqlParam) GetStringParam(name string) (res string)

func (*SqlParam) Set

func (this_ *SqlParam) Set(name string, value any) *SqlParam

type SqlParamParser

type SqlParamParser struct {
	NotParseArg bool // 不是 不解析参数值 只解析SQL
	ParamBefore string
	ParamAfter  string
	// contains filtered or unexported fields
}

func NewSqlParamParser

func NewSqlParamParser(sqlInfo string, param any) (res *SqlParamParser)

func (*SqlParamParser) Append

func (this_ *SqlParamParser) Append(sql string, param any) *SqlParamParser

func (*SqlParamParser) GetParamData

func (this_ *SqlParamParser) GetParamData(param any) (data map[string]any)

func (*SqlParamParser) Parse

func (this_ *SqlParamParser) Parse() (res string, args []any, err error)

func (*SqlParamParser) ParseInfo

func (this_ *SqlParamParser) ParseInfo() (info *SqlParamParserInfo, err error)

type SqlParamParserInfo

type SqlParamParserInfo struct {
	Sql        string
	Args       []any
	ParamNames []string
}

type SqlReader

type SqlReader struct {
	*ReadState

	*ReadScope
	// contains filtered or unexported fields
}

func NewSqlReader

func NewSqlReader(str string) (r *SqlReader)

func (*SqlReader) Next

func (this_ *SqlReader) Next()

func (*SqlReader) NextByCharEnd

func (this_ *SqlReader) NextByCharEnd(endChar string, skipChar string)

func (*SqlReader) NextHasChar

func (this_ *SqlReader) NextHasChar()

func (*SqlReader) NextLine

func (this_ *SqlReader) NextLine() (res string)

func (*SqlReader) Scan

func (this_ *SqlReader) Scan() (res string)

func (*SqlReader) ScanMore

func (this_ *SqlReader) ScanMore(size int) (res []string)

type SqlSelect

type SqlSelect struct {

	// 模型 设置 如:表名、主键、包含字段、忽略字段、空值设置 等
	*ModelSetting
	// contains filtered or unexported fields
}

func (*SqlSelect) GetSql

func (this_ *SqlSelect) GetSql() (sqlInfo string, args []any, err error)

func (*SqlSelect) Select

func (this_ *SqlSelect) Select(columns ...string) *SqlSelect

func (*SqlSelect) SelectAll

func (this_ *SqlSelect) SelectAll() *SqlSelect

SelectAll 查询时候 必须 设置条件 除非 设置 SelectAll

func (*SqlSelect) SetWhere

func (this_ *SqlSelect) SetWhere(where *Conditions) *SqlSelect

func (*SqlSelect) Where

func (this_ *SqlSelect) Where() *Conditions

type SqlTemplate

type SqlTemplate struct {
	SqlList []*SqlNodeSql

	// 中括号 可选 内容 是否
	BracketOptional bool

	// 设置 Debug 表示输出日志
	Debug bool
	// contains filtered or unexported fields
}

SqlTemplate SQL 模板语句 将 SQL 解析为 普通语句、参数替换语句、参数占位语句、if 语句 等 ${xx}: 参数占位语句,拼接SQL 为 ? 然后拼接参数 #{xx}和{xx}: 参数替换语句,直接将 参数 拼接SQL {xx}: 参数替换语句,直接将 参数 替换 if(xx){xxx}: 条件 [ss {x}]: BracketOptional = true,非必须,有参数情况,如果有 x 这个参数 则拼接 [ss ss dfd]: BracketOptional = true,非必须,无参数情况,如果参数有 ssSsDfd 则拼接

func NewSqlTemplate

func NewSqlTemplate(sqlList ...string) (t *SqlTemplate)

func (*SqlTemplate) Append

func (this_ *SqlTemplate) Append(sqlList ...string) *SqlTemplate

func (*SqlTemplate) GetSql

func (this_ *SqlTemplate) GetSql(handler SqlHandler, param map[string]any) (sqlInfo string, sqlArgs []any)

func (*SqlTemplate) GetSqlHandler

func (this_ *SqlTemplate) GetSqlHandler() SqlHandler

func (*SqlTemplate) GetSqlList

func (this_ *SqlTemplate) GetSqlList(handler SqlHandler, param map[string]any) (sqlList []string, sqlArgsList [][]any)

func (*SqlTemplate) GetTemplateSql

func (this_ *SqlTemplate) GetTemplateSql() (str string)

func (*SqlTemplate) Parse

func (this_ *SqlTemplate) Parse() (err error)

func (*SqlTemplate) ParseSql

func (this_ *SqlTemplate) ParseSql(r *SqlReader) (res *SqlNodeSql, err error)

func (*SqlTemplate) ParseSqlList

func (this_ *SqlTemplate) ParseSqlList(str string) (res []*SqlNodeSql, err error)

func (*SqlTemplate) SetSqlHandler

func (this_ *SqlTemplate) SetSqlHandler(sqlHandler SqlHandler) *SqlTemplate

type SqlUpdate

type SqlUpdate struct {

	// 模型 设置 如:表名、主键、包含字段、忽略字段、空值设置 等
	*ModelSetting
	// contains filtered or unexported fields
}

func (*SqlUpdate) Exec

func (this_ *SqlUpdate) Exec(ctx context.Context) (res sql.Result, err error)

func (*SqlUpdate) GetSql

func (this_ *SqlUpdate) GetSql() (sqlInfo string, args []any, err error)

func (*SqlUpdate) SetWhere

func (this_ *SqlUpdate) SetWhere(where *Conditions) *SqlUpdate

func (*SqlUpdate) UpdateAll

func (this_ *SqlUpdate) UpdateAll() *SqlUpdate

UpdateAll 更新时候 必须 设置条件 除非 设置 UpdateAll

func (*SqlUpdate) Value

func (this_ *SqlUpdate) Value(column string, value any) *SqlUpdate

func (*SqlUpdate) Where

func (this_ *SqlUpdate) Where() *Conditions

type StringType

type StringType interface {
	String() string
}

type Table

type Table struct {
	DatabaseName string `json:"databaseName,omitempty"`
	SchemaName   string `json:"schemaName,omitempty"`

	Name    string `json:"name,omitempty"`
	Comment string `json:"comment,omitempty"`

	AutoIncrement       bool   `json:"autoIncrement,omitempty"`
	AutoIncrementStart  int64  `json:"autoIncrementStart,omitempty"`
	AutoIncrementName   string `json:"autoIncrementName,omitempty"`
	AutoIncrementCreate bool   `json:"autoIncrementCreate,omitempty"`

	ColumnList     []*Column     `json:"columnList,omitempty"`
	ConstraintList []*Constraint `json:"constraintList,omitempty"`
	IndexList      []*Index      `json:"indexList,omitempty"`

	IfNotExists bool `json:"ifNotExists,omitempty"`
	// 扩展属性
	Extend map[string]any `json:"extend,omitempty"`
}

func TableByMap

func TableByMap(data map[string]any) (res *Table)

func (*Table) FindColumn

func (this_ *Table) FindColumn(name string) (res *Column)

func (*Table) Init

func (this_ *Table) Init(databaseName string, schemaName string, handler DDLHandler)

type User

type User struct {
	Name     string `json:"name,omitempty"`
	Password string `json:"password,omitempty"`

	IsSystem bool `json:"isSystem,omitempty"`

	// 扩展属性
	Extend map[string]any `json:"param,omitempty"`
}

func UserByMap

func UserByMap(data map[string]any) (res *User)

type WhereOperator

type WhereOperator struct {
	Column   string
	Operator string
}

type WrapOption

type WrapOption struct {
	// 是否 包装 名称
	WrapNameOpen *bool `json:"wrapNameOpen,omitempty"`
	// 包装 名称 的字符
	WrapNameChar *string `json:"wrapNameChar,omitempty"`
	// 是否 包装 表名称 该配置 > NameWrap
	WrapTableNameOpen *bool `json:"wrapTableNameOpen,omitempty"`
	// 是否 包装 字段名称 该配置 > NameWrap
	WrapColumnNameOpen *bool `json:"wrapColumnNameOpen,omitempty"`

	// 包装 字符串的 字符
	WrapStringChar *string `json:"wrapStringChar,omitempty"`
}

func (WrapOption) IsWrapColumnName

func (this_ WrapOption) IsWrapColumnName() bool

func (WrapOption) IsWrapName

func (this_ WrapOption) IsWrapName() bool

func (WrapOption) IsWrapTableName

func (this_ WrapOption) IsWrapTableName() bool

func (WrapOption) Names

func (this_ WrapOption) Names(names []string) (res string)

func (WrapOption) Set

func (this_ WrapOption) Set(fn func(o WrapOption)) WrapOption

func (WrapOption) WrapColumnName

func (this_ WrapOption) WrapColumnName(name string) string

func (WrapOption) WrapName

func (this_ WrapOption) WrapName(name string) (res string)

func (WrapOption) WrapNames

func (this_ WrapOption) WrapNames(names []string) (res string)

func (WrapOption) WrapString

func (this_ WrapOption) WrapString(str string) (res string)

func (WrapOption) WrapTableName

func (this_ WrapOption) WrapTableName(name string) string

Jump to

Keyboard shortcuts

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