From 607fde717d69521c19cf0db0bc7b015e343ff65d Mon Sep 17 00:00:00 2001 From: Marco Realacci Date: Sat, 10 Dec 2022 02:08:05 +0100 Subject: [PATCH] Improve comments in database.go+ --- service/database/database.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/service/database/database.go b/service/database/database.go index f70b464..0aeb9ad 100644 --- a/service/database/database.go +++ b/service/database/database.go @@ -97,13 +97,14 @@ func New(db *sql.DB) (AppDatabase, error) { // Check if tables exist. If not, the database is empty, and we need to create the structure var tableName string - err := db.QueryRow(`SELECT name FROM sqlite_master WHERE type='table' AND name='users';`).Scan(&tableName) //todo: check for all the tables + //todo: check for all the tables, not just users + err := db.QueryRow(`SELECT name FROM sqlite_master WHERE type='table' AND name='users';`).Scan(&tableName) if errors.Is(err, sql.ErrNoRows) { sqlStmt := `CREATE TABLE "users" ( "uid" TEXT NOT NULL, "name" TEXT NOT NULL UNIQUE, PRIMARY KEY("uid") - )` //todo: one query is enough! Why do I need to do this? + )` // todo: one query is enough! We are we doing a query per table? _, err = db.Exec(sqlStmt) if err != nil { return nil, fmt.Errorf("error creating database structure: %w", err)