MCPcopy
hub / github.com/go-gorm/gorm / prepare

Method prepare

prepare_stmt.go:66–86  ·  view source on GitHub ↗
(ctx context.Context, conn ConnPool, isTransaction bool, query string)

Source from the content-addressed store, hash-verified

64}
65
66func (db *PreparedStmtDB) prepare(ctx context.Context, conn ConnPool, isTransaction bool, query string) (_ *stmt_store.Stmt, err error) {
67 db.Mux.RLock()
68 if db.Stmts != nil {
69 if stmt, ok := db.Stmts.Get(query); ok && (!stmt.Transaction || isTransaction) {
70 db.Mux.RUnlock()
71 return stmt, stmt.Error()
72 }
73 }
74 db.Mux.RUnlock()
75
76 // retry
77 db.Mux.Lock()
78 if db.Stmts != nil {
79 if stmt, ok := db.Stmts.Get(query); ok && (!stmt.Transaction || isTransaction) {
80 db.Mux.Unlock()
81 return stmt, stmt.Error()
82 }
83 }
84
85 return db.Stmts.New(ctx, query, isTransaction, conn, db.Mux)
86}
87
88func (db *PreparedStmtDB) BeginTx(ctx context.Context, opt *sql.TxOptions) (ConnPool, error) {
89 if beginner, ok := db.ConnPool.(TxBeginner); ok {

Callers 6

ExecContextMethod · 0.95
QueryContextMethod · 0.95
QueryRowContextMethod · 0.95
ExecContextMethod · 0.80
QueryContextMethod · 0.80
QueryRowContextMethod · 0.80

Calls 3

GetMethod · 0.65
ErrorMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected