hicon

package module
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 7 Imported by: 0

README

License

This project is licensed under the MIT License - see the LICENSE file for details.

img.png

[Flowchart]

img.png

Installation

Install client sdk
go get github.com/vothanhdo2602/hicon-go
Run Hicon
docker run --name hicon -p 7979:7979 -d vothanhdo2602/hicon

Why Hicon?

  • Suitable for high CCU systems.
  • Hicon is a solution that provides optimization techniques such as caching and connection pooling to improve application performance.
  • It also supports multiple databases including MySQL and PostgreSQL, making it easy to integrate with existing systems or add new ones as needed. Additionally, its built-in query builder ensures secure access to sensitive information stored within those databases. Finally, its ability to combine similar queries together reduces overhead costs associated with running multiple requests simultaneously.
  • Hicon is designed to be fast and efficient by minimizing the number of database queries made during each operation. This allows developers to build applications that can handle large amounts of data without sacrificing performance or scalability.
  • Overall, Hicon offers a powerful set of features that make it ideal for building scalable web applications that require robust database integration capabilities. Whether you're working on a small project or something more ambitious, this tool will help streamline your workflow while ensuring optimal performance throughout development cycles.

Features

  • Built-in query builder based on BunORM for security.
  • Communicate with gRPC.
  • Combine identical queries in the same time into single query.
  • Cache connections in pool.
  • Support for multi DBs: MySQL, Postgresql.
  • Connect with your Redis for better performance.
  • Optimized Redis cache size.
  • Client SDK for Node.js, Golang.
  • Disable cache at global and per request.
  • Custom your lock key with write actions.
  • Bulk write operations with transactions.

Backlogs

  • SDK for PHP, C#, Ruby, Java...
  • OpenTelemetry.

Client SDK

Go
NodeJS ==> Coming soon...

Example:

go to example.go

Important

  • Hicon is still in beta version and may have some bugs.
  • There are many breaking changes between versions so please check before upgrading.

Documentation

Overview

Package hicon provides a client SDK for optimizing database queries through hicon query proxy.

MIT License - see LICENSE file for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRequest

type BaseRequest struct {
	Headers map[string]string `json:"headers"`
	Body    interface{}       `json:"body"`
}

type BaseResponse added in v1.1.0

type BaseResponse struct {
	Data    interface{} `json:"data"`
	Status  int         `json:"status"`
	Message string      `json:"message"`
	Shared  bool        `json:"shared"`
	Success bool        `json:"success"`
}

type BulkInsert

type BulkInsert struct {
	LockKey      string
	Table        string
	Data         []interface{}
	DisableCache bool
}

func (*BulkInsert) Cache added in v1.1.6

func (s *BulkInsert) Cache(isCache bool) *BulkInsert

func (*BulkInsert) Exec

func (s *BulkInsert) Exec(ctx context.Context, opts *ExecOptions) (r *BaseResponse, err error)

func (*BulkInsert) ToOperation

func (s *BulkInsert) ToOperation() *Operation

func (*BulkInsert) WithData added in v1.1.6

func (s *BulkInsert) WithData(data []interface{}) *BulkInsert

func (*BulkInsert) WithLockKey

func (s *BulkInsert) WithLockKey(lockKey string) *BulkInsert

type BulkUpdateByPK

type BulkUpdateByPK struct {
	// Lock key for concurrent insert operations
	// The later task with the same lock key in the same time will not execute and get the result from the first task
	LockKey      string
	Table        string
	Set          []string
	Where        []string
	Data         interface{}
	DisableCache bool
}

func (*BulkUpdateByPK) Cache added in v1.1.6

func (s *BulkUpdateByPK) Cache(isCache bool) *BulkUpdateByPK

func (*BulkUpdateByPK) Exec

func (s *BulkUpdateByPK) Exec(ctx context.Context, opts *ExecOptions) (r *BaseResponse, err error)

func (*BulkUpdateByPK) ToOperation

func (s *BulkUpdateByPK) ToOperation() *Operation

func (*BulkUpdateByPK) WithData added in v1.1.6

func (s *BulkUpdateByPK) WithData(data []interface{}) *BulkUpdateByPK

