go-gorm / playground

GORM Playground (Please Create PR for this project to report issues)
MIT License
91 stars 697 forks source link

Project doesn't compile/run #751

Closed robertoneto-senior closed 1 week ago

robertoneto-senior commented 4 months ago

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 commented 3 months ago

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

vivere-dally commented 2 months ago

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

YidiDev commented 2 months ago

I also have this issue

henryjcee commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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

maxant commented 1 month ago

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
CrazyThursdayV50 commented 1 week ago

i've solved this problem with these steps:

  1. clone github.com/go-gorm/gen

    git clone git@github.com:go-gorm/gen.git
  2. find all the "gorm.io/gen/examples" in "import", and replace them with "examples"

before:

import (
    "xxxxxx"
    "gorm.io/gen/examples"
    "gorm.io/gen/examples/xxxx"
)

after:

import (
    "xxxxxx"
    "examples"
    "examples/xxxx"
)
  1. run go mod download in github.com/go-gorm/gen/examples

    cd PATH/TO/YOUR/{github.com/go-gorm/gen/examples}
    go mod download
  2. update the go.mod in playground

    
    # add this line
    require gorm.io/gen/examples v0.3.25

add this line

replace gorm.io/gen/examples v0.3.25 => PATH/TO/YOUR/{github.com/go-gorm/gen/examples}



5. run test.sh in playgound