diff --git a/packages/api/internal/db/client.go b/packages/api/internal/db/client.go index 6354a4b03..0c825492e 100644 --- a/packages/api/internal/db/client.go +++ b/packages/api/internal/db/client.go @@ -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 { @@ -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