boil

package
v3.7.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DebugMode = false

DebugMode is a flag controlling whether generated sql statements and debug information is outputted to the DebugWriter handle

NOTE: This should be disabled in production to avoid leaking sensitive data

View Source
var DebugWriter io.Writer = os.Stdout

DebugWriter is where the debug output will be sent if DebugMode is true

Functions

func BeginTx

func BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx begins a transaction with the current global database handle.

func DebugWriterFrom

func DebugWriterFrom(ctx context.Context) io.Writer

DebugWriterFrom returns the debug writer for the context, or DebugWriter if not set.

func GetLocation

func GetLocation() *time.Location

GetLocation retrieves the global timestamp Location. This is the timezone used by the generated package for the automated setting of created_at and updated_at columns if the package was not generated with the --no-auto-timestamps flag.

func HooksAreSkipped

func HooksAreSkipped(ctx context.Context) bool

HooksAreSkipped returns true if the context skips hooks

func IsBoilErr

func IsBoilErr(err error) bool

IsBoilErr checks if err is a boilErr

func IsDebug

func IsDebug(ctx context.Context) bool

IsDebug returns true if the context has debugging enabled, or the value of DebugMode if not set.

func SetDB

func SetDB(db Executor)

SetDB initializes the database handle for all template db interactions

func SetLocation

func SetLocation(loc *time.Location)

SetLocation sets the global timestamp Location. This is the timezone used by the generated package for the automated setting of created_at and updated_at columns. If the package was generated with the --no-auto-timestamps flag then this function has no effect.

func SkipHooks

func SkipHooks(ctx context.Context) context.Context

SkipHooks modifies a context to prevent hooks from running for any query it encounters.

func SkipTimestamps

func SkipTimestamps(ctx context.Context) context.Context

SkipTimestamps modifies a context to prevent hooks from running for any query it encounters.

func TimestampsAreSkipped

func TimestampsAreSkipped(ctx context.Context) bool

TimestampsAreSkipped returns true if the context skips hooks

func WithDebug

func WithDebug(ctx context.Context, debug bool) context.Context

WithDebug modifies a context to configure debug writing. If true, all queries made using this context will be outputted to the io.Writer returned by DebugWriterFrom.

func WithDebugWriter

func WithDebugWriter(ctx context.Context, writer io.Writer) context.Context

WithDebugWriter modifies a context to configure the writer written to when debugging is enabled.

func WrapErr

func WrapErr(err error) error

WrapErr wraps err in a boilErr

Types

type Beginner

type Beginner interface {
	Begin() (*sql.Tx, error)
}

Beginner begins transactions.

type Columns

type Columns struct {
	Kind int
	Cols []string
}

Columns is a list of columns and a kind of list. Each kind interacts differently with non-zero and default column inference to produce a final list of columns for a given query. (Typically insert/updates).

func Blacklist

func Blacklist(columns ...string) Columns

Blacklist creates a list that overrides column inference choices by excluding a column from the inferred list. In essence, inference creates the list of columns, and blacklisted columns are removed from that list to produce the final list.

func Greylist

func Greylist(columns ...string) Columns

Greylist creates a list that adds to the inferred column choices. The final list is composed of both inferred columns and greylisted columns.

func Infer

func Infer() Columns

Infer is a placeholder that means there is no other list, simply infer the final list of columns for insert/update etc.

func Whitelist

func Whitelist(columns ...string) Columns

Whitelist creates a list that completely overrides column inference. It becomes the final list for the insert/update etc.

func (Columns) InsertColumnSet

func (c Columns) InsertColumnSet(cols, defaults, noDefaults, nonZeroDefaults []string) ([]string, []string)

InsertColumnSet generates the set of columns to insert and return for an insert statement. The return columns are used to get values that are assigned within the database during the insert to keep the struct in sync with what's in the db. The various interactions with the different types of Columns list are outlined below.

Note that a default column's zero value is based on the Go type and does not take into account the default value in the database.

Infer:
 insert: columns-without-default + non-zero-default-columns
 return: columns-with-defaults - insert

Whitelist:
 insert: whitelist
 return: columns-with-defaults - whitelist

Blacklist:
  insert: columns-without-default + non-zero-default-columns - blacklist
  return: columns-with-defaults - insert

Greylist:
  insert: columns-without-default + non-zero-default-columns + greylist
  return: columns-with-defaults - insert

func (Columns) IsBlacklist

func (c Columns) IsBlacklist() bool

IsBlacklist checks to see if these columns should be inferred. This method is here simply to not have to export the columns types.

func (Columns) IsGreylist

func (c Columns) IsGreylist() bool

IsGreylist checks to see if these columns should be inferred. This method is here simply to not have to export the columns types.

func (Columns) IsInfer

func (c Columns) IsInfer() bool

IsInfer checks to see if these columns should be inferred. This method is here simply to not have to export the columns types.

func (Columns) IsWhitelist

func (c Columns) IsWhitelist() bool

IsWhitelist checks to see if these columns should be inferred. This method is here simply to not have to export the columns types.

func (Columns) UpdateColumnSet

func (c Columns) UpdateColumnSet(allColumns, pkeyCols []string) []string

UpdateColumnSet generates the set of columns to update for an update statement. The various interactions with the different types of Columns list are outlined below. In the case of greylist you can only add pkeys, which isn't useful in an update since then you can't find the original record you were trying to update.

Infer:     all - pkey-columns
whitelist: whitelist
blacklist: all - pkeys - blacklist
greylist:  all - pkeys + greylist

type ContextBeginner

type ContextBeginner interface {
	BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error)
}

ContextBeginner allows creation of context aware transactions with options.

type ContextExecutor

type ContextExecutor interface {
	Executor

	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
}

ContextExecutor can perform SQL queries with context

func GetContextDB

func GetContextDB() ContextExecutor

GetContextDB retrieves the global state database handle as a context executor

type ContextTransactor

type ContextTransactor interface {
	Commit() error
	Rollback() error

	ContextExecutor
}

ContextTransactor can commit and rollback, on top of being able to execute context-aware queries.

type Executor

type Executor interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

Executor can perform SQL queries.

func GetDB

func GetDB() Executor

GetDB retrieves the global state database handle

type HookPoint

type HookPoint int

HookPoint is the point in time at which we hook

const (
	BeforeInsertHook HookPoint = iota + 1
	BeforeUpdateHook
	BeforeDeleteHook
	BeforeUpsertHook
	AfterInsertHook
	AfterSelectHook
	AfterUpdateHook
	AfterDeleteHook
	AfterUpsertHook
)

the hook point constants

type Transactor

type Transactor interface {
	Commit() error
	Rollback() error

	Executor
}

Transactor can commit and rollback, on top of being able to execute queries.

func Begin

func Begin() (Transactor, error)

Begin a transaction with the current global database handle.

Jump to

Keyboard shortcuts

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