gsdb

package
v1.9.9 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Query = iota
	Insert
	Update
	Delete
	Exec //仅返回受影响行数 如果是插入 需要使用Insert
)
View Source
const DbTypeMysql = `mysql`
View Source
const DbTypePgsql = `pgsql`
View Source
const DbTypeSqlite = `sqlite`
View Source
const RedisKeyHash = `hash`
View Source
const RedisKeyList = `list`
View Source
const RedisKeySet = `set`
View Source
const RedisKeyString = `string`
View Source
const RedisKeyZSet = `zset`

Variables

This section is empty.

Functions

func BaseHashArrayCache

func BaseHashArrayCache(cli *GsRedis, key string, queryFunc func() (map[string]map[string]any, error), expired time.Duration) (map[string]map[string]any, error)

BaseHashArrayCache map[string]map[string]any -> hash[string]string init 将一个双层map存为 hash

func BaseHashCache

func BaseHashCache(cli *GsRedis, key string, queryFunc func() (map[string]string, error), expired time.Duration) (map[string]string, error)

BaseHashCache map[string]string -> hash[string]string 将单层map存入hash

func BaseString2Cache

func BaseString2Cache(cli *GsRedis, key string, queryFunc func() (map[string]any, error), expired time.Duration) (string, error)

BaseString2Cache map[string]any -> string 将一个map[string]any 存为 string 最后返回string

func BaseStringCache

func BaseStringCache(cli *GsRedis, key string, queryFunc func() (map[string]any, error), expired time.Duration) (map[string]any, error)

BaseStringCache map[string]any -> string 将一个map[string]any 存为 string

func RedisGetKey

func RedisGetKey(client *GsRedis, key string) string

RedisGetKey 获取key的值 @deprecated 不再使用

func RedisGetKeyE

func RedisGetKeyE(client *GsRedis, key string) (string, error)

RedisGetKeyE 获取key的值 @deprecated 不再使用

func RedisGetStringCall

func RedisGetStringCall(client *GsRedis, key string, call func() string, expire time.Duration) string

RedisGetStringCall 获取redis中的数据 @deprecated 不再使用

func RedisGetStringCallE

func RedisGetStringCallE(client *GsRedis, key string, call func() string, expire time.Duration) (string, error)

RedisGetStringCallE 获取redis中的数据 @deprecated 不再使用

func RedisHash

func RedisHash(client *GsRedis, key, subKey string, call func() map[string]string, expire time.Duration) string

RedisHash 获取hash中的某一个值 @deprecated 不再使用

func RedisHashAll

func RedisHashAll(client *GsRedis, key string, call func() map[string]string, expire time.Duration) map[string]string

RedisHashAll 获取hash中的所有值 @deprecated 不再使用

func RedisHashAllE

func RedisHashAllE(client *GsRedis, key string, call func() map[string]string, expire time.Duration) (map[string]string, error)

RedisHashAllE 获取hash中的所有值 @deprecated 不再使用

func RedisHashE

func RedisHashE(client *GsRedis, key, subKey string, call func() map[string]string, expire time.Duration) (string, error)

RedisHashE 获取hash中的某一个值 @deprecated 不再使用

func RedisKeyExist

func RedisKeyExist(client *GsRedis, key string) (bool, error)

RedisKeyExist 判断key是否存在 @deprecated 不再使用

func RedisSetExpire

func RedisSetExpire(client *GsRedis, key string, expire time.Duration) error

RedisSetExpire 设置缓存有效期 @deprecated 不再使用

func RedisSetNx

func RedisSetNx(client *GsRedis, key, value string, expire time.Duration) bool

RedisSetNx 获取锁 @deprecated 不再使用

func RedisSetNxE

func RedisSetNxE(client *GsRedis, key, value string, expire time.Duration) (bool, error)

RedisSetNxE 获取锁 @deprecated 不再使用

Types

type GsMysql

type GsMysql struct {
	MysqlConfig *MysqlConfig

	GsLog *gstool.GsSlog
	Ssh   *gsssh.SshConfig
	// contains filtered or unexported fields
}

func NewMysql

func NewMysql(config *MysqlConfig, autoTransType bool) *GsMysql

func (*GsMysql) CreateConn

func (h *GsMysql) CreateConn() error

