sqlboiler: Generated code keeps refering to v4 and v8 folders when they do not exist

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v4.1.1

What is your database and version:

Sqlite3

If this happened at generation time what was the full SQLBoiler command you used to generate your models?

sqlboiler sqlite3 -c ../lib/sqlboiler.toml --no-hooks

Several imports generated that points to non existing folders: github.com/volatiletech/sqlboiler/v4/boil github.com/volatiletech/null/v8

This was easily fixed by refracting “/v4” and “/v8” out to get it to work. But it is annoying having to refract it every time the model is changed The library was installed using the commands stated in the Github page.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Okay. I think I have an inkling as to what’s going on here.

The v8/v4 folders are semantic import versioning folders. They exist to declare that it’s part of a major version of a package. This is part of the Go modules system described here: https://blog.golang.org/using-go-modules

sqlboiler v4 moved to the Go module system. This is the Go dependency management system and was introduced in Go 1.11. We’re years after that and I made the decision that sqlboiler should be a Go module now that the problems with modules have started to smooth out.

You will encounter issues with sqlboiler v4 if you do not have a Go version that understands semantic import versioning. If you are +1’ing on this issue here please include some details:

  • What is your Go version?
  • What is the output of sqlboiler --version?
  • What is the output of go env | grep GO111?

I believe Go versions <1.10.4 and <1.9.7 have no idea how to deal with semantic import versioning and will simply not be able to use sqlboiler anymore. There is no support for these versions of Go neither in the Go community nor in sqlboiler, please upgrade Go if you find you have an old version of it.

In order to ensure everything works:

  • Make sure you delete all sqlboiler-* binaries
  • go get the binaries in a “module-friendly” way. This prevents Go from thinking you want to add this module as a dependency to your current package and does the correct behavior from older versions of Go. See this issue for more details: https://github.com/golang/go/issues/30515
env GO111MODULE=off go get github.com/volatiletech/sqlboiler
env GO111MODULE=off go get github.com/volatiletech/sqlboiler/drivers/sqlboiler-psql

This should leave you with the latest sqlboiler and sqlboiler-psql, and it should generate code with v8/v4 in the paths, and as long as you have a Go version that understands semantic import versioning it -should- work.

I am quite against the usage of “global install” tools as it is hard to ensure that our team members use the same version. We always break the code due to using different versions of the tools.

Go modules solves this problem, because we can now specify the version we use in a project. I will share how we manage to use sqlboiler (both command line utility and project dependency) locally:

  1. Install sqlboiler with Go modules according to existing README instruction:
# Do not forget the trailing /v4
go get github.com/volatiletech/sqlboiler/v4
# Assuming you're going to use the null package for its additional null types
# Do not forget the trailing /v8
go get github.com/volatiletech/null/v8
  1. Install the driver
# Install an sqlboiler driver - these are seperate binaries, here we are
# choosing postgresql
GO111MODULE=off go get github.com/volatiletech/sqlboiler/drivers/sqlboiler-psql
  1. Go to GOPATH/bin and find your driver binary. In our case, it is named sqlboiler-psql. Move this binary to your project root.

  2. It’s done. We have installed sqlboilder locally: the project dependency is declared in go.mod, while the driver binary is placed at root directory. Both are to be put in your git so we have version control on them. Whenever you need to run sqlboilder as command line tool, use go run github.com/volatiletech/sqlboiler/v4 psql. It uses the binary in your project root. You can also use //go:generate go run github.com/volatiletech/sqlboiler/v4 psql.

This has worked for me, hope same for others having the same issue:

  • Remove all binaries from $GOPATH/bin/sqlboiler*
  • Download latest binaries
export GO111MODULE="on"
go get -u -t github.com/volatiletech/sqlboiler
go get github.com/volatiletech/sqlboiler/drivers/sqlboiler-psql
  • Use regular package references in the code
github.com/volatiletech/null
github.com/volatiletech/sqlboiler/boil

imo it makes no sense versioning if the latest is working great

I’m having this issue as well, after an update of sqlboiler and the psql driver.