aboutsummaryrefslogtreecommitdiffhomepage
path: root/database/database.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-08-01 20:28:45 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-08-01 20:28:45 -0700
commitcf03e0e33859b213f1d7e55b300a074eea107100 (patch)
tree3b88987c42c75b946c4e4b8eeb71fa2359bfe79d /database/database.go
parent17054b396eff571f49812074024cb9db2e098bdc (diff)
Create database package (refactoring)
Diffstat (limited to 'database/database.go')
-rw-r--r--database/database.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/database/database.go b/database/database.go
new file mode 100644
index 0000000..42f2292
--- /dev/null
+++ b/database/database.go
@@ -0,0 +1,25 @@
+// Copyright 2018 Frédéric Guillot. All rights reserved.
+// Use of this source code is governed by the Apache 2.0
+// license that can be found in the LICENSE file.
+
+package database
+
+import (
+ "database/sql"
+
+ // Postgresql driver import
+ _ "github.com/lib/pq"
+)
+
+// NewConnectionPool configures the database connection pool.
+func NewConnectionPool(dsn string, minConnections, maxConnections int) (*sql.DB, error) {
+ db, err := sql.Open("postgres", dsn)
+ if err != nil {
+ return nil, err
+ }
+
+ db.SetMaxOpenConns(maxConnections)
+ db.SetMaxIdleConns(minConnections)
+
+ return db, nil
+}