gopherdata / gopherdata/gophernotes

unimplemented type

未关闭
#265 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Go
星标
4k
派生
264
平均合并
7 天 21 小时
30 天内合并 PR
1

描述

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

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

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。