Skip to content

Commit

Permalink
added basic postgres code to main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyStiles committed Sep 8, 2023
1 parent 06aa658 commit c7b6efb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.18

require (
github.com/jmoiron/sqlx v1.3.4
github.com/lib/pq v1.2.1-0.20191011153232-f91d3411e481
github.com/mattn/go-sqlite3 v1.14.12
)

require github.com/lib/pq v1.2.1-0.20191011153232-f91d3411e481 // indirect
37 changes: 36 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
package main

import (
"database/sql"
"fmt"

_ "github.com/lib/pq"
)

const (
host = "127.0.0.1"
port = 65318
user = ""
password = ""
dbname = ""
)

func main() {
// cmd.Execute()
// connection string
psqlconn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)

// open database
db, err := sql.Open("postgres", psqlconn)
CheckError(err)

// close database
defer db.Close()

// check db
err = db.Ping()
CheckError(err)

fmt.Println("Connected!")
}

func CheckError(err error) {
if err != nil {
panic(err)
}
}

0 comments on commit c7b6efb

Please sign in to comment.