postgresql.go 714 B

12345678910111213141516171819202122232425262728293031
  1. //go:build !sqlite
  2. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  3. // SPDX-License-Identifier: Apache-2.0
  4. package database // import "miniflux.app/v2/internal/database"
  5. import (
  6. "database/sql"
  7. "time"
  8. _ "github.com/lib/pq"
  9. )
  10. // NewConnectionPool configures the database connection pool.
  11. func NewConnectionPool(dsn string, minConnections, maxConnections int, connectionLifetime time.Duration) (*sql.DB, error) {
  12. db, err := sql.Open("postgres", dsn)
  13. if err != nil {
  14. return nil, err
  15. }
  16. db.SetMaxOpenConns(maxConnections)
  17. db.SetMaxIdleConns(minConnections)
  18. db.SetConnMaxLifetime(connectionLifetime)
  19. return db, nil
  20. }
  21. func getDriverStr() string {
  22. return "postgresql"
  23. }