Open pumoica opened 7 months ago
Hello,
Am trying to build a notebook with the following code snippet (compiles and works correctly as a standalone program). However, the kernel chokes and spits out the following message:
repl.go:52:15: unimplemented type: db.Create(&car) <*ast.CallExpr>.
Any suggestions what could cause the problem? The snippet and go env are provided below.
Code Snippet:
import ( "fmt" "log" "os" "gorm.io/gorm" "gorm.io/driver/postgres" ) type PetExample struct { //gorm.Model Name string `json:"name"` Animal string `json:"animal"` } type CarExample struct { //gorm.Model Color string `json:"color"` Make string `json:"make"` Year int `json:"year"` CarModel string `json:"model"` } func connectToDB() (*gorm.DB, error) { dsn := "<connection string>" // Attempt to open a connection to the database. db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) if err != nil { return nil, fmt.Errorf("failed to connect to database: %w", err) } log.Println("Database connection successfully established.") return db, nil } log.SetOutput(os.Stdout) log.Println("Attempting to connect to the database...") var err error db, err = connectToDB() log.Printf("DB: %v", db) if err != nil { log.Printf("Error connecting to the database: %v", err) // Return or handle the error appropriately } else { log.Println("Connected to the database successfully!") // Create a CarExample Model car := CarExample{Color: "Red", Make: "Ford", Year: 2019, CarModel: "F150"} if err := db.Create(&car).Error; err != nil { log.Printf("Failed to create CarExample: %v", err) } else { log.Printf("CarExample created successfully: %+v", car) } }
Go Env
GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/work/.cache/go-build" GOENV="/work/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/work/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/work/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.19.4" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" 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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2381839480=/tmp/go-build -gno-record-gcc-switches"
Hello,
Am trying to build a notebook with the following code snippet (compiles and works correctly as a standalone program). However, the kernel chokes and spits out the following message:
repl.go:52:15: unimplemented type: db.Create(&car) <*ast.CallExpr>.
Any suggestions what could cause the problem? The snippet and go env are provided below.
Code Snippet:
Go Env