Prepare delegates down to the underlying Preparer and caches the result using the provided query as a key
(query string)
| 37 | // Prepare delegates down to the underlying Preparer and caches the result |
| 38 | // using the provided query as a key |
| 39 | func (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 |
| 55 | func (sc *StmtCache) Exec(query string, args ...interface{}) (res sql.Result, err error) { |