clickhousebuilder

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RegCount      = regexp.MustCompile("(?is)^(SELECT).*?(FROM)")
	RegLimit      = regexp.MustCompile(`(?is)LIMIT\s+(\d+|\?)(?:\s*,\s*(\d+|\?))*\s*$`)
	RegOrderLimit = regexp.MustCompile(`(?is)(ORDER BY \S+(\s+(ASC|DESC))?\s+)?LIMIT\s+(\d+|\?)(?:\s*,\s*(\d+|\?))*\s*$`)
)

Functions

This section is empty.

Types

type Count

type Count struct {
	Count uint64 `ch:"count"`
}

type DBConnect

type DBConnect struct {
	clickhouse.Conn
	Options *clickhouse.Options
}

func New

func New(opts *clickhouse.Options) (*DBConnect, error)

New return a new clickhouse client, and try ping.

	conn, err := clickhousebuilder.New(&clickhouse.Options{
	Addr: []string{fmt.Sprintf("%s:%d", "localhost", 9000)},
	Auth: clickhouse.Auth{
		Database: "database",
		Username: "default",
		Password: "default",
	},
	DialTimeout:     time.Second,
	MaxOpenConns:    10,
	MaxIdleConns:    10 / 2,
	ConnMaxLifetime: time.Hour,
})

func (*DBConnect) AllowExperimentalObjectType

func (db *DBConnect) AllowExperimentalObjectType(enable bool) error

AllowExperimentalObjectType enable or disable object(json) type

func (*DBConnect) Select

func (db *DBConnect) Select(ctx context.Context, dest any, query string, args ...any) (count int64, err error)

Select 查询数据

func (*DBConnect) SelectAll

func (db *DBConnect) SelectAll(ctx context.Context, dest any, query string, args ...any) (count int64, err error)

SelectAll 返回所有数据,如果最后有 limit 会删除

func (*DBConnect) SelectMany

func (db *DBConnect) SelectMany(ctx context.Context, dest any, query string, args ...any) (count int64, err error)

SelectMany 查询总数并返回指定数据

func (*DBConnect) SelectOne

func (db *DBConnect) SelectOne(ctx context.Context, dest any, query string, args ...any) (err error)

SelectOne 查询单条数据,不是单条数据会报错

type MultiSelect

type MultiSelect func(ctx context.Context, dest any, query string, args ...any) (count int64, err error)

Jump to

Keyboard shortcuts

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