CreateConn create a connection

func (*GsMysql) ExecBySql

func (h *GsMysql) ExecBySql(sqlStr string, params ...interface{}) *SqlQuick

ExecBySql 执行

func (*GsMysql) GetTx added in v1.9.6

func (h *GsMysql) GetTx() (*sql.Tx, error)

GetTx 获取事务 注意:如果使用了隧道,那么在tx释放之前,所有查询都会被阻塞

func (*GsMysql) InsertBySql

func (h *GsMysql) InsertBySql(sqlStr string, params ...interface{}) *SqlQuick

InsertBySql 插入

func (*GsMysql) OpenDebug

func (h *GsMysql) OpenDebug()

func (*GsMysql) QueryBySql

func (h *GsMysql) QueryBySql(sqlStr string, params ...interface{}) *SqlQuick

QueryBySql 获取多行数据

func (*GsMysql) QuickCreate

func (h *GsMysql) QuickCreate(tableName string, params map[string]interface{}) *SqlQuick

QuickCreate 快速根据map插入

func (*GsMysql) QuickDelete

func (h *GsMysql) QuickDelete(tableName string, where map[string]interface{}) *SqlQuick

QuickDelete 快速删除数据

func (*GsMysql) QuickQuery

func (h *GsMysql) QuickQuery(tableName, fields string, where map[string]interface{}) *SqlQuick

QuickQuery 快速查询数据

func (*GsMysql) QuickUpdate

func (h *GsMysql) QuickUpdate(tableName string, where map[string]interface{}, update map[string]interface{}) *SqlQuick

QuickUpdate 快速更新

func (*GsMysql) SetGsLog

func (h *GsMysql) SetGsLog(gsLog *gstool.GsSlog)

func (*GsMysql) SetOpenFunc

func (h *GsMysql) SetOpenFunc(openFunc func(db *sql.DB))

func (*GsMysql) TableDetail

func (h *GsMysql) TableDetail(tableName string) *SqlQuick

TableDetail 查询表的信息

type GsPgsql

type GsPgsql struct {
	PgsqlConfig *PgsqlConfig

	GsLog *gstool.GsSlog
	Ssh   *gsssh.SshConfig
	// contains filtered or unexported fields
}

func NewPgsql

func NewPgsql(config *PgsqlConfig, autoTransType bool) *GsPgsql

func (*GsPgsql) CreateConn

func (h *GsPgsql) CreateConn() error

CreateConn create a connection

func (*GsPgsql) ExecBySql

func (h *GsPgsql) ExecBySql(sqlStr string, params ...interface{}) *SqlQuick

ExecBySql 执行

func (*GsPgsql) GetTx added in v1.9.6

func (h *GsPgsql) GetTx() (*sql.Tx, error)

GetTx 获取事务 注意:如果使用了隧道,那么在tx释放之前,所有查询都会被阻塞

func (*GsPgsql) InsertBySql

func (h *GsPgsql) InsertBySql(sqlStr string, params ...interface{}) *SqlQuick

InsertBySql 插入

func (*GsPgsql) OpenDebug

func (h *GsPgsql) OpenDebug()

func (*GsPgsql) QueryBySql

func (h *GsPgsql) QueryBySql(sqlStr string, params ...interface{}) *SqlQuick

QueryBySql 获取多行数据

func (*GsPgsql) QuickCreate

func (h *GsPgsql) QuickCreate(tableName string, params map[string]interface{}) *SqlQuick

QuickCreate 快速根据map插入

func (*GsPgsql) QuickDelete

func (h *GsPgsql) QuickDelete(tableName string, where map[string]interface{}) *SqlQuick

QuickDelete 快速删除数据

func (*GsPgsql) QuickQuery

func (h *GsPgsql) QuickQuery(tableName, fields string, where map[string]interface{}) *SqlQuick

QuickQuery 快速查询数据

func (*GsPgsql) QuickUpdate

func (h *GsPgsql) QuickUpdate(tableName string, where map[string]interface{}, update map[string]interface{}) *SqlQuick

QuickUpdate 快速更新

func (*GsPgsql) SetGsLog

func (h *GsPgsql) SetGsLog(gsLog *gstool.GsSlog)

func (*GsPgsql) SetOpenFunc

