Browse Source

Copy/Paste connection methods

Volodymyr Tkach 2 years ago
parent
commit
d25b444270
2 changed files with 15 additions and 0 deletions
  1. 3 0
      gosql/common/common.go
  2. 12 0
      gosql/common/dbmethods.go

+ 3 - 0
gosql/common/common.go

@@ -26,6 +26,9 @@ type Engine interface {
 	Prepare(ctx context.Context, query string) (*sql.Stmt, error)
 	Prepare(ctx context.Context, query string) (*sql.Stmt, error)
 	Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
 	Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
 	QueryRow(ctx context.Context, query string, args ...any) *sql.Row
 	QueryRow(ctx context.Context, query string, args ...any) *sql.Row
+	SetConnMaxLifetime(d time.Duration)
+	SetMaxIdleConns(n int)
+	SetMaxOpenConns(n int)
 	Transaction(ctx context.Context, queries func(ctx context.Context, tx *Tx) error) error
 	Transaction(ctx context.Context, queries func(ctx context.Context, tx *Tx) error) error
 }
 }
 
 

+ 12 - 0
gosql/common/dbmethods.go

@@ -97,6 +97,18 @@ func (db *DBMethods) QueryRow(ctx context.Context, query string, args ...any) *s
 	return db.DB.QueryRowContext(ctx, db.fixQuery(query), args...)
 	return db.DB.QueryRowContext(ctx, db.fixQuery(query), args...)
 }
 }
 
 
+func (db *DBMethods) SetConnMaxLifetime(d time.Duration) {
+	db.DB.SetConnMaxLifetime(d)
+}
+
+func (db *DBMethods) SetMaxIdleConns(n int) {
+	db.DB.SetMaxIdleConns(n)
+}
+
+func (db *DBMethods) SetMaxOpenConns(n int) {
+	db.DB.SetMaxOpenConns(n)
+}
+
 func (db *DBMethods) Transaction(ctx context.Context, queries func(ctx context.Context, tx *Tx) error) error {
 func (db *DBMethods) Transaction(ctx context.Context, queries func(ctx context.Context, tx *Tx) error) error {
 	if queries == nil {
 	if queries == nil {
 		return fmt.Errorf("queries is not set for transaction")
 		return fmt.Errorf("queries is not set for transaction")