Skip to content

Commit

Permalink
Limit max open connection to 20
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Oct 24, 2023
1 parent 6d28b33 commit e04987a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/api/internal/db/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package db
import (
"context"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"fmt"
"github.com/e2b-dev/infra/packages/api/internal/db/ent"
"os"

_ "github.com/lib/pq"
"os"
)

type DB struct {
Expand All @@ -22,9 +22,19 @@ func NewClient(ctx context.Context) (*DB, error) {
return nil, fmt.Errorf("database URL is empty")
}

client, err := ent.Open(dialect.Postgres, databaseURL, ent.AlternateSchema(ent.SchemaConfig{
drv, err := sql.Open(dialect.Postgres, databaseURL)
if err != nil {
return nil, err
}

// Get the underlying sql.DB object of the driver.
db := drv.DB()
db.SetMaxOpenConns(20)

client := ent.NewClient(ent.Driver(drv), ent.AlternateSchema(ent.SchemaConfig{
User: "auth",
}))

if err != nil {
err = fmt.Errorf("failed to connect to database: %w", err)
return nil, err
Expand Down

0 comments on commit e04987a

Please sign in to comment.