Documentation ¶
Index ¶
- Variables
- func BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
- func DebugWriterFrom(ctx context.Context) io.Writer
- func GetLocation() *time.Location
- func HooksAreSkipped(ctx context.Context) bool
- func IsBoilErr(err error) bool
- func IsDebug(ctx context.Context) 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 WithDebug(ctx context.Context, debug bool) context.Context
- func WithDebugWriter(ctx context.Context, writer io.Writer) context.Context
- 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) IsNone() 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 DebugWriterFrom ¶
DebugWriterFrom returns the debug writer for the context, or DebugWriter if not set.
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 IsDebug ¶
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 ¶
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
func WithDebug ¶
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 ¶
WithDebugWriter modifies a context to configure the writer written to when debugging is enabled.
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.
None: insert: empty return: empty 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) IsNone ¶
IsNone checks to see if no 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.
None: empty 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.