about summary refs log tree commit diff
path: root/src/db.go
blob: 976354b9d7386a2c36fe02893a98dcd6167c22e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
}