db

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const DriverMysql = "mysql"
View Source
const DriverNameCrateDb = "cratedb"
View Source
const DriverNameRedshift = "redshift"
View Source
const (
	FormatDateTime = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func IsDuplicateEntryError

func IsDuplicateEntryError(err error) bool

func NewConnectionFromSettings

func NewConnectionFromSettings(logger log.Logger, settings Settings) (*sqlx.DB, error)

func NewConnectionWithInterfaces

func NewConnectionWithInterfaces(settings Settings) (*sqlx.DB, error)

func NewCrateDbDriverFactory

func NewCrateDbDriverFactory() *crateDbDriverFactory

func ProvideConnection

func ProvideConnection(config cfg.Config, logger log.Logger, configKey string) (*sqlx.DB, error)

Types

type Client

type Client interface {
	GetSingleScalarValue(ctx context.Context, query string, args ...interface{}) (int, error)
	GetResult(ctx context.Context, query string, args ...interface{}) (*Result, error)
	Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	Prepare(ctx context.Context, query string) (*sql.Stmt, error)
	Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	Queryx(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
	QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
	Select(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	Get(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	WithTx(ctx context.Context, ops *sql.TxOptions, do func(ctx context.Context, tx *sql.Tx) error) error
}

func NewClient

func NewClient(config cfg.Config, logger log.Logger, name string) (Client, error)

func NewClientWithInterfaces

func NewClientWithInterfaces(logger log.Logger, db *sqlx.DB) Client

func NewClientWithSettings

func NewClientWithSettings(logger log.Logger, settings Settings) (Client, error)

type ClientSqlx

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

func (*ClientSqlx) BeginTx

func (c *ClientSqlx) BeginTx(ctx context.Context, ops *sql.TxOptions) (*sql.Tx, error)

func (*ClientSqlx) Exec

func (c *ClientSqlx) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*ClientSqlx) Get

func (c *ClientSqlx) Get(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*ClientSqlx) GetResult

func (c *ClientSqlx) GetResult(ctx context.Context, query string, args ...interface{}) (*Result, error)

func (*ClientSqlx) GetSingleScalarValue

func (c *ClientSqlx) GetSingleScalarValue(ctx context.Context, query string, args ...interface{}) (int, error)

func (*ClientSqlx) Prepare

func (c *ClientSqlx) Prepare(ctx context.Context, query string) (*sql.Stmt, error)

func (*ClientSqlx) Query

func (c *ClientSqlx) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (*ClientSqlx) QueryRow

func (c *ClientSqlx) QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row

func (*ClientSqlx) Queryx

func (c *ClientSqlx) Queryx(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)

func (*ClientSqlx) Select

func (c *ClientSqlx) Select(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*ClientSqlx) WithTx

func (c *ClientSqlx) WithTx(ctx context.Context, ops *sql.TxOptions, do func(ctx context.Context, tx *sql.Tx) error) (err error)

type DriverFactory

type DriverFactory interface {
	GetDSN(settings Settings) string
	GetMigrationDriver(db *sql.DB, database string, migrationsTable string) (database.Driver, error)
}

func GetDriverFactory

func GetDriverFactory(driverName string) (DriverFactory, error)

func NewMysqlDriverFactory

func NewMysqlDriverFactory() DriverFactory

func NewRedshiftDriverFactory

func NewRedshiftDriverFactory() DriverFactory

type DuplicateEntryError

type DuplicateEntryError struct {
	Err error
}

func (*DuplicateEntryError) As

func (e *DuplicateEntryError) As(target interface{}) bool

func (*DuplicateEntryError) Error

func (e *DuplicateEntryError) Error() string

func (*DuplicateEntryError) Is

func (e *DuplicateEntryError) Is(err error) bool

func (*DuplicateEntryError) Unwrap

func (e *DuplicateEntryError) Unwrap() error

type MigrationSettings

type MigrationSettings struct {
	Application    string `cfg:"application" default:"{app_name}"`
	Path           string `cfg:"path"`
	PrefixedTables bool   `cfg:"prefixed_tables" default:"false"`
	Enabled        bool   `cfg:"enabled" default:"false"`
}

type QueryBuilder

type QueryBuilder interface {
	Table(table string) QueryBuilder
	Joins(joins []string) QueryBuilder
	Where(query interface{}, args ...interface{}) QueryBuilder
	GroupBy(field ...string) QueryBuilder
	OrderBy(field string, direction string) QueryBuilder
	Page(offset int, size int) QueryBuilder
}

type RawQueryBuilder

type RawQueryBuilder struct {
	Builder squirrel.SelectBuilder
}

func NewQueryBuilder

func NewQueryBuilder() *RawQueryBuilder

func (*RawQueryBuilder) GroupBy

func (b *RawQueryBuilder) GroupBy(field ...string) QueryBuilder

func (*RawQueryBuilder) Joins

func (b *RawQueryBuilder) Joins(joins []string) QueryBuilder

func (*RawQueryBuilder) OrderBy

func (b *RawQueryBuilder) OrderBy(field string, direction string) QueryBuilder

func (*RawQueryBuilder) Page

func (b *RawQueryBuilder) Page(offset int, size int) QueryBuilder

func (*RawQueryBuilder) Table

func (b *RawQueryBuilder) Table(table string) QueryBuilder

func (*RawQueryBuilder) Where

func (b *RawQueryBuilder) Where(query interface{}, args ...interface{}) QueryBuilder

type Result

type Result []ResultRow

type ResultRow

type ResultRow map[string]string

type Settings

type Settings struct {
	ConnectionMaxLifetime time.Duration `cfg:"connection_max_lifetime" default:"120s"`
	Driver                string        `cfg:"driver"`
	MaxIdleConnections    int           `cfg:"max_idle_connections" default:"2"` // 0 or negative number=no idle connections, sql driver default=2
	MaxOpenConnections    int           `cfg:"max_open_connections" default:"0"` // 0 or negative number=unlimited, sql driver default=0
	ParseTime             bool          `cfg:"parse_time" default:"true"`

	Uri        Uri               `cfg:"uri"`
	Migrations MigrationSettings `cfg:"migrations"`
}

type SqlResult

type SqlResult interface {
	LastInsertId() (int64, error)
	RowsAffected() (int64, error)
}

type Uri

type Uri struct {
	Host     string `cfg:"host" validation:"required"`
	Port     int    `cfg:"port" validation:"required"`
	User     string `cfg:"user" validation:"required"`
	Password string `cfg:"password" validation:"required"`
	Database string `cfg:"database" validation:"required"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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