boil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2016 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JoinInner joinKind = iota
	JoinOuterLeft
	JoinOuterRight
	JoinNatural
)

Join type constants

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 = os.Stdout

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

Functions

func AppendFrom

func AppendFrom(q *Query, from ...string)

AppendFrom on the query.

func AppendGroupBy

func AppendGroupBy(q *Query, clause string)

AppendGroupBy on the query.

func AppendHaving

func AppendHaving(q *Query, clause string, args ...interface{})

AppendHaving on the query.

func AppendIn

func AppendIn(q *Query, clause string, args ...interface{})

AppendIn on the query.

func AppendInnerJoin

func AppendInnerJoin(q *Query, clause string, args ...interface{})

AppendInnerJoin on the query.

func AppendOrderBy

func AppendOrderBy(q *Query, clause string)

AppendOrderBy on the query.

func AppendSelect

func AppendSelect(q *Query, columns ...string)

AppendSelect on the query.

func AppendWhere

func AppendWhere(q *Query, clause string, args ...interface{})

AppendWhere on the query.

func Bind

func Bind(rows *sql.Rows, obj interface{}) error

Bind executes the query and inserts the result into the passed in object pointer

Bind rules:

  • Struct tags control bind, in the form of: `boil:"name,bind"`
  • If "name" is omitted the sql column names that come back are TitleCased and matched against the field name.
  • If the "name" part of the struct tag is specified, the given name will be used instead of the struct field name for binding.
  • If the "name" of the struct tag is "-", this field will not be bound to.
  • If the ",bind" option is specified on a struct field and that field is a struct itself, it will be recursed into to look for fields for binding.

Example Query:

type JoinStruct struct {
  // User1 can have it's struct fields bound to since it specifies
  // ,bind in the struct tag, it will look specifically for
  // fields that are prefixed with "user." returning from the query.
  // For example "user.id" column name will bind to User1.ID
  User1      *models.User `boil:"user,bind"`
  // User2 will follow the same rules as noted above except it will use
  // "friend." as the prefix it's looking for.
  User2      *models.User `boil:"friend,bind"`
  // RandomData will not be recursed into to look for fields to
  // bind and will not be bound to because of the - for the name.
  RandomData myStruct     `boil:"-"`
  // Date will not be recursed into to look for fields to bind because
  // it does not specify ,bind in the struct tag. But it can be bound to
  // as it does not specify a - for the name.
  Date       time.Time
}

models.Users(qm.InnerJoin("users as friend on users.friend_id = friend.id")).Bind(&joinStruct)

For custom objects that want to use eager loading, please see the loadRelationships function.

func BindMapping

func BindMapping(typ reflect.Type, mapping map[string]uint64, cols []string) ([]uint64, error)

BindMapping creates a mapping that helps look up the pointer for the column given.

func BuildUpsertQuery

func BuildUpsertQuery(tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string

BuildUpsertQuery builds a SQL statement string using the upsertData provided.

func ExecQuery

func ExecQuery(q *Query) (sql.Result, error)

ExecQuery executes a query that does not need a row returned

func ExecQueryAll

func ExecQueryAll(q *Query) (*sql.Rows, error)

ExecQueryAll executes the query for the All finisher and returns multiple rows

func ExecQueryOne

func ExecQueryOne(q *Query) *sql.Row

ExecQueryOne executes the query for the One finisher and returns a row

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 GetSliceValues

func GetSliceValues(slice []interface{}, columns ...string) []interface{}

GetSliceValues returns the values (as interface) of the matching columns in obj.

func GetStructPointers

func GetStructPointers(obj interface{}, columns ...string) []interface{}

GetStructPointers returns a slice of pointers to the matching columns in obj

func GetStructValues

func GetStructValues(obj interface{}, columns ...string) []interface{}

GetStructValues returns the values (as interface) of the matching columns in obj

func IsBoilErr

func IsBoilErr(err error) bool

IsBoilErr checks if err is a boilErr

func MakeStructMapping

func MakeStructMapping(typ reflect.Type) map[string]uint64

MakeStructMapping creates a map of the struct to be able to quickly look up its pointers and values by name.

func NonZeroDefaultSet

func NonZeroDefaultSet(defaults []string, obj interface{}) []string

NonZeroDefaultSet returns the fields included in the defaults slice that are non zero values

func PtrsFromMapping

func PtrsFromMapping(val reflect.Value, mapping []uint64) []interface{}

PtrsFromMapping expects to be passed an addressable struct and a mapping of where to find things. It pulls the pointers out referred to by the mapping.

func SetCount

func SetCount(q *Query)

SetCount on the query.

func SetDB

func SetDB(db Executor)

SetDB initializes the database handle for all template db interactions

func SetDelete

func SetDelete(q *Query)

SetDelete on the query.

func SetExecutor

func SetExecutor(q *Query, exec Executor)

SetExecutor on the query.

func SetFor

func SetFor(q *Query, clause string)

SetFor on the query.

func SetFrom

func SetFrom(q *Query, from ...string)

SetFrom replaces the current from statements.

func SetLastInAsOr

func SetLastInAsOr(q *Query)

SetLastInAsOr sets the or separator for the tail "IN" in the slice

func SetLastWhereAsOr

func SetLastWhereAsOr(q *Query)

SetLastWhereAsOr sets the or separator for the tail "WHERE" in the slice

func SetLimit

func SetLimit(q *Query, limit int)

SetLimit on the query.

func SetLoad

func SetLoad(q *Query, relationships ...string)

SetLoad on the query.

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 SetOffset

func SetOffset(q *Query, offset int)

SetOffset on the query.

func SetSQL

func SetSQL(q *Query, sql string, args ...interface{})

SetSQL on the query.

func SetUpdate

func SetUpdate(q *Query, cols map[string]interface{})

SetUpdate on the query.

func ValuesFromMapping

func ValuesFromMapping(val reflect.Value, mapping []uint64) []interface{}

ValuesFromMapping expects to be passed an addressable struct and a mapping of where to find things. It pulls the pointers out referred to by the mapping.

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 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

func GetExecutor

func GetExecutor(q *Query) Executor

GetExecutor on the query.

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 Query

type Query struct {
	// contains filtered or unexported fields
}

Query holds the state for the built up query

func SQL

func SQL(exec Executor, query string, args ...interface{}) *Query

SQL makes a plainSQL query, usually for use with bind

func SQLG

func SQLG(query string, args ...interface{}) *Query

SQLG makes a plainSQL query using the global Executor, usually for use with bind

func (*Query) Bind

func (q *Query) Bind(obj interface{}) error

Bind executes the query and inserts the result into the passed in object pointer

See documentation for boil.Bind()

func (*Query) BindP

func (q *Query) BindP(obj interface{})

BindP executes the query and inserts the result into the passed in object pointer. It panics on error. See boil.Bind() documentation.

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

Directories

Path Synopsis
Package randomize has helpers for randomization of structs and fields
Package randomize has helpers for randomization of structs and fields

Jump to

Keyboard shortcuts

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