Skip to content

Commit

Permalink
refactor(model): move to database dir
Browse files Browse the repository at this point in the history
added database connection pool config
  • Loading branch information
MrMissx committed Mar 3, 2024
1 parent 69cf011 commit 8b37fa1
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions database/database.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package database

import (
"time"

"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"github.com/mrmissx/stashbin/utils"
Expand All @@ -17,6 +19,10 @@ func ConnectDb() {
utils.Logger.Info("Connecting to database...")

db := sqlx.MustConnect("postgres", dbUri)
db.SetMaxIdleConns(5)
db.SetMaxOpenConns(10)
db.SetConnMaxIdleTime(10 * time.Minute)
db.SetConnMaxLifetime(1 * time.Hour)

session = db
utils.Logger.Info("Successfuly connected database")
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions handler/api/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/jmoiron/sqlx"
"github.com/labstack/echo/v4"
"github.com/mrmissx/stashbin/model"
"github.com/mrmissx/stashbin/response"
"github.com/mrmissx/stashbin/database/model"
"github.com/mrmissx/stashbin/utils/response"
)

func GetDocumentBySlug(c echo.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion handler/api/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"

"github.com/labstack/echo/v4"
"github.com/mrmissx/stashbin/response"
"github.com/mrmissx/stashbin/utils/response"
)

func HealthCheck(c echo.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion handler/page/about.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/labstack/echo/v4"

"github.com/mrmissx/stashbin/response"
"github.com/mrmissx/stashbin/utils/response"
"github.com/mrmissx/stashbin/view"
)

Expand Down
4 changes: 2 additions & 2 deletions handler/page/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/jmoiron/sqlx"
"github.com/labstack/echo/v4"

"github.com/mrmissx/stashbin/model"
"github.com/mrmissx/stashbin/response"
"github.com/mrmissx/stashbin/database/model"
"github.com/mrmissx/stashbin/utils/response"
"github.com/mrmissx/stashbin/view"
)

Expand Down
2 changes: 1 addition & 1 deletion handler/page/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/labstack/echo/v4"

"github.com/mrmissx/stashbin/response"
"github.com/mrmissx/stashbin/utils/response"
"github.com/mrmissx/stashbin/view"
)

Expand Down
2 changes: 1 addition & 1 deletion handler/page/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/jmoiron/sqlx"
"github.com/labstack/echo/v4"

"github.com/mrmissx/stashbin/model"
"github.com/mrmissx/stashbin/database/model"
)

func RawPageHandler(c echo.Context) error {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8b37fa1

Please sign in to comment.