-
Notifications
You must be signed in to change notification settings - Fork 11
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
Showing
1 changed file
with
0 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,3 @@ | ||
package database | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/jmoiron/sqlx" | ||
|
||
_ "github.com/lib/pq" | ||
) | ||
|
||
type RowMap = map[string]interface{} | ||
|
||
type DB struct { | ||
*sqlx.DB | ||
} | ||
|
||
type Option struct { | ||
Host string | ||
Port string | ||
User string | ||
Pass string | ||
DbName string | ||
} | ||
|
||
func Open(option Option) (*DB, error) { | ||
return OpenWith(option.Host, option.Port, option.User, option.Pass, option.DbName) | ||
} | ||
|
||
func OpenWith(host, port, user, pass, dbName string) (*DB, error) { | ||
db, err := sqlx.Open( | ||
"postgres", | ||
fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=disable", | ||
user, | ||
pass, | ||
host, | ||
port, | ||
dbName), | ||
) | ||
return &DB{db}, err | ||
} |