diff --git a/backend/backend/connector_mysql.exe b/backend/backend/connector_mysql.exe index 499644c..acba95b 100644 Binary files a/backend/backend/connector_mysql.exe and b/backend/backend/connector_mysql.exe differ diff --git a/backend/backend/connector_mysql.go b/backend/backend/connector_mysql.go index d69b8ad..60c9e76 100644 --- a/backend/backend/connector_mysql.go +++ b/backend/backend/connector_mysql.go @@ -16,29 +16,36 @@ func connectMysql() (*sql.DB, error) { return db, nil } -// func addUser(login string, password string, userDescription string, points int) { -// //do rejestracji uzytkownika -// // Insert do bazy Mysql Nowego użytkownika +func addUser(_login string, _password string, _userDescription string, _points int) { + //do rejestracji uzytkownika + // Insert do bazy Mysql Nowego użytkownika -// db, err = connectMysql() -// if err != nil { -// panic(err.Error()) -// } -// queryInsert := fmt.Sprintf(`INSERT INTO golang_user ( -// login, -// password, -// userDescription, -// points -// )VALUES ( -// %s, -// %s, -// %s, -// %d -// )`, login, password, userDescription, 0) + db, err := connectMysql() -// insert, err := db.Query(queryInsert) + if err != nil { + panic(err.Error()) + } -// } + queryInsert := fmt.Sprintf(`INSERT INTO users ( + login, + password, + userDescription, + points + )VALUES ( + "%s", + "%s", + "%s", + "%d" + )`, _login, _password, _userDescription, _points) + + fmt.Printf(queryInsert) + insert, err := db.Query(queryInsert) + if err != nil { + panic(err.Error()) + } + fmt.Println(insert) + +} func getAllUsers() []User { //pobiera wszystkich uzytkownikow - do wysiwetlenie na front @@ -60,16 +67,14 @@ func getAllUsers() []User { for result.Next() { var user User - err = result.Scan(&user.userId, user.login, user.userDescription, user.points) + err = result.Scan(&user.userId, &user.login, &user.password, &user.userDescription, &user.points) if err != nil { panic(err.Error()) } - fmt.Println(user.userId, user.login) allUsers = append(allUsers, user) } - fmt.Println(allUsers) return allUsers } @@ -81,6 +86,9 @@ func main() { // // db, err := sql.Open("mysql", "root:password@tcp(127.0.0.1:3306)/golang_user") // fmt.Println(reflect.TypeOf(db)) // fmt.Println(reflect.TypeOf(err)) + + addUser("login10", "password", "userDescription", 123) allUsers := getAllUsers() fmt.Println(allUsers) + }