29 lines
488 B
Go
29 lines
488 B
Go
package store
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"aiaa-notification-service/internal/config"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
_ "github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
type Store struct {
|
|
DB *sqlx.DB
|
|
}
|
|
|
|
func NewStore(cfg config.DatabaseConfig) (*Store, error) {
|
|
db, err := sqlx.Connect("mysql", cfg.DSN())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("connect mysql: %w", err)
|
|
}
|
|
db.SetMaxOpenConns(25)
|
|
db.SetMaxIdleConns(5)
|
|
return &Store{DB: db}, nil
|
|
}
|
|
|
|
func (s *Store) Close() error {
|
|
return s.DB.Close()
|
|
}
|