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

unimplemented type #265

Open
pumoica opened this issue Apr 8, 2024 · 0 comments
Open

unimplemented type #265

pumoica opened this issue Apr 8, 2024 · 0 comments

Comments

@pumoica
Copy link

pumoica commented Apr 8, 2024

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"
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

1 participant