From 362d9d0296b868d77e2cc2fa2bf960120248bff0 Mon Sep 17 00:00:00 2001 From: Pablo Ovelleiro Corral Date: Fri, 19 Apr 2019 23:54:13 +0200 Subject: [PATCH] fixed db, implemented missing methods --- .gitignore | 1 + giteadb.go | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index e01cfd7..764dec8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ tags config.ini gitea-matrix-bot +tokens.db diff --git a/giteadb.go b/giteadb.go index 2081162..b15666a 100644 --- a/giteadb.go +++ b/giteadb.go @@ -50,7 +50,7 @@ func (dbg *GiteaDB) GetToken(room string) string { } defer db.Close() - stmt, err := db.Prepare("select name from foo where id = ?") + stmt, err := db.Prepare("select token from tokens where room = ?") if err != nil { log.Fatal(err) } @@ -134,17 +134,20 @@ func (dbg *GiteaDB) Set(room, token string) { if err != nil { log.Fatal(err) } + fmt.Println("inserting") + stmt, err := tx.Prepare("insert into tokens(room, token) values(?, ?)") if err != nil { log.Fatal(err) } + defer stmt.Close() - for i := 0; i < 100; i++ { - _, err = stmt.Exec(room, token) - if err != nil { - log.Fatal(err) - } + _, err = stmt.Exec(room, token) + if err != nil { + log.Fatal(err) } tx.Commit() + dbg.GetAll() + }