Documentation ¶
Overview ¶
Package sql provides tools and DAOs for speaking SQL as well as managing tables migrations
Index ¶
- Variables
- func CountStringFromExpression(tableName string, columnCount string, driver string, e Enquirer, ...) (string, []interface{}, error)
- func DeleteStringFromExpression(tableName string, driver string, ex goqu.Expression) (string, []interface{}, error)
- func ExecMax(db *sql.DB, dialect string, m migrate.MigrationSource, ...) (int, error)
- func ExecMigration(db *sql.DB, dialect string, m migrate.MigrationSource, ...) (int, error)
- func GetExpressionForString(neq bool, field interface{}, values ...string) (expression goqu.Expression)
- func GetQueryValueFor(field string, values ...string) string
- func GetSqlConnection(ctx context.Context, driver string, dsn string) (*sql.DB, error)
- func JoinWheresWithParenthesis(wheres []string, join string) string
- func LockMigratePackage()
- func NewDAO(ctx context.Context, driver string, dsn string, prefix string) (dao.DAO, error)
- func NewDAOQuery(enquirer Enquirer, converters ...service.Converter) fmt.Stringer
- func PlanMigration(db *sql.DB, dialect string, m migrate.MigrationSource, ...) ([]*migrate.PlannedMigration, *gorp.DbMap, error)
- func QueryStringFromExpression(tableName string, driver string, e Enquirer, ex goqu.Expression, ...) (string, []interface{}, error)
- func RetryTxOnDeadlock(ctx context.Context, db *sql.DB, opts *RetryTxOpts, ...) error
- func UnlockMigratePackage()
- type BatchReceiver
- type BatchSender
- type DAO
- type Enquirer
- type ExpressionConverter
- type Expressioner
- type FSMigrationSource
- type Handler
- func (h *Handler) As(i interface{}) bool
- func (h *Handler) Concat(s ...string) string
- func (h *Handler) DB() *sql.DB
- func (h *Handler) GetStmt(key string, args ...interface{}) (Stmt, error)
- func (h *Handler) GetStmtWithArgs(key string, params ...interface{}) (Stmt, []interface{}, error)
- func (h *Handler) Hash(s ...string) string
- func (h *Handler) HashParent(name string, mpath ...string) string
- func (h *Handler) Init(ctx context.Context, c configx.Values) error
- func (h *Handler) Lock()
- func (h *Handler) Prepare(key string, query interface{}) error
- func (h *Handler) Stats() map[string]interface{}
- func (h *Handler) Unlock()
- func (h *Handler) UseExclusion()
- func (h *Handler) Version() (string, error)
- func (h *Handler) WatchStatus() (registry.StatusWatcher, error)
- type Helper
- type RetryTxOpts
- type Scanner
- type Stmt
Constants ¶
This section is empty.
Variables ¶
var ( ConnectionOpenTimeout = 60 * time.Second ConnectionOpenRetries = 10 * time.Second )
Functions ¶
func CountStringFromExpression ¶
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 ¶
func DeleteStringFromExpression(tableName string, driver string, ex goqu.Expression) (string, []interface{}, error)
DeleteStringFromExpression creates sql for DELETE FROM expression
func ExecMax ¶
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 ¶
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 ¶
func GetExpressionForString(neq bool, field interface{}, values ...string) (expression goqu.Expression)
GetExpressionForString creates correct goqu.Expression for field + string value
func GetQueryValueFor ¶
GetQueryValueFor field value
func GetSqlConnection ¶ added in v4.0.1
func JoinWheresWithParenthesis ¶
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 ¶
NewDAOQuery adds database functionality to a Query proto message
func PlanMigration ¶
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 ¶
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 RetryTxOnDeadlock ¶ added in v4.2.6
func RetryTxOnDeadlock(ctx context.Context, db *sql.DB, opts *RetryTxOpts, f func(context.Context, *sql.Tx) error) error
RetryTxOnDeadlock creates a transaction and automatically retries it *if error is '1213: Deadlock found'*
func UnlockMigratePackage ¶
func UnlockMigratePackage()
UnlockMigratePackage frees the global lock on rubenv/migrate package
Types ¶
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
type Enquirer ¶
type Enquirer interface { GetSubQueries() []*anypb.Any GetOperation() service.OperationType GetOffset() int64 GetLimit() int64 GetGroupBy() int32 GetResourcePolicyQuery() *service.ResourcePolicyQuery fmt.Stringer }
Enquirer interface
type ExpressionConverter ¶
type ExpressionConverter interface {
Convert(sub *anypb.Any, driver string) (goqu.Expression, bool)
}
ExpressionConverter ...
type Expressioner ¶
type Expressioner interface {
Expression(driver string) goqu.Expression
}
Expressioner ...
func NewQueryBuilder ¶
func NewQueryBuilder(e Enquirer, c ...ExpressionConverter) Expressioner
NewQueryBuilder generates SQL request from object
type FSMigrationSource ¶
type FSMigrationSource struct { Box statics.FS // Path in the box to use. Dir string TablePrefix string }
FSMigrationSource is a set of migrations loaded from a packr box.
func (FSMigrationSource) FindMigrations ¶
func (p FSMigrationSource) FindMigrations() ([]*migrate.Migration, error)
type Handler ¶
Handler for the main functions of the DAO
func (*Handler) GetStmtWithArgs ¶
GetStmtWithArgs returns a list of all statements used by the dao
func (*Handler) UseExclusion ¶
func (h *Handler) UseExclusion()
func (*Handler) WatchStatus ¶ added in v4.0.1
func (h *Handler) WatchStatus() (registry.StatusWatcher, error)
type RetryTxOpts ¶ added in v4.0.5
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 }
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package index provides ready-to-use tables and DAOs for storing hierarchical data using the nested sets pattern
|
Package index provides ready-to-use tables and DAOs for storing hierarchical data using the nested sets pattern |
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 |