Added repositories
This commit is contained in:
parent
c0cb826917
commit
4a16acc87e
7 changed files with 264 additions and 39 deletions
23
internal/infrastructure/db/db.go
Normal file
23
internal/infrastructure/db/db.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"58team_blog/internal/infrastructure"
|
||||
"fmt"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
Conn *sqlx.DB
|
||||
}
|
||||
|
||||
func DatabaseInit(config infrastructure.Config) (db *Database, err error) {
|
||||
db = &Database{}
|
||||
db_setup := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s", config.DBUser, config.DBPass, config.DBHost, config.DBPort, config.DBName)
|
||||
db.Conn, err = sqlx.Connect("postgres", db_setup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue