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

Project doesn't compile/run #751

Open
robertoneto-senior opened this issue Jul 12, 2024 · 8 comments
Open

Project doesn't compile/run #751

robertoneto-senior opened this issue Jul 12, 2024 · 8 comments
Assignees

Comments

@robertoneto-senior
Copy link

GORM Playground Link

  1. Cloned the repository
  2. Ran the ./test.sh
$ ./test.sh 
git clone --depth 1 -b master https://github.com/go-gorm/gorm.git
Cloning into 'gorm'...
remote: Enumerating objects: 180, done.
remote: Counting objects: 100% (180/180), done.
remote: Compressing objects: 100% (173/173), done.
remote: Total 180 (delta 13), reused 55 (delta 5), pack-reused 0
Receiving objects: 100% (180/180), 234.74 KiB | 1.19 MiB/s, done.
Resolving deltas: 100% (13/13), done.
go: downloading gorm.io/gen v0.3.25
go: downloading gorm.io/driver/sqlite v1.5.3
go: downloading gorm.io/driver/sqlserver v1.5.1
go: downloading gorm.io/driver/mysql v1.5.2
go: downloading gorm.io/driver/postgres v1.5.2
go: downloading github.com/jinzhu/now v1.1.5
go: downloading gorm.io/driver/sqlite v1.5.6
go: downloading gorm.io/driver/sqlserver v1.5.3
go: downloading github.com/jinzhu/inflection v1.0.0
go: downloading golang.org/x/text v0.14.0
go: downloading gorm.io/driver/postgres v1.5.9
go: downloading gorm.io/driver/mysql v1.5.7
go: downloading github.com/mattn/go-sqlite3 v1.14.17
go: downloading gorm.io/gen v0.3.26
go: downloading github.com/microsoft/go-mssqldb v1.5.0
go: downloading github.com/jackc/pgx/v5 v5.4.3
go: downloading github.com/go-sql-driver/mysql v1.7.1
go: downloading github.com/go-sql-driver/mysql v1.8.1
go: downloading github.com/microsoft/go-mssqldb v1.7.2
go: downloading golang.org/x/tools v0.15.0
go: downloading github.com/mattn/go-sqlite3 v1.14.22
go: downloading github.com/jackc/pgx/v5 v5.6.0
go: downloading gorm.io/datatypes v1.1.1-0.20230130040222-c43177d3cf8c
go: downloading gorm.io/datatypes v1.2.1
go: downloading golang.org/x/tools v0.23.0
go: downloading gorm.io/hints v1.1.0
go: downloading gorm.io/hints v1.1.2
go: downloading gorm.io/plugin/dbresolver v1.5.0
go: downloading github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9
go: downloading github.com/golang-sql/sqlexp v0.1.0
go: downloading gorm.io/plugin/dbresolver v1.5.2
go: downloading golang.org/x/text v0.16.0
go: downloading golang.org/x/sys v0.14.0
go: downloading golang.org/x/crypto v0.14.0
go: downloading golang.org/x/mod v0.14.0
go: downloading github.com/jackc/pgx v3.6.2+incompatible
go: downloading golang.org/x/mod v0.19.0
go: downloading golang.org/x/sys v0.22.0
go: downloading github.com/jackc/pgpassfile v1.0.0
go: downloading github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a
go: downloading golang.org/x/crypto v0.25.0
go: downloading github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761
go: downloading filippo.io/edwards25519 v1.1.0
go: downloading golang.org/x/sync v0.7.0
go: downloading github.com/jackc/puddle/v2 v2.2.1
go: downloading github.com/jackc/puddle v1.3.0
go: gorm.io/playground imports
	gorm.io/gen/examples/dal: cannot find module providing package gorm.io/gen/examples/dal

Tried also to run go clean -modcache and go clean -cache, but the problem continues.

go version go1.22.3 linux/amd64

Description

Just trying to fork this repository to report a bug related to many2many.

@brett--anderson
Copy link

I'm also having this problem, and I'm also trying to report a bug related to many2many.

@vivere-dally
Copy link

Any update on how to deal with the examples/dal issue?

@YidiDev
Copy link

YidiDev commented Sep 27, 2024

I also have this issue

@henryjcee
Copy link

henryjcee commented Oct 8, 2024

So the issue here as I understand it is that /gen/examples was made a submodule in this commit and as a result the current import strategy doesn't work. I don't know the go mod system well enough to recommend a fix but I've worked around this by cloning gen and using a replace directive to import the examples submodule from my local copy.

@deqing
Copy link

deqing commented Oct 9, 2024

So the issue here as I understand it is that /gen/examples was made a submodule in this commit and as a result the current import strategy doesn't work. I don't know the go mod system well enough to recommend a fix but I've worked around this by cloning gen and using a replace directive to import the examples submodule from my local copy.

Could you please share what is the replace directive? I want to report an issue too.

@henryjcee
Copy link

henryjcee commented Oct 9, 2024

Am just writing up a PR now but I've checked out the gen repo and am using:

replace gorm.io/gen/examples => ../gen/examples

which resolves the /examples submodule correctly. For some reason I can't get this to work by requiring gorm.io/gen/examples v0.3.26 without replacing it with a local version, but I am pretty new to Go and perhaps I'm missing the special sauce for requiring a submod?

@henryjcee
Copy link

Have raised an issue to fix what I think is the root cause

@maxant
Copy link

maxant commented Oct 22, 2024

I commented out the following in gorm-playground/gen.go:

package main

import (
	"gorm.io/gen"
//	"./gen/examples/dal" <<<<<<<<<<<<<<<<<<<<<<<<<<
)

func generate() {
	g := gen.NewGenerator(gen.Config{
		OutPath: "./dal/query",
		Mode:    gen.WithDefaultQuery, /*WithQueryInterface, WithoutContext*/

		WithUnitTest: true,
	})
//	g.UseDB(dal.DB)  <<<<<<<<<<<<<<<<<<<<<<<<<<

	g.ApplyBasic(Company{}, Language{}) // Associations
	g.ApplyBasic(g.GenerateModel("user"), g.GenerateModelAs("account", "AccountInfo"))

	g.Execute()
}

then run ./test.sh

it fails much later:

2024/10/22 23:31:23 /tmp/gorm-playground/db.go:69
[error] failed to initialize database, got error read tcp 127.0.0.1:46478->127.0.0.1:9930: read: connection reset by peer
2024/10/22 23:31:23 failed to connect database, got error read tcp 127.0.0.1:46478->127.0.0.1:9930: read: connection reset by peer
FAIL	gorm.io/playground	0.019s
FAIL

but this passes:

GORM_DIALECT=mysql go test
2024/10/22 23:32:06 testing mysql...

2024/10/22 23:32:07 /tmp/gorm-playground/main_test.go:14
[9.772ms] [rows:1] INSERT INTO `users` (`created_at`,`updated_at`,`deleted_at`,`name`,`age`,`birthday`,`company_id`,`manager_id`,`active`) VALUES ('2024-10-22 23:32:07.486','2024-10-22 23:32:07.486',NULL,'jinzhu',0,NULL,NULL,NULL,false)

2024/10/22 23:32:07 /tmp/gorm-playground/main_test.go:17
[0.524ms] [rows:1] SELECT * FROM `users` WHERE `users`.`id` = 1 AND `users`.`deleted_at` IS NULL ORDER BY `users`.`id` LIMIT 1
PASS
ok  	gorm.io/playground	1.139s

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

8 participants