Documentation ¶
Index ¶
- Variables
- func BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
- func GetLocation() *time.Location
- func HooksAreSkipped(ctx context.Context) bool
- func IsBoilErr(err error) bool
- func SetDB(db Executor)
- func SetLocation(loc *time.Location)
- func SkipHooks(ctx context.Context) context.Context
- func SkipTimestamps(ctx context.Context) context.Context
- func TimestampsAreSkipped(ctx context.Context) bool
- func WrapErr(err error) error
- type Beginner
- type Columns
- func (c Columns) InsertColumnSet(cols, defaults, noDefaults, nonZeroDefaults []string) ([]string, []string)
- func (c Columns) IsBlacklist() bool
- func (c Columns) IsGreylist() bool
- func (c Columns) IsInfer() bool
- func (c Columns) IsWhitelist() bool
- func (c Columns) UpdateColumnSet(allColumns, pkeyCols []string) []string
- type ContextBeginner
- type ContextExecutor
- type ContextTransactor
- type Executor
- type HookPoint
- type Transactor
Constants ¶
This section is empty.
Variables ¶
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
var DebugWriter io.Writer = os.Stdout
DebugWriter is where the debug output will be sent if DebugMode is true
Functions ¶
func GetLocation ¶
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 ¶
HooksAreSkipped returns true if the context skips hooks
func SetDB ¶
func SetDB(db Executor)
SetDB initializes the database handle for all template db interactions
func SetLocation ¶
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 ¶
SkipHooks modifies a context to prevent hooks from running for any query it encounters.
func SkipTimestamps ¶
SkipTimestamps modifies a context to prevent hooks from running for any query it encounters.
func TimestampsAreSkipped ¶
TimestampsAreSkipped returns true if the context skips hooks
Types ¶
type Columns ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
type Transactor ¶
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.