MCPcopy
hub / github.com/Masterminds/squirrel / Prepare

Method Prepare

stmtcacher.go:39–52  ·  view source on GitHub ↗

Prepare delegates down to the underlying Preparer and caches the result using the provided query as a key

(query string)

Source from the content-addressed store, hash-verified

37// Prepare delegates down to the underlying Preparer and caches the result
38// using the provided query as a key
39func (sc *StmtCache) Prepare(query string) (*sql.Stmt, error) {
40 sc.mu.Lock()
41 defer sc.mu.Unlock()
42
43 stmt, ok := sc.cache[query]
44 if ok {
45 return stmt, nil
46 }
47 stmt, err := sc.prep.Prepare(query)
48 if err == nil {
49 sc.cache[query] = stmt
50 }
51 return stmt, err
52}
53
54// Exec delegates down to the underlying Preparer using a prepared statement
55func (sc *StmtCache) Exec(query string, args ...interface{}) (res sql.Result, err error) {

Callers 4

ExecMethod · 0.95
QueryMethod · 0.95
QueryRowMethod · 0.95
TestStmtCachePrepareFunction · 0.95

Calls 1

PrepareMethod · 0.65

Tested by 1

TestStmtCachePrepareFunction · 0.76