Loggest thy stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

48 lines
941 B

package mysql
import (
"database/sql"
"fmt"
"git.aiterp.net/stufflog3/stufflog3-api/internal/database"
"time"
_ "github.com/go-sql-driver/mysql"
)
type Database struct {
db *sql.DB
}
func (d *Database) Scopes() database.ScopeRepository {
return &scopeRepository{db: d.db}
}
func (d *Database) Stats(scopeID int) database.StatRepository {
//TODO implement me
panic("implement me")
}
func (d *Database) Items(scopeID int) database.ItemRepository {
//TODO implement me
panic("implement me")
}
func Connect(host string, port int, username, password, database string) (*Database, error) {
db, err := sql.Open("mysql", fmt.Sprintf(
"%s:%s@(%s:%d)/%s?parseTime=true", username, password, host, port, database,
))
if err != nil {
return nil, err
}
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)
db.SetConnMaxIdleTime(time.Minute)
err = db.Ping()
if err != nil {
return nil, err
}
return &Database{db: db}, nil
}