func (*BulkUpdateByPK) WithLockKey

func (s *BulkUpdateByPK) WithLockKey(lockKey string) *BulkUpdateByPK

func (*BulkUpdateByPK) WithSet added in v1.1.6

func (s *BulkUpdateByPK) WithSet(columns ...string) *BulkUpdateByPK

func (*BulkUpdateByPK) WithWhere added in v1.1.6

func (s *BulkUpdateByPK) WithWhere(columns ...string) *BulkUpdateByPK

type BulkWriteWithTx

type BulkWriteWithTx struct {
	LockKey    string
	Operations []*Operation
}

func (*BulkWriteWithTx) Exec

func (s *BulkWriteWithTx) Exec(ctx context.Context, opts *ExecOptions) (r *BaseResponse, err error)

func (*BulkWriteWithTx) WithLockKey

func (s *BulkWriteWithTx) WithLockKey(lockKey string) *BulkWriteWithTx

type Client

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

func NewClient

func NewClient(ctx context.Context, addr string) (*Client, error)

func (*Client) NewBulkInsert

func (s *Client) NewBulkInsert(table string) *BulkInsert

func (*Client) NewBulkUpdateByPK

func (s *Client) NewBulkUpdateByPK(table string) *BulkUpdateByPK

func (*Client) NewBulkWriteWithTx

func (s *Client) NewBulkWriteWithTx(operations ...*Operation) *BulkWriteWithTx

func (*Client) NewDeleteByPK

func (s *Client) NewDeleteByPK(table string) *DeleteByPK

func (*Client) NewExec

func (s *Client) NewExec(sql string, args ...interface{}) *Exec

func (*Client) NewFindAll

func (s *Client) NewFindAll(table string) *FindAll

func (*Client) NewFindByPK

func (s *Client) NewFindByPK(table string) *FindByPK

func (*Client) NewFindOne

func (s *Client) NewFindOne(table string) *FindOne

func (*Client) NewUpdateAll

func (s *Client) NewUpdateAll(table string) *UpdateAll

func (*Client) NewUpdateByPK

func (s *Client) NewUpdateByPK(table string) *UpdateByPK

func (*Client) NewUpsertConfig

func (s *Client) NewUpsertConfig(opts ...UpsertConfigOption) *UpsertConfig

NewUpsertConfig New creates a new NewUpsertConfig with default settings

type Column

type Column struct {
	Name         string
	Type         constant.ColumnType
	Nullable     bool
	IsPrimaryKey bool
	SoftDelete   bool
}

type DBConfig

type DBConfig struct {
	Type     constant.DBType
	Host     string
	Port     int
	Username string
	Password string
	Database string
	MaxCons  int
	TLS      *TLS
}

type DeleteByPK

type DeleteByPK struct {
	// Lock key for concurrent insert operations
	// The later task with the same lock key in the same time will not execute and get the result from the first task
	LockKey      string
	Table        string
	Data         interface{}
	Where        []*QueryWithArgs
	DisableCache bool
	ForceDelete  bool // if enable soft delete in table
}

func (*DeleteByPK) Cache added in v1.1.6

func (s *DeleteByPK) Cache(isCache bool) *DeleteByPK

func (*DeleteByPK) Exec

func (s *DeleteByPK) Exec(ctx context.Context, opts *ExecOptions) (r *BaseResponse, err error)

func (*DeleteByPK) ToOperation

func (s *DeleteByPK) ToOperation() *Operation

func (*DeleteByPK) WithData added in v1.1.6

func (s *DeleteByPK) WithData(data interface{}) *DeleteByPK

func (*DeleteByPK) WithForceDelete added in v1.1.6

func (s *DeleteByPK) WithForceDelete(forceDelete bool) *DeleteByPK

func (*DeleteByPK) WithLockKey

func (s *DeleteByPK) WithLockKey(lockKey string) *DeleteByPK

func (*DeleteByPK) WithWhere added in v1.1.6

func (s *DeleteByPK) WithWhere(query string, args ...interface{}) *DeleteByPK

type Exec

type Exec struct {
	LockKey string
	Sql     string
	Args    []interface{}
}

func (*Exec) Exec

