Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hiroshi Kurabayashi
committed
Jan 21, 2020
1 parent
ddb18f8
commit 233604e
Showing
3 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package datastore | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/jinzhu/gorm" | ||
_ "github.com/jinzhu/gorm/dialects/postgres" | ||
|
||
"api/config" | ||
) | ||
|
||
func NewPostgreSQL() *gorm.DB { | ||
connectString := fmt.Sprintf( | ||
"host=%s port=%s user=%s dbname= %s password=%s %s", | ||
config.C.Postgres.HOST, | ||
config.C.Postgres.PORT, | ||
config.C.Postgres.USER, | ||
config.C.Postgres.DBNAME, | ||
config.C.Postgres.PASS, | ||
config.C.Postgres.OPTION, | ||
) | ||
db, err := gorm.Open(config.C.Postgres.DBMS, connectString) | ||
|
||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
db.LogMode(true) | ||
|
||
return db | ||
} |