-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
1456330
commit 111ecbc
Showing
4 changed files
with
43 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
package db | ||
|
||
import ( | ||
"database/sql" | ||
"log" | ||
"os" | ||
|
||
_ "github.com/lib/pq" | ||
) | ||
|
||
func (db SqlHandler) Connect() { | ||
conn, err := sql.Open("postgres", os.Getenv("POSTGRES_DATABASE_URL")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
log.Println("Connected to database!") | ||
db.Conn = conn | ||
} | ||
|
||
func (db SqlHandler) Close() { | ||
db.Conn.Close() | ||
} |
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,20 @@ | ||
package db | ||
|
||
import "database/sql" | ||
|
||
var DB SqlHandler | ||
|
||
type SqlHandlerInterface interface { | ||
Connect() | ||
Close() | ||
Query(string) | ||
} | ||
|
||
type SqlHandler struct { | ||
SqlHandlerInterface | ||
Conn *sql.DB | ||
} | ||
|
||
func (db SqlHandler) Query(query string) { | ||
db.Conn.Query(query) | ||
} |
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