func (s *Exec) Exec(ctx context.Context, opts *ExecOptions) (r *BaseResponse, err error)

func (*Exec) ToOperation

func (s *Exec) ToOperation() *Operation

func (*Exec) WithLockKey

func (s *Exec) WithLockKey(lockKey string) *Exec

type ExecOptions added in v1.1.0

type ExecOptions struct {
	RequestID string
}

type FindAll

type FindAll struct {
	Table               string
	DisableCache        bool
	Selects             []string
	Where               []*QueryWithArgs
	Relations           []string
	Joins               []*Join
	Limit               int
	Offset              int
	OrderBy             []string
	WhereAllWithDeleted bool
}

func (*FindAll) Cache added in v1.1.6

func (s *FindAll) Cache(isCache bool) *FindAll

func (*FindAll) Exec

func (s *FindAll) Exec(ctx context.Context, opts *ExecOptions) (r *BaseResponse, err error)

func (*FindAll) Join

func (s *FindAll) Join(query string, args ...interface{}) *FindAll

func (*FindAll) Relation

func (s *FindAll) Relation(relation ...string) *FindAll

func (*FindAll) WithLimit added in v1.1.6

func (s *FindAll) WithLimit(limit int) *FindAll

func (*FindAll) WithOffset added in v1.1.6

func (s *FindAll) WithOffset(offset int) *FindAll

func (*FindAll) WithOrderBy added in v1.1.6

func (s *FindAll) WithOrderBy(orderBy string) *FindAll

func (*FindAll) WithSelects added in v1.1.6

func (s *FindAll) WithSelects(columns ...string) *FindAll

func (*FindAll) WithWhere added in v1.1.6

func (s *FindAll) WithWhere(query string, args ...interface{}) *FindAll

func (*FindAll) WithWhereAllWithDeleted added in v1.1.6

func (s *FindAll) WithWhereAllWithDeleted() *FindAll

type FindByPK

type FindByPK struct {
	Table               string
	DisableCache        bool
	Selects             []string
	Data                interface{}
	WhereAllWithDeleted bool
}

func (*FindByPK) Cache added in v1.1.6

func (s *FindByPK) Cache(isCache bool) *FindByPK

func (*FindByPK) Exec

func (s *FindByPK) Exec(ctx context.Context, opts *ExecOptions) (r *BaseResponse, err error)

func (*FindByPK) WithData added in v1.1.6

func (s *FindByPK) WithData(data interface{}) *FindByPK

func (*FindByPK) WithSelects added in v1.1.6

func (s *FindByPK) WithSelects(columns ...string) *FindByPK

func (*FindByPK) WithWhereAllWithDeleted added in v1.1.6

func (s *FindByPK) WithWhereAllWithDeleted() *FindByPK

type FindOne

type FindOne struct {
	Table               string
	DisableCache        bool
	Selects             []string
	Where               []*QueryWithArgs
	Relations           []string
	Joins               []*Join
	Offset              int
	OrderBy             []string
	WhereAllWithDeleted bool
}

func (*FindOne) Cache added in v1.1.6

func (s *FindOne) Cache(isCache bool) *FindOne

func (*FindOne) Exec

func (s *FindOne) Exec(ctx context.Context, opts *ExecOptions) (r *BaseResponse, err error)

func (*FindOne) Join

func (s *FindOne) Join(query string, args ...interface{}) *FindOne

func (*FindOne) Relation

func (s *FindOne) Relation(relation ...string) *FindOne

func (*FindOne) WithOffset added in v1.1.6

func (s *FindOne) WithOffset(offset int) *FindOne

func (*FindOne) WithOrderBy added in v1.1.6

func (s *FindOne) WithOrderBy(orderBy string) *FindOne

func (*FindOne) WithSelects added in v1.1.6

func (s *FindOne) WithSelects(columns ...string) *FindOne

func (*FindOne) WithWhere added in v1.1.6

func (s *FindOne) WithWhere(query string, args ...interface{}) *FindOne

func (*FindOne) WithWhereAllWithDeleted added in v1.1.6

func (s *FindOne) WithWhereAllWithDeleted() *FindOne

type Join

type Join struct {
	Join string
	Args []interface{}
}

type Operation

