Created
January 16, 2015 15:48
-
-
Save heathd/dee3bc07829ed2fd100e to your computer and use it in GitHub Desktop.
psql connection example
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
package main | |
import ( | |
"database/sql" | |
"fmt" | |
_ "github.com/lib/pq" | |
"log" | |
) | |
func main() { | |
db, err := sql.Open("postgres", "host=/var/run/postgresql/ sslmode=disable dbname=entities") | |
if err != nil { | |
fmt.Printf("%v", err) | |
} | |
rows, err := db.Query("SELECT * FROM entities") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer rows.Close() | |
for rows.Next() { | |
var num int | |
if err := rows.Scan(&num); err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("num: %v", num) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment