reform-db: gofmt error: exit status 2
Closed this issue · 10 comments
Hello! I'm really new to golang, i wish i can provide more info but this is all i have now. Running reform-db -db-driver=postgres -db-source=postgres://user:pass@localhost:port/database init
returns reform-db: gofmt error: exit status 2
, even if it's simple 2 tables "just for test" database. I'm using:
- PostgreSQL 10.5
- Ubuntu Server 18.04
- Go 1.11
- installed reform by
go get -u gopkg.in/reform.v1/...
so I assume I'm using v1.3.2
For now i don't know what to do, I'm deadlined so i have to choose between other options like kallax or pg, but I really like the simplicity and ideology of reform, so I hope this will be fixed.
Please try
reform-db [flags] init -gofmt=false
Wow. That was really fast. Thank you very much @AlekSi, that helped me, code is generated now. But what's the problem? Also i have bunch of enumerated types that marked as FIXME, what should i do with them? Basically that's nullable strings, is it right?
P.S your Go ORM report rocks :)
P.P.S Foreign keys isn't an option here, right?
But what's the problem?
It is hard to say. Please try when you are not under time pressure:
reform-db -debug [flags] init
Also i have bunch of enumerated types that marked as FIXME, what should i do with them? Basically that's nullable strings, is it right?
*string
for NULLable varchar
columns, right. You can also define a custom type if you need it, the following should work with Go 1.11:
type MyEnum string
const (
Foo MyEnum = "foo"
Bar MyEnum = "bar"
)
type Model struct {
Enum MyEnum `reform:"enum"`
}
Please try when you are not under time pressure
Here you go:
reform-db: 2018/08/30 17:46:00.454630 main.go:78: >>> SELECT "information_schema"."tables"."table_catalog", "information_schema"."tables"."table_schema", "information_schema"."tables"."table_name", "information_schema"."tables"."table_type" FROM "information_schema"."tables" WHERE table_schema = current_schema()
reform-db: 2018/08/30 17:46:00.459508 main.go:78: <<< SELECT "information_schema"."tables"."table_catalog", "information_schema"."tables"."table_schema", "information_schema"."tables"."table_name", "information_schema"."tables"."table_type" FROM "information_schema"."tables" WHERE table_schema = current_schema() 4.758423ms
reform-db: 2018/08/30 17:46:00.459654 main.go:78: >>> SELECT column_name, ordinal_position FROM information_schema.key_column_usage
INNER JOIN information_schema.table_constraints ON key_column_usage.table_catalog = table_constraints.table_catalog AND key_column_usage.table_schema = table_constraints.table_schema AND key_column_usage.table_name = table_constraints.table_name
WHERE key_column_usage.table_catalog = $1 AND
key_column_usage.table_schema = $2 AND
key_column_usage.table_name = $3 AND
constraint_type = 'PRIMARY KEY'
ORDER BY ordinal_position DESC [`database`, `public`, `accounts`]
reform-db: 2018/08/30 17:46:00.465896 main.go:78: <<< SELECT column_name, ordinal_position FROM information_schema.key_column_usage
INNER JOIN information_schema.table_constraints ON key_column_usage.table_catalog = table_constraints.table_catalog AND key_column_usage.table_schema = table_constraints.table_schema AND key_column_usage.table_name = table_constraints.table_name
WHERE key_column_usage.table_catalog = $1 AND
key_column_usage.table_schema = $2 AND
key_column_usage.table_name = $3 AND
constraint_type = 'PRIMARY KEY'
ORDER BY ordinal_position DESC [`database`, `public`, `accounts`] 6.163433ms
reform-db: 2018/08/30 17:46:00.466115 main.go:78: >>> SELECT "information_schema"."columns"."table_catalog", "information_schema"."columns"."table_schema", "information_schema"."columns"."table_name", "information_schema"."columns"."column_name", "information_schema"."columns"."is_nullable", "information_schema"."columns"."data_type" FROM "information_schema"."columns" WHERE table_catalog = $1 AND table_schema = $2 AND table_name = $3 ORDER BY ordinal_position [`database`, `public`, `accounts`]
reform-db: 2018/08/30 17:46:00.474430 main.go:78: <<< SELECT "information_schema"."columns"."table_catalog", "information_schema"."columns"."table_schema", "information_schema"."columns"."table_name", "information_schema"."columns"."column_name", "information_schema"."columns"."is_nullable", "information_schema"."columns"."data_type" FROM "information_schema"."columns" WHERE table_catalog = $1 AND table_schema = $2 AND table_name = $3 ORDER BY ordinal_position [`database`, `public`, `accounts`] 8.285622ms
reform-db: 2018/08/30 17:46:00.474604 main.go:78: >>> SELECT column_name, ordinal_position FROM information_schema.key_column_usage
INNER JOIN information_schema.table_constraints ON key_column_usage.table_catalog = table_constraints.table_catalog AND key_column_usage.table_schema = table_constraints.table_schema AND key_column_usage.table_name = table_constraints.table_name
WHERE key_column_usage.table_catalog = $1 AND
key_column_usage.table_schema = $2 AND
key_column_usage.table_name = $3 AND
constraint_type = 'PRIMARY KEY'
ORDER BY ordinal_position DESC [`database`, `public`, `contacts`]
reform-db: 2018/08/30 17:46:00.477969 main.go:78: <<< SELECT column_name, ordinal_position FROM information_schema.key_column_usage
INNER JOIN information_schema.table_constraints ON key_column_usage.table_catalog = table_constraints.table_catalog AND key_column_usage.table_schema = table_constraints.table_schema AND key_column_usage.table_name = table_constraints.table_name
WHERE key_column_usage.table_catalog = $1 AND
key_column_usage.table_schema = $2 AND
key_column_usage.table_name = $3 AND
constraint_type = 'PRIMARY KEY'
ORDER BY ordinal_position DESC [`database`, `public`, `contacts`] 3.234114ms
reform-db: 2018/08/30 17:46:00.478095 main.go:78: >>> SELECT "information_schema"."columns"."table_catalog", "information_schema"."columns"."table_schema", "information_schema"."columns"."table_name", "information_schema"."columns"."column_name", "information_schema"."columns"."is_nullable", "information_schema"."columns"."data_type" FROM "information_schema"."columns" WHERE table_catalog = $1 AND table_schema = $2 AND table_name = $3 ORDER BY ordinal_position [`database`, `public`, `contacts`]
reform-db: 2018/08/30 17:46:00.482769 main.go:78: <<< SELECT "information_schema"."columns"."table_catalog", "information_schema"."columns"."table_schema", "information_schema"."columns"."table_name", "information_schema"."columns"."column_name", "information_schema"."columns"."is_nullable", "information_schema"."columns"."data_type" FROM "information_schema"."columns" WHERE table_catalog = $1 AND table_schema = $2 AND table_name = $3 ORDER BY ordinal_position [`database`, `public`, `contacts`] 4.645009ms
reform-db: 2018/08/30 17:46:00.483990 cmd_init.go:204: main.StructData{Imports:map[string]struct {}{"time":struct {}{}}, StructInfo:parse.StructInfo{Type:"Accounts", SQLSchema:"", SQLName:"accounts", Fields:[]parse.FieldInfo{parse.FieldInfo{Name:"ID", Type:"int32", Column:"id"}, parse.FieldInfo{Name:"CreatedAt", Type:"*time.Time", Column:"created_at"}, parse.FieldInfo{Name:"UpdatedAt", Type:"*time.Time", Column:"updated_at"}, parse.FieldInfo{Name:"DeletedAt", Type:"*time.Time", Column:"deleted_at"}, parse.FieldInfo{Name:"Email", Type:"*string", Column:"email"}, parse.FieldInfo{Name:"Password", Type:"*string", Column:"password"}, parse.FieldInfo{Name:"Token", Type:"*string", Column:"token"}}, PKFieldIndex:0}, FieldComments:[]string{"", "", "", "", "", "", ""}}
reform-db: 2018/08/30 17:46:00.484170 cmd_init.go:211: Writing /root/accounts.go ...
reform-db: 2018/08/30 17:46:00.484989 cmd_init.go:204: main.StructData{Imports:map[string]struct {}{"time":struct {}{}}, StructInfo:parse.StructInfo{Type:"Contacts", SQLSchema:"", SQLName:"contacts", Fields:[]parse.FieldInfo{parse.FieldInfo{Name:"ID", Type:"int32", Column:"id"}, parse.FieldInfo{Name:"CreatedAt", Type:"*time.Time", Column:"created_at"}, parse.FieldInfo{Name:"UpdatedAt", Type:"*time.Time", Column:"updated_at"}, parse.FieldInfo{Name:"DeletedAt", Type:"*time.Time", Column:"deleted_at"}, parse.FieldInfo{Name:"Name", Type:"*string", Column:"name"}, parse.FieldInfo{Name:"Phone", Type:"*string", Column:"phone"}, parse.FieldInfo{Name:"UserID", Type:"*int32", Column:"user_id"}}, PKFieldIndex:0}, FieldComments:[]string{"", "", "", "", "", "", ""}}
reform-db: 2018/08/30 17:46:00.485141 cmd_init.go:211: Writing /root/contacts.go ...
reform-db: 2018/08/30 17:46:00.485695 cmd_init.go:47: gofmt -s -w /root
reform-db: 2018/08/30 17:46:18.324573 cmd_init.go:50: gofmt error: exit status 2
panic: gofmt error: exit status 2
goroutine 1 [running]:
gopkg.in/reform.v1/internal.(*Logger).Fatalf(0xc000020ca0, 0x8c093f, 0xf, 0xc000352d90, 0x1, 0x1)
/root/go/src/gopkg.in/reform.v1/internal/logger.go:51 +0x107
main.gofmt(0xc00001a054, 0x5)
/root/go/src/gopkg.in/reform.v1/reform-db/cmd_init.go:50 +0x1fd
main.cmdInit(0xc00000d4c0, 0xc00001a054, 0x5)
/root/go/src/gopkg.in/reform.v1/reform-db/cmd_init.go:227 +0x85e
main.main()
/root/go/src/gopkg.in/reform.v1/reform-db/main.go:128 +0x3a4
Are you writing code outside of GOPATH? Are you using Go modules?
Please post outputs of go env
and env | grep '^GO'
.
I assume my GOPATH is fine as my GOPATH is part of my PATH.
# go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GOPROXY=""
GORACE=""
GOROOT="/root/.go"
GOTMPDIR=""
GOTOOLDIR="/root/.go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build291529854=/tmp/go-build -gno-record-gcc-switches"
# env | grep '^GO'
GOPATH=/root/go
Btw i checked just now and it looks like this panic is not infuencing the results - all my schema was generated in .go files even without -gofmt=false, but that error confused me and I didn't checked that earlier.
Yeah, but do you have projects' code in the GOPATH? Where are other files of your project located?
My project is in ~/go/src/projectname. I thought db-reform is a standalone utility so i launched it in ~, and after you said about GOPATH i tried to launch it in ~/go, but nothing changed
Normally, one should run reform-db
inside existing project directory, so files are generated inside Go package that can be imported by gofmt
.
I will make it more clear in the documentation.
Even after launching it in the project folder same error occured. Documentation with full examples would make this project beginner-friendly for sure, i still don't figured out how to properly use NewDB :(