From 762d3c875a5fd0774a3d820d5118fff22cdc4b5c Mon Sep 17 00:00:00 2001 From: michaellindman Date: Thu, 4 Jul 2019 05:28:00 +0100 Subject: [PATCH] wip database implementation --- database.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 database.go diff --git a/database.go b/database.go new file mode 100644 index 0000000..6abc3c7 --- /dev/null +++ b/database.go @@ -0,0 +1,40 @@ +package request + +import ( + "database/sql" + "fmt" + "log" +) + +func dbConnect() *sql.DB { + resp := Option().Database + db, err := sql.Open("mysql", resp.User+":"+resp.Passwd+"@tcp("+resp.Server+")/"+resp.DB) + if err != nil { + fmt.Println(err) + } else { + fmt.Println("Connection Established") + } + return db +} + +func GetUser(id int) { + var email string + db := dbConnect() + rows, err := db.Query("select request_id, email from gdpr_requests where request_id = ?", 1) + if err != nil { + log.Fatal(err) + } + defer db.Close() + for rows.Next() { + err := rows.Scan(&id, &email) + if err != nil { + log.Fatal(err) + } + fmt.Println(id, email) + } + err = rows.Err() + if err != nil { + log.Fatal(err) + } + defer db.Close() +}