chorm

package module
v0.0.0-...-c715ba0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

Golang Clickhouse ORM

A robust and efficient ORM (Object-Relational Mapping) for ClickhouseDB, written in Go.

Design Choices

  • As minimal reflection as possible. It looks very sweet to use go struct tags to define model without additional hussle, however that includes that for each insert/update/delete/select we need to deal with reflection which will slow down operations quite a lot.

Getting Started

Installation

Todo...

Benchmarks

Insert Benchmarking
go test -benchmem -run=^$ -bench ^BenchmarkNewInsert$ github.com/0x19/go-clickhouse-model -v

goos: linux
goarch: amd64
pkg: github.com/0x19/go-clickhouse-model
cpu: AMD Ryzen Threadripper 3960X 24-Core Processor 
BenchmarkNewInsert
BenchmarkNewInsert-48               1194            942314 ns/op            6493 B/op         61 allocs/op
PASS
ok      github.com/0x19/go-clickhouse-model     1.249s

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoConfigProvided   = errors.New("configuration must be provided")
	ErrNoHostProvided     = errors.New("host must be provided")
	ErrNoPortProvided     = errors.New("port must be provided")
	ErrNoUsernameProvided = errors.New("username must be provided")
	ErrNoPasswordProvided = errors.New("password must be provided")
	ErrNoDatabaseProvided = errors.New("database must be provided")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string `json:"host" yaml:"host" env:"GCHM_HOST"`
	Port     int    `json:"port" yaml:"port" env:"GCHM_PORT"`
	Username string `json:"username" yaml:"username" env:"GCHM_USERNAME"`
	Password string `json:"password" yaml:"password" env:"GCHM_PASSWORD"`
	Database string `json:"database" yaml:"database" env:"GCHM_DATABASE"`
	SSLMode  string `json:"ssl_mode" yaml:"ssl_mode" env:"GCHM_SSL_MODE"`
	Insecure bool   `json:"insecure" yaml:"insecure" env:"GCHM_INSECURE"`
}

func (*Config) GetDSN

func (c *Config) GetDSN() string

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration provided. TOOD: In the future, this should be replaced with a more robust validation

type DatabaseBuilder

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

func NewCreateDatabase

func NewCreateDatabase(ctx context.Context, orm *ORM, dbName string, useDb bool, queryOptions *chconn.QueryOptions) (*DatabaseBuilder, error)

func NewDropDatabase

func NewDropDatabase(ctx context.Context, orm *ORM, dbName string, queryOptions *chconn.QueryOptions) (*DatabaseBuilder, error)

func (*DatabaseBuilder) Build

func (b *DatabaseBuilder) Build() (string, error)

func (*DatabaseBuilder) ExecContext

func (b *DatabaseBuilder) ExecContext(ctx context.Context, queryOptions *chconn.QueryOptions) error

func (*DatabaseBuilder) SQL

func (b *DatabaseBuilder) SQL() string

type Field

type Field struct {
	Table      string
	PrimaryKey bool
	Name       string
	Default    string
	Type       string
	GoField    reflect.StructField
}

type InsertBuilder

type InsertBuilder[T models.Model] struct {
	// contains filtered or unexported fields
}

func NewInsert

func NewInsert[T models.Model](ctx context.Context, orm *ORM, model T, queryOptions *chconn.QueryOptions) (T, *InsertBuilder[T], error)

func (*InsertBuilder[T]) Build

func (b *InsertBuilder[T]) Build() (string, error)

func (*InsertBuilder[T]) ExecContext

func (b *InsertBuilder[T]) ExecContext(ctx context.Context, queryOptions *chconn.QueryOptions, columns ...column.ColumnBasic) error

func (*InsertBuilder[T]) SQL

func (b *InsertBuilder[T]) SQL() string

type ORM

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

func NewORM

func NewORM(ctx context.Context, cfg *Config) (*ORM, error)

func (*ORM) Close

func (o *ORM) Close()

func (*ORM) Connect

func (o *ORM) Connect() error

func (*ORM) CreateDatabase

func (o *ORM) CreateDatabase(ctx context.Context, dbName string, useDb bool, queryOptions *chconn.QueryOptions) (*DatabaseBuilder, error)

func (*ORM) DropDatabase

func (o *ORM) DropDatabase(ctx context.Context, dbName string, queryOptions *chconn.QueryOptions) (*DatabaseBuilder, error)

func (*ORM) GetConfig

func (o *ORM) GetConfig() *Config

func (*ORM) GetConn

func (o *ORM) GetConn() chpool.Pool

func (*ORM) GetContext

func (o *ORM) GetContext() context.Context

func (*ORM) GetDatabaseName

func (o *ORM) GetDatabaseName() string

func (*ORM) Insert

func (o *ORM) Insert(ctx context.Context, model models.Model, queryOptions *chconn.QueryOptions) (models.Model, *InsertBuilder[models.Model], error)

type TableBuilder

type TableBuilder[T models.Model] struct {
	// contains filtered or unexported fields
}

func NewCreateTable

func NewCreateTable[T models.Model](ctx context.Context, orm *ORM, model T, queryOptions *chconn.QueryOptions) (*TableBuilder[T], error)

func NewDropTable

func NewDropTable[T models.Model](ctx context.Context, orm *ORM, model T, queryOptions *chconn.QueryOptions) (*TableBuilder[T], error)

func (*TableBuilder[T]) Build

func (b *TableBuilder[T]) Build() (string, error)

func (*TableBuilder[T]) Exec

func (b *TableBuilder[T]) Exec(ctx context.Context) error

func (*TableBuilder[T]) ExecContext

func (b *TableBuilder[T]) ExecContext(ctx context.Context, queryOptions *chconn.QueryOptions, columns ...column.ColumnBasic) error

func (*TableBuilder[T]) GetBuilder

func (b *TableBuilder[T]) GetBuilder() *sql.TableBuilder

func (*TableBuilder[T]) SQL

func (b *TableBuilder[T]) SQL() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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