sql

package
v3.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package sql provides tools and DAOs for speaking SQL as well as managing tables migrations

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultConnectionTimeout = 30 * time.Second
	LongConnectionTimeout    = 10 * time.Minute
	ErrNoRows                = sql.ErrNoRows
)

Functions

func CountStringFromExpression added in v1.0.1

func CountStringFromExpression(tableName string, columnCount string, driver string, e Enquirer, ex goqu.Expression, resourceExpression goqu.Expression) (string, []interface{}, error)

CountStringFromExpression finally builds a full SELECT count(*) from a Goqu Expression

func DeleteStringFromExpression added in v1.0.1

func DeleteStringFromExpression(tableName string, driver string, ex goqu.Expression) (string, []interface{}, error)

DeleteStringFromExpression creates sql for DELETE FROM expression

func ExecMax added in v1.0.1

func ExecMax(db *sql.DB, dialect string, m migrate.MigrationSource, dir migrate.MigrationDirection, max int, prefix string) (int, error)

ExecMax execute a set of migrations

Will apply at most `max` migrations. Pass 0 for no limit (or use Exec).

Returns the number of applied migrations.

func ExecMigration added in v1.0.1

func ExecMigration(db *sql.DB, dialect string, m migrate.MigrationSource, dir migrate.MigrationDirection, prefix string) (int, error)

ExecMigration Execute a set of migrations

Returns the number of applied migrations.

func GetExpressionForString added in v1.0.1

func GetExpressionForString(neq bool, field string, values ...string) (expression goqu.Expression)

GetExpressionForString creates correct goqu.Expression for field + string value

func GetQueryValueFor

func GetQueryValueFor(field string, values ...string) string

GetQueryValueFor field value

func JoinWheresWithParenthesis

func JoinWheresWithParenthesis(wheres []string, join string) string

JoinWheresWithParenthesis joins conditions using parenthesis if there are many, or no parenthesis if there is just one, and prepend the WHERE keyword to the string

func LockMigratePackage

func LockMigratePackage()

LockMigratePackage sets a global lock on rubenv/migrate package

func NewDAOQuery

func NewDAOQuery(enquirer Enquirer, converters ...common.Converter) fmt.Stringer

NewDAOQuery adds database functionality to a Query proto message

func PlanMigration added in v1.0.1

func PlanMigration(db *sql.DB, dialect string, m migrate.MigrationSource, dir migrate.MigrationDirection, max int, prefix string) ([]*migrate.PlannedMigration, *gorp.DbMap, error)

PlanMigration plans a migration.

func QueryStringFromExpression added in v1.0.1

func QueryStringFromExpression(tableName string, driver string, e Enquirer, ex goqu.Expression, resourceExpression goqu.Expression, limit int64) (string, []interface{}, error)

QueryStringFromExpression finally builds a full SELECT from a Goqu Expression

func UnlockMigratePackage

func UnlockMigratePackage()

UnlockMigratePackage frees the global lock on rubenv/migrate package

Types

type BatchReceiver

type BatchReceiver interface {
	Recv(interface{})
}

BatchReceiver interface

type BatchSender

type BatchSender interface {
	Send(interface{})
	Close() error
}

BatchSender interface

type DAO

type DAO interface {
	dao.DAO

	DB() *sql.DB
	Version() (string, error)
	Prepare(string, interface{}) error
	GetStmt(string, ...interface{}) (Stmt, error)
	GetStmtWithArgs(string, ...interface{}) (Stmt, []interface{}, error)
	UseExclusion()
	Lock()
	Unlock()

	// Helper functions for expressions that can differ from one dao to another
	Concat(...string) string
	Hash(...string) string
	HashParent(string, ...string) string
}

DAO interface definition

func NewDAO

func NewDAO(driver string, dsn string, prefix string) DAO

type Enquirer

