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

Method PrepareContext

stmtcacher_ctx.go:43–59  ·  view source on GitHub ↗

PrepareContext delegates down to the underlying PreparerContext and caches the result using the provided query as a key

(ctx context.Context, query string)

Source from the content-addressed store, hash-verified

41// PrepareContext delegates down to the underlying PreparerContext and caches the result
42// using the provided query as a key
43func (sc *StmtCache) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) {
44 ctxPrep, ok := sc.prep.(PreparerContext)
45 if !ok {
46 return nil, NoContextSupport
47 }
48 sc.mu.Lock()
49 defer sc.mu.Unlock()
50 stmt, ok := sc.cache[query]
51 if ok {
52 return stmt, nil
53 }
54 stmt, err := ctxPrep.PrepareContext(ctx, query)
55 if err == nil {
56 sc.cache[query] = stmt
57 }
58 return stmt, err
59}
60
61// ExecContext delegates down to the underlying PreparerContext using a prepared statement
62func (sc *StmtCache) ExecContext(ctx context.Context, query string, args ...interface{}) (res sql.Result, err error) {

Callers 4

ExecContextMethod · 0.95
QueryContextMethod · 0.95
QueryRowContextMethod · 0.95

Calls 1

PrepareContextMethod · 0.65

Tested by 1