docs icon indicating copy to clipboard operation
docs copied to clipboard

Issues with sqlite3 (and solutions) while getting started with Buffalo

Open rohfle opened this issue 2 years ago • 1 comments

This is the first time I've played around with buffalo. I had trouble getting sqlite3 working as a database while following the getting started docs and thought I would share what I did.

What I did From https://gobuffalo.io/documentation/getting_started/installation/ go install -tags sqlite github.com/gobuffalo/cli/cmd/[email protected] - OK

From https://gobuffalo.io/documentation/getting_started/new-project/ and https://dev.to/alexmercedcoder/api-with-go-buffalo-in-2021-from-zero-to-deploy-5642 buffalo new project1 --api - OK

Then I wanted to change database type to sqlite for development in database.yml

development:
  dialect: "sqlite3"
  database: development.sqlite

But I got this error when running buffalo dev

buffalo: 2022/08/07 08:37:00 === Rebuild on: :start: ===
buffalo: 2022/08/07 08:37:00 === Running: go build -v -tags development -o tmp/project1-build ./cmd/app (PID: 615572) ===
buffalo: 2022/08/07 08:37:01 === Building Completed (PID: 615572) (Time: 1.093997852s) ===
buffalo: 2022/08/07 08:37:01 === Running: tmp/project1-build (PID: 615635) ===
[POP] 2022/08/07 08:37:01 warn - unable to load connection development: could not create new connection: sqlite3 support was not compiled into the binary
2022/08/07 08:37:01 could not find connection named development
buffalo: 2022/08/07 08:37:01 === exit status 1
2022/08/07 08:37:01 could not find connection named development

To fix this, I have to browse through issues and slack and read between the lines. I set the following in config/buffalo-app.toml

with_sqlite = true

And set the following in config/buffalo-plugins.toml

[[plugin]]
  binary = "buffalo-pop"
  go_get = "github.com/gobuffalo/buffalo-pop/v3@latest"
  tags = ["sqlite"]

Then buffalo dev works

buffalo: 2022/08/07 08:44:24 === Rebuild on: :start: ===
buffalo: 2022/08/07 08:44:24 === Running: go build -v -tags development sqlite -o tmp/project1-build ./cmd/app (PID: 616136) ===
buffalo: 2022/08/07 08:44:27 === Building Completed (PID: 616136) (Time: 2.496160018s) ===
buffalo: 2022/08/07 08:44:27 === Running: tmp/project1-build (PID: 616211) ===
DEBU[2022-08-07T08:44:27+12:00] starting application
INFO[2022-08-07T08:44:27+12:00] starting simple server on 127.0.0.1:3002
INFO[2022-08-07T08:44:27+12:00] starting Simple background worker

Somewhere I learn about using the --db-type arg like buffalo new project1 --db-type sqlite3, which gets me to the same point. I have to change database.yml as I want to use sqlite3 for development but not for testing and production. Also paths are absolute (not relative to project directory), so if the project moves this would need to be updated.

When I try to run buffalo pop migrate I get

pop v6.0.5

[POP] 2022/08/07 08:56:54 warn - unable to load connection development: could not create new connection: sqlite3 support was not compiled into the binary
There is no connection named development defined!

which soda and which pop gives no result so I assume that pop is embedded in buffalo. But weird that sqlite3 support is present for dev but not for pop. Not sure how to proceed with this one.

rohfle avatar Aug 06 '22 21:08 rohfle