func (h *GsPgsql) SetOpenFunc(openFunc func(db *sql.DB))

func (*GsPgsql) TableDetail

func (h *GsPgsql) TableDetail(tableName string) *SqlQuick

TableDetail 查询表的信息

type GsRedis

type GsRedis struct {
	RedisConfig *RedisConfig
	Client      *redis.Client
	Ssh         *gsssh.SshConfig
}

func NewRedis

func NewRedis(config *RedisConfig) *GsRedis

func (*GsRedis) CreateConn

func (h *GsRedis) CreateConn() error

CreateConn create a connection

type GsSqlite

type GsSqlite struct {
	DbPath string

	GsLog *gstool.GsSlog
	// contains filtered or unexported fields
}

func NewSqlite

func NewSqlite(dbPath string, autoTransType bool) (*GsSqlite, error)

NewSqlite create sqlite

func (*GsSqlite) CreateConn

func (h *GsSqlite) CreateConn() error

CreateConn create connection

func (*GsSqlite) ExecBySql

func (h *GsSqlite) ExecBySql(sqlStr string, params ...interface{}) *SqlQuick

ExecBySql 执行

func (*GsSqlite) GetTx added in v1.9.6

func (h *GsSqlite) GetTx() (*sql.Tx, error)

GetTx 获取事务

func (*GsSqlite) InsertBySql

func (h *GsSqlite) InsertBySql(sqlStr string, params ...interface{}) *SqlQuick

InsertBySql 插入

func (*GsSqlite) OpenDebug

func (h *GsSqlite) OpenDebug()

func (*GsSqlite) QueryBySql

func (h *GsSqlite) QueryBySql(sqlStr string, params ...interface{}) *SqlQuick

QueryBySql 获取多行数据

func (*GsSqlite) QuickCreate

func (h *GsSqlite) QuickCreate(tableName string, params map[string]interface{}) *SqlQuick

QuickCreate 快速根据map插入

func (*GsSqlite) QuickDelete

func (h *GsSqlite) QuickDelete(tableName string, where map[string]interface{}) *SqlQuick

QuickDelete 快速删除数据

func (*GsSqlite) QuickQuery

func (h *GsSqlite) QuickQuery(tableName, fields string, where map[string]interface{}) *SqlQuick

QuickQuery 快速查询数据

func (*GsSqlite) QuickUpdate

func (h *GsSqlite) QuickUpdate(tableName string, where map[string]interface{}, update map[string]interface{}) *SqlQuick

QuickUpdate 快速更新

func (*GsSqlite) SetGsLog

func (h *GsSqlite) SetGsLog(gsLog *gstool.GsSlog)

func (*GsSqlite) TableDetail

func (h *GsSqlite) TableDetail(tableName string) *SqlQuick

TableDetail 查询表的信息

type MysqlConfig

type MysqlConfig struct {
	Name              string `json:"name"`
	Host              string `json:"host"`
	Port              int64  `json:"port"`
	Username          string `json:"username"`
	Password          string `json:"password"`
	Dbname            string `json:"dbname"`
	MaxOpenConns      int    `json:"maxOpenConns"`      //最大连接池连接数量
	MaxIdleConns      int    `json:"maxIdleConns"`      //最大可空闲连接数
	MaxLifetimeSecond int    `json:"maxLifetimeSecond"` //链接重置时间 秒
}

type PgsqlConfig

type PgsqlConfig struct {
	Name              string `json:"name"`
	Host              string `json:"host"`
	Port              int64  `json:"port"`
	Username          string `json:"username"`
	Password          string `json:"password"`
	Dbname            string `json:"dbname"`
	PoolSize          int    `json:"poolsize"`
	MaxOpenConns      int    `json:"maxOpenConns"`
	MaxIdleConns      int    `json:"maxIdleConns"`
	MaxLifetimeSecond int    `json:"maxLifetimeSecond"` //链接重置时间 秒
}

type RedisConfig

type RedisConfig struct {
	Name              string `json:"name"`
	Host              string `json:"host"`
	Port              int64  `json:"port"`
	Password          string `json:"password"`
	Default           int    `json:"default"`
	Username          string `json:"userName"`
	MaxOpenConns      int    `json:"maxOpenConns"`      //最大连接池连接数量
	MaxIdleConns      int    `json:"maxIdleConns"`      //最大可空闲连接数
	MaxLifetimeSecond int64  `json:"maxLifetimeSecond"` //连接的最大生存时间
}

