Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: database is closed #3

Open
goodforever opened this issue Jul 20, 2018 · 2 comments
Open

sql: database is closed #3

goodforever opened this issue Jul 20, 2018 · 2 comments

Comments

@goodforever
Copy link

I use postgresql server ,When I go run server.go ,I got

(sql: database is closed)
[2018-07-20 11:36:04]

(sql: database is closed)
[2018-07-20 11:36:04]

(sql: database is closed)
[2018-07-20 11:36:04]

(sql: database is closed)
[2018-07-20 11:36:04]
[negroni] listening on :3000

@markcheno
Copy link
Owner

I have not tried Postgres, I would check your config info.

@catdevman
Copy link

@goodforever I double-checked and I was able to get Postgres working.

Changed server.go to have

db := models.NewPostgresDB("postgres://postgres:password@localhost/pqgotest?sslmode=disable")

Instead of

db := models.NewSqliteDB("data.db")

Make sure that you change any credentials and database accordingly. Also, I believe you will have to create the database prior to starting the server. Unlike Sqlite, Postgres can have multiple databases under the same connection (sqlite would require multiple files as far as I know, maybe I am wrong), which means the driver needs the database to exist to connect to it. If you have done all that I am not sure why it wouldn't be working but like I said I verifed it to working.

FYI: I used docker for both the database and database management tools

docker run --name go-postgres -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres

docker pull dpage/pgadmin4

docker run -p 80:80 \
-e "[email protected]" \
-e "PGADMIN_DEFAULT_PASSWORD=password" \
--link go-postgres:go-postgres -d dpage/pgadmin4

When the database was not created I did get an error on startup that was different then yours

panic: pq: database "pqgotest" does not exist

goroutine 1 [running]:
github.com/markcheno/go-vue-starter/models.NewPostgresDB(0x45d2f1f, 0x3f, 0x0)
	/Users/******/go/src/github.com/markcheno/go-vue-starter/models/db.go:21 +0x172
main.main()
	/Users/******/go/src/github.com/markcheno/go-vue-starter/server.go:11 +0x3a
exit status 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants