about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-10-18 23:38:14 +0200
committerEmile <hanemile@protonmail.com>2019-10-18 23:38:14 +0200
commit059964e63fb9f06bceb153f903d04551c782bbf0 (patch)
treeb38993f2be0712511a80ab57a6d1d3a1ba209c38 /src
parentc8c6400944a880da424c97c36410767290771644 (diff)
basic database connection
Diffstat (limited to 'src')
-rw-r--r--src/db.go32
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
+}