pool.go 420 B

123456789101112131415161718192021222324
  1. package db
  2. import (
  3. "sync"
  4. "github.com/jmoiron/sqlx"
  5. )
  6. // *sqlx.NamedStmt pool
  7. var namedStmtPool = sync.Pool{
  8. New: func() any {
  9. return &sqlx.NamedStmt{}
  10. },
  11. }
  12. // NewNamedStmt alloc *sqlx.NamedStmt from pool
  13. func NewNamedStmt() *sqlx.NamedStmt {
  14. return namedStmtPool.Get().(*sqlx.NamedStmt)
  15. }
  16. // PutNamedStmt release *sqlx.NamedStmt to pool
  17. func PutNamedStmt(stmt *sqlx.NamedStmt) {
  18. namedStmtPool.Put(stmt)
  19. }