feat: store connection and source CRUD
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user