type Enquirer interface {
	GetSubQueries() []*any.Any
	GetOperation() service.OperationType
	GetOffset() int64
	GetLimit() int64
	GetGroupBy() int32
	GetResourcePolicyQuery() *service.ResourcePolicyQuery

	fmt.Stringer
}

Enquirer interface

type ExpressionConverter added in v1.0.1

type ExpressionConverter interface {
	Convert(sub *any.Any, driver string) (goqu.Expression, bool)
}

ExpressionConverter ...

type Expressioner added in v1.0.1

type Expressioner interface {
	Expression(driver string) goqu.Expression
}

Expressioner ...

func NewQueryBuilder added in v1.0.1

func NewQueryBuilder(e Enquirer, c ...ExpressionConverter) Expressioner

NewQueryBuilder generates SQL request from object

type Handler

type Handler struct {
	dao.DAO
	// contains filtered or unexported fields
}

Handler for the main functions of the DAO

func (*Handler) Concat

func (h *Handler) Concat(s ...string) string

func (*Handler) DB

func (h *Handler) DB() *sql.DB

DB returns the sql DB object

func (*Handler) GetStmt

func (h *Handler) GetStmt(key string, args ...interface{}) (Stmt, error)

GetStmt returns a list of all statements used by the dao

func (*Handler) GetStmtWithArgs added in v1.5.0

func (h *Handler) GetStmtWithArgs(key string, params ...interface{}) (Stmt, []interface{}, error)

GetStmtWithArgs returns a list of all statements used by the dao

func (*Handler) Hash

func (h *Handler) Hash(s ...string) string

func (*Handler) HashParent

func (h *Handler) HashParent(name string, mpath ...string) string

func (*Handler) Init

func (h *Handler) Init(c configx.Values) error

func (*Handler) Lock

func (h *Handler) Lock()

func (*Handler) Prepare

func (h *Handler) Prepare(key string, query interface{}) error

Prepare the statements that can be used by the DAO

func (*Handler) Unlock

func (h *Handler) Unlock()

func (*Handler) UseExclusion

func (h *Handler) UseExclusion()

func (*Handler) Version

func (h *Handler) Version() (string, error)

Version returns mysql version

type Helper

type Helper interface {
	Concat(...string) string
	Hash(...string) string
	HashParent(string, ...string) string
}

type PackrBox

type PackrBox interface {
	List() []string
	Bytes(name string) []byte
}

PackrBox avoids pulling in the packr library for everyone, mimicks the bits of packr.Box that we need.

type PackrMigrationSource

type PackrMigrationSource struct {
	Box PackrBox

	// Path in the box to use.
	Dir string

	TablePrefix string
}

PackrMigrationSource is a set of migrations loaded from a packr box.

func (PackrMigrationSource) FindMigrations

func (p PackrMigrationSource) FindMigrations() ([]*migrate.Migration, error)

type Scanner

type Scanner interface {
	Scan(...interface{}) error
}

type Stmt

type Stmt interface {
	Close() error
	GetSQLStmt() *sql.Stmt
	Exec(...interface{}) (sql.Result, error)
	ExecContext(context.Context, ...interface{}) (sql.Result, error)
	Query(...interface{}) (*sql.Rows, error)
	LongQuery(...interface{}) (*sql.Rows, context.CancelFunc, error)
	QueryContext(context.Context, ...interface{}) (*sql.Rows, error)
	QueryRow(...interface{}) *sql.Row
	QueryRowContext(context.Context, ...interface{}) *sql.Row
}

Directories

Path Synopsis
Package index provides ready-to-use tables and DAOs for storing hierarchical data using the nested sets pattern * Copyright (c) 2019-2021.
Package index provides ready-to-use tables and DAOs for storing hierarchical data using the nested sets pattern * Copyright (c) 2019-2021.
Package resources provides ready-to-use SQL schemes and DAOs for attaching resource policies to any data
Package resources provides ready-to-use SQL schemes and DAOs for attaching resource policies to any data

Jump to

Keyboard shortcuts

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