Skip to content

Commit

Permalink
nullExecer singleton instead of allocating panicExecer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario L Gutierrez committed Jun 19, 2015
1 parent 7a19689 commit fdd52cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 9 additions & 9 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,62 +17,62 @@ type Builder interface {
// Call creates a new CallBuilder for the given sproc and args.
func Call(sproc string, args ...interface{}) *CallBuilder {
b := NewCallBuilder(sproc, args...)
b.Execer = &panicExecer{}
b.Execer = nullExecer
return b
}

// DeleteFrom creates a new DeleteBuilder for the given table.
func DeleteFrom(table string) *DeleteBuilder {
b := NewDeleteBuilder(table)
b.Execer = &panicExecer{}
b.Execer = nullExecer
return b
}

// InsertInto creates a new InsertBuilder for the given table.
func InsertInto(table string) *InsertBuilder {
b := NewInsertBuilder(table)
b.Execer = &panicExecer{}
b.Execer = nullExecer
return b
}

// Insect inserts into a table if does not exist.
func Insect(table string) *InsectBuilder {
b := NewInsectBuilder(table)
b.Execer = &panicExecer{}
b.Execer = nullExecer
return b
}

// Select creates a new SelectBuilder for the given columns.
func Select(columns ...string) *SelectBuilder {
b := NewSelectBuilder(columns...)
b.Execer = &panicExecer{}
b.Execer = nullExecer
return b
}

// SelectDoc creates a new SelectDocBuilder for the given columns.
func SelectDoc(columns ...string) *SelectDocBuilder {
b := NewSelectDocBuilder(columns...)
b.Execer = &panicExecer{}
b.Execer = nullExecer
return b
}

// SQL creates a new raw SQL builder.
func SQL(sql string, args ...interface{}) *RawBuilder {
b := NewRawBuilder(sql, args...)
b.Execer = &panicExecer{}
b.Execer = nullExecer
return b
}

// Update creates a new UpdateBuilder for the given table.
func Update(table string) *UpdateBuilder {
b := NewUpdateBuilder(table)
b.Execer = &panicExecer{}
b.Execer = nullExecer
return b
}

// Upsert insert (if it does not exist) or updates a row.
func Upsert(table string) *UpsertBuilder {
b := NewUpsertBuilder(table)
b.Execer = &panicExecer{}
b.Execer = nullExecer
return b
}
2 changes: 2 additions & 0 deletions execer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Execer interface {

const panicExecerMsg = "dat builders are disconnected, use sqlx-runner package"

var nullExecer = &panicExecer{}

// panicExecer is the execer for instances of dat builders from
// data package.
type panicExecer struct{}
Expand Down

0 comments on commit fdd52cd

Please sign in to comment.