type Operation struct {
	Name string
	Data interface{}
}

type QueryWithArgs

type QueryWithArgs struct {
	Query string
	Args  []interface{}
}

type Redis

type Redis struct {
	Host     string
	Port     int
	Username string
	Password string
	DB       int
	PoolSize int
}

type RelationColumn

type RelationColumn struct {
	Name     string
	RefTable string
	Type     constant.RelationType
	Join     string
}

type TLS

type TLS struct {
	CertPEM       string
	PrivateKeyPEM string
	RootCAPEM     string
}

type TableConfig

type TableConfig struct {
	Name            string
	Columns         []*Column
	RelationColumns []*RelationColumn
}

type UpdateAll

type UpdateAll struct {
	// Lock key for concurrent insert operations
	// The later task with the same lock key in the same time will not execute and get the result from the first task
	LockKey             string
	Table               string
	Where               []*QueryWithArgs
	Set                 []*QueryWithArgs
	WhereAllWithDeleted bool
	DisableCache        bool
}

func (*UpdateAll) Cache added in v1.1.6

func (s *UpdateAll) Cache(isCache bool) *UpdateAll

func (*UpdateAll) Exec

func (s *UpdateAll) Exec(ctx context.Context, opts *ExecOptions) (r *BaseResponse, err error)

func (*UpdateAll) ToOperation

func (s *UpdateAll) ToOperation() *Operation

func (*UpdateAll) WithLockKey

func (s *UpdateAll) WithLockKey(lockKey string) *UpdateAll

func (*UpdateAll) WithSet added in v1.1.6

func (s *UpdateAll) WithSet(query string, args ...interface{}) *UpdateAll

func (*UpdateAll) WithWhere added in v1.1.6

func (s *UpdateAll) WithWhere(query string, args ...interface{}) *UpdateAll

func (*UpdateAll) WithWhereAllWithDeleted added in v1.1.6

func (s *UpdateAll) WithWhereAllWithDeleted() *UpdateAll

type UpdateByPK

type UpdateByPK struct {
	// Lock key for concurrent insert operations
	// The later task with the same lock key in the same time will not execute and get the result from the first task
	LockKey      string
	Table        string
	Data         interface{}
	Where        []*QueryWithArgs
	DisableCache bool
}

func (*UpdateByPK) Cache added in v1.1.6

func (s *UpdateByPK) Cache(isCache bool) *UpdateByPK

func (*UpdateByPK) Exec

func (s *UpdateByPK) Exec(ctx context.Context, opts *ExecOptions) (r *BaseResponse, err error)

func (*UpdateByPK) ToOperation

func (s *UpdateByPK) ToOperation() *Operation

func (*UpdateByPK) WithData added in v1.1.6

func (s *UpdateByPK) WithData(data interface{}) *UpdateByPK

func (*UpdateByPK) WithLockKey

func (s *UpdateByPK) WithLockKey(lockKey string) *UpdateByPK

func (*UpdateByPK) WithWhere added in v1.1.6

func (s *UpdateByPK) WithWhere(query string, args ...interface{}) *UpdateByPK

type UpsertConfig

type UpsertConfig struct {
	DBConfig     *DBConfig
	Redis        *Redis
	TableConfigs []*TableConfig
	Debug        bool
	DisableCache bool
}

func (*UpsertConfig) Exec

func (s *UpsertConfig) Exec(ctx context.Context, opts *ExecOptions) (r *BaseResponse, err error)

Exec finalize the configuration

type UpsertConfigOption

type UpsertConfigOption func(config *UpsertConfig)

UpsertConfigOption is a functional configuration option type

func Cache added in v1.1.6

func Cache(cache bool) UpsertConfigOption

Cache toggles cache functionality

func WithDBConfig

func WithDBConfig(dbConfig *DBConfig) UpsertConfigOption

WithDBConfig WithDB Database configuration methods

func WithDebug

func WithDebug(debug bool) UpsertConfigOption

WithDebug enables or disables debug mode

func WithRedis

func WithRedis(redis *Redis) UpsertConfigOption

WithRedis Redis configuration methods

func WithTable

func WithTable(tbl *TableConfig) UpsertConfigOption

WithTable adds a table configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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