481471 (1) [Avatar] Offline
#1
Hello,
I am following the tutorial in Chapter 2. I notice in the GitHub code repository there is reference to a db() function in the thread_test.go file:

func ThreadDeleteAll() (err error) {
db := db()
defer db.Close()
statement := "delete from threads"
_, err = db.Exec(statement)
if err != nil {
return
}
return
}

There is no listing for the db() function in the GitHub.
Assuming the first line of the function should read: db := Db (where Db is the global var created in the data.go file)

I am constantly getting this error: sql: database is closed Cannot create user.

Does anyone know why this is happening please. I am using a new version of PostgreSQL
500974 (1) [Avatar] Offline
#2
481471 wrote:Hello,
I am following the tutorial in Chapter 2. I noticed that there is a reference to a db() function in the thread_test.go file in the GitHub code repository:

func ThreadDeleteAll() (err error) {
	db := db()
	defer db.Close()
	statement := "delete from threads"
	_, err = db.Exec(statement)
	if err != nil {
		return
	}
	return
}


There is no listing for the db() function in the GitHub.
Assuming the first line of the function should read:
db := Db
(where Db is the global var created in the data.go file)

I am constantly getting this error: sql: database is closed Cannot create user.

Does anyone know why this is happening please? I am using a new version of PostgreSQL