type SqlFormat

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

func NewSqlFormat

func NewSqlFormat(boolTransType bool, dbType string, tableFieldFunc func(string string) (map[string]string, error)) *SqlFormat

func (*SqlFormat) FormatInsert

func (h *SqlFormat) FormatInsert(tableName string, insert map[string]any) (string, string, []any, error)

FormatInsert 仅支持quick create

func (*SqlFormat) FormatQuery

func (h *SqlFormat) FormatQuery(tableName string, where map[string]any, valueList *[]any) (string, error)

FormatQuery 仅支持quick 系列

func (*SqlFormat) FormatUpdate

func (h *SqlFormat) FormatUpdate(tableName string, update map[string]any, valueList *[]any) (string, error)

FormatUpdate 仅支持quick update

type SqlQuick

type SqlQuick struct {
	GsLog *gstool.GsSlog
	// contains filtered or unexported fields
}

func (*SqlQuick) All

func (h *SqlQuick) All(txs ...*sql.Tx) ([]map[string]any, error)

All 操作多条

func (*SqlQuick) Debug

func (h *SqlQuick) Debug() *SqlQuick

func (*SqlQuick) Debugf

func (h *SqlQuick) Debugf(msg string, params ...interface{})

func (*SqlQuick) Errof

func (h *SqlQuick) Errof(msg string, params ...interface{})

func (*SqlQuick) Exec

func (h *SqlQuick) Exec(txs ...*sql.Tx) (int64, error)

Exec 执行变更

func (*SqlQuick) ExecBySql

func (h *SqlQuick) ExecBySql(sqlStr string, params ...interface{}) *SqlQuick

ExecBySql 执行

func (*SqlQuick) GetSql

func (h *SqlQuick) GetSql() string

func (*SqlQuick) InsertBySql

func (h *SqlQuick) InsertBySql(sqlStr string, params ...interface{}) *SqlQuick

InsertBySql 插入

func (*SqlQuick) Limit

func (h *SqlQuick) Limit(limit int) *SqlQuick

Limit 操作多条

func (*SqlQuick) OffsetLimit

func (h *SqlQuick) OffsetLimit(offset, limit int) *SqlQuick

func (*SqlQuick) One

func (h *SqlQuick) One(txs ...*sql.Tx) (map[string]any, error)

One 查询

func (*SqlQuick) Order

func (h *SqlQuick) Order(orderSql string) *SqlQuick

func (*SqlQuick) QueryBySql

func (h *SqlQuick) QueryBySql(sqlStr string, params ...interface{}) *SqlQuick

QueryBySql 获取多行数据

func (*SqlQuick) QuickCreate

func (h *SqlQuick) QuickCreate(tableName string, params map[string]interface{}, primaryKey ...string) *SqlQuick

func (*SqlQuick) QuickDelete

func (h *SqlQuick) QuickDelete(tableName string, where map[string]interface{}) *SqlQuick

QuickDelete 快速删除数据

func (*SqlQuick) QuickQuery

func (h *SqlQuick) QuickQuery(tableName, fields string, where map[string]interface{}) *SqlQuick

func (*SqlQuick) QuickUpdate

func (h *SqlQuick) QuickUpdate(tableName string, where map[string]interface{}, update map[string]interface{}) *SqlQuick

QuickUpdate 快速更新

func (*SqlQuick) Select added in v1.9.0

func (h *SqlQuick) Select() (any, error)

Select 快速查询单个字段值

func (*SqlQuick) Selects added in v1.9.0

func (h *SqlQuick) Selects() ([]any, error)

Selects 快速查询多条数据的某个字段值

func (*SqlQuick) TableColumnsMap

func (h *SqlQuick) TableColumnsMap(columnList []map[string]any) (map[string]string, error)

TableColumnsMap 查询表的所有列 map[string]string

func (*SqlQuick) TableDetail

func (h *SqlQuick) TableDetail(tableName string) ([]map[string]any, error)

TableDetail 查询表的信息

Jump to

Keyboard shortcuts

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