commSql

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: GPL-3.0 Imports: 18 Imported by: 4

README

功能说明

commSql对go原生的sql组件进行了封装,提供了commEntity.IEntity的schema的能力,从而能够形成自动ORM的能力

这里的ORM就是将对象实体的CRUD变成SQL的CRUD

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SQL          EntitySQL
	Client       *SqlClient
	Fox          foxSqlService
	SqlBuilder   sqlBuilder
	EntityEngine clientEntityEngine
)

Functions

func DeleteEntityById

func DeleteEntityById(entityType string, id int64) error

func GetDBType added in v1.0.1

func GetDBType() string

func GetEntityType added in v1.0.1

func GetEntityType() []string

func HasSchema added in v1.0.1

func HasSchema(entityType string) bool

func InsertEntity

func InsertEntity(entity commEntity.IEntity) error

func InsertRecord added in v1.0.2

func InsertRecord(tableName string, entity commEntity.IEntity) error

func Query

func Query(entityType string, sql string) ([]commEntity.IEntity, error)

func QueryCount added in v1.0.1

func QueryCount(sql string) (int, error)

func QueryEntityById

func QueryEntityById(entityType string, id int64) (commEntity.IEntity, error)

func QueryEntityList

func QueryEntityList(entityType string) ([]commEntity.IEntity, error)

func Register added in v1.0.1

func Register(entityType string)

func SQuery added in v1.0.2

func SQuery(entityType string, sql string, args []interface{}) ([]commEntity.IEntity, error)

func SQueryCount added in v1.0.2

func SQueryCount(sql string, args []interface{}) (int, error)

func UpdateEntityById

func UpdateEntityById(entity commEntity.IEntity) error

func UpdateRecordById added in v1.0.2

func UpdateRecordById(tableName string, entity commEntity.IEntity) error

Types

type EntitySQL added in v1.0.2

type EntitySQL struct {
}

func (*EntitySQL) DeleteWhere added in v1.0.2

func (e *EntitySQL) DeleteWhere(entityType string, where string) (string, error)

func (*EntitySQL) DeleteWhereId added in v1.0.2

func (e *EntitySQL) DeleteWhereId(entityType string, id int64) (string, error)

func (*EntitySQL) Insert added in v1.0.2

func (e *EntitySQL) Insert(entity commEntity.IEntity) (string, []interface{}, error)

func (*EntitySQL) InsertRecord added in v1.0.2

func (e *EntitySQL) InsertRecord(tblName string, entity commEntity.IEntity) (string, []interface{}, error)

func (*EntitySQL) Select added in v1.0.2

func (e *EntitySQL) Select(entityType string) (string, error)

func (*EntitySQL) SelectWhere added in v1.0.2

func (e *EntitySQL) SelectWhere(entityType string, where string) (string, error)

func (*EntitySQL) SelectWhereId added in v1.0.2

func (e *EntitySQL) SelectWhereId(entityType string, id int64) (string, error)

func (*EntitySQL) UpdateRecordWhereId added in v1.0.2

func (e *EntitySQL) UpdateRecordWhereId(tableName string, entity commEntity.IEntity) (string, []interface{}, error)

func (*EntitySQL) UpdateWhereId added in v1.0.2

func (e *EntitySQL) UpdateWhereId(entity commEntity.IEntity) (string, []interface{}, error)

type FieldValue added in v1.0.1

type FieldValue struct {
	Name  string
	Value interface{} //字段的数值
}

type SQLOption added in v1.0.1

type SQLOption struct {
	DriverName string
	DataSource string
}

type SqlClient added in v1.0.2

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

func (*SqlClient) ConnectMySQL added in v1.0.2

func (e *SqlClient) ConnectMySQL() error

func (*SqlClient) ConnectSQLite added in v1.0.2

func (e *SqlClient) ConnectSQLite(fileName string) error

func (*SqlClient) Exec added in v1.0.2

func (e *SqlClient) Exec(sql string, values []interface{}) (int64, error)

Exec 执行sql 参数:

sql 准备执行的sql语句
values sql语言中的参数表

说明:如果你构造的values参数为nil,那么你要确保自己的sql不含有文本参数的语句,不会发生注入式攻击

func (*SqlClient) Query added in v1.0.2

func (e *SqlClient) Query(entityType string, sql string) ([]commEntity.IEntity, error)

Query 查询数据 说明:直接执行SQL语句,不进行预处理

func (*SqlClient) QueryCount added in v1.0.2

func (e *SqlClient) QueryCount(sql string) (int, error)

func (*SqlClient) QueryList added in v1.0.2

func (e *SqlClient) QueryList(sql string, fields []FieldValue) ([]map[string]interface{}, error)

func (*SqlClient) SQuery added in v1.0.2

func (e *SqlClient) SQuery(entityType string, sql string, args []interface{}) ([]commEntity.IEntity, error)

SQuery 安全查询数据 说明:带预处理的方式执行SQL语句,防止注入攻击,或者特殊字符的冲突

func (*SqlClient) SQueryCount added in v1.0.2

func (e *SqlClient) SQueryCount(sql string, args []interface{}) (int, error)

func (*SqlClient) SQueryList added in v1.0.2

func (e *SqlClient) SQueryList(sql string, fields []FieldValue, args []interface{}) ([]map[string]interface{}, error)

Jump to

Keyboard shortcuts

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