diff options
-rw-r--r-- | src/db.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/db.go b/src/db.go new file mode 100644 index 0000000..976354b --- /dev/null +++ b/src/db.go @@ -0,0 +1,32 @@ +package main + +import ( + "database/sql" + "fmt" + "log" +) + +// setup the Database +func setupDatabase() *sql.DB { + connStr := "user=postgres dbname=postgres sslmode=disable" + db, err := sql.Open("postgres", connStr) + if err != nil { + log.Fatal(err) + } + + return db +} + +// getNames gets the name of all the challenges +func getName(db *sql.DB) string { + + // get the current name of the challenges + query := fmt.Sprintf("SELECT name FROM challenges WHERE points=200") + var names string + err := db.QueryRow(query).Scan(&names) + if err != nil { + log.Fatalf("[ E ] :", err) + } + + return names +} |