package squirrel

import (
	
	
	
)
Prepareer is the interface that wraps the Prepare method. Prepare executes the given query as implemented by database/sql.Prepare.
type Preparer interface {
	Prepare(query string) (*sql.Stmt, error)
}
DBProxy groups the Execer, Queryer, QueryRower, and Preparer interfaces.
NOTE: NewStmtCache is defined in stmtcacher_ctx.go (Go >= 1.8) or stmtcacher_noctx.go (Go < 1.8).
StmtCache wraps and delegates down to a Preparer type It also automatically prepares all statements sent to the underlying Preparer calls for Exec, Query and QueryRow and caches the returns *sql.Stmt using the provided query as the key. So that it can be automatically re-used.
Prepare delegates down to the underlying Preparer and caches the result using the provided query as a key
func ( *StmtCache) ( string) (*sql.Stmt, error) {
	.mu.Lock()
	defer .mu.Unlock()

	,  := .cache[]
	if  {
		return , nil
	}
	,  := .prep.Prepare()
	if  == nil {
		.cache[] = 
	}
	return , 
}
Exec delegates down to the underlying Preparer using a prepared statement
func ( *StmtCache) ( string,  ...interface{}) ( sql.Result,  error) {
	,  := .Prepare()
	if  != nil {
		return
	}
	return .Exec(...)
}
Query delegates down to the underlying Preparer using a prepared statement
func ( *StmtCache) ( string,  ...interface{}) ( *sql.Rows,  error) {
	,  := .Prepare()
	if  != nil {
		return
	}
	return .Query(...)
}
QueryRow delegates down to the underlying Preparer using a prepared statement
func ( *StmtCache) ( string,  ...interface{}) RowScanner {
	,  := .Prepare()
	if  != nil {
		return &Row{err: }
	}
	return .QueryRow(...)
}
Clear removes and closes all the currently cached prepared statements
func ( *StmtCache) () ( error) {
	.mu.Lock()
	defer .mu.Unlock()

	for ,  := range .cache {
		delete(.cache, )

		if  == nil {
			continue
		}

		if  := .Close();  != nil {
			 = 
		}
	}

	if  != nil {
		return fmt.Errorf("one or more Stmt.Close failed; last error: %v", )
	}

	return
}

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

type stmtCacheProxy struct {
	DBProxy
	db *sql.DB
}

func ( *sql.DB) DBProxyBeginner {
	return &stmtCacheProxy{DBProxy: NewStmtCache(), db: }
}

func ( *stmtCacheProxy) () (*sql.Tx, error) {
	return .db.Begin()