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

DB #846

Closed
Re-Wi opened this issue Oct 29, 2023 · 6 comments · Fixed by cloudwego/cwgo#94
Closed

DB #846

Re-Wi opened this issue Oct 29, 2023 · 6 comments · Fixed by cloudwego/cwgo#94
Assignees
Labels
bug Something isn't working Cwgo

Comments

@Re-Wi
Copy link

Re-Wi commented Oct 29, 2023

此命令cwgo model --db_type sqlite --dsn database.db
生成的的代码为:

// SqliteSequence mapped from table <sqlite_sequence>
type SqliteSequence struct {
	Name string `gorm:"column:name;type:" json:"name"`
	Seq  string `gorm:"column:seq;type:" json:"seq"`
}

运行代码报错:

[error] unsupported data type: 0xc0004556c0
panic: Cannot parse model: &{Name: Seq:}
unsupported data type: 0xc0004556c0

goroutine 1 [running]:
gorm.io/gen.(*DO).UseModel(0xc000160aa8, {0x7ff69aaaac00, 0xc0002bee80})
        D:/Go/workspace/pkg/mod/gorm.io/gen@v0.3.23/do.go:83 +0x10e
ToolKitHub/biz/dal/query.newSqliteSequence(_, {_, _, _})

去掉这里的两个type:,就可以成功运行了

@Re-Wi Re-Wi added the bug Something isn't working label Oct 29, 2023
@li-jin-gou
Copy link
Member

@Re-Wi 发下数据库吧,这个看起来是 gen 生成 model 的时候报错了 cc @chaoranz758

@rogerogers
Copy link
Contributor

sqlite_sequence 和 sqlite_master 是 sqlite 的系统表,感觉本不应该被生成出来,这个问题应该算是 gen 本身的一个问题。

@Re-Wi
Copy link
Author

Re-Wi commented Oct 29, 2023 via email

@li-jin-gou
Copy link
Member

sqlite_sequence 和 sqlite_master 是 sqlite 的系统表,感觉本不应该被生成出来,这个问题应该算是 gen 本身的一个问题。

看起来是的

@chaoranz758
Copy link
Member

就是随便建了一个sqlite数据库测试,建数据库的工具是:db browser for sqlite | | @.*** | | @.*** |

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2023年10月29日 18:25 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [cloudwego/cloudwego.github.io] DB (Issue #846) | @Re-Wi 发下数据库吧,这个看起来是 gen 生成 model 的时候报错了 cc @chaoranz758 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

type 后面需要指定字段对应的数据库字段类型,在 type 后面补上类型或者删掉 type 应该都不会报错,这个问题与 cwgo 侧无关

@rogerogers
Copy link
Contributor

gen没有提供exclude的相关方法,但是提供了匹配的自定义方法 https://github.com/go-gorm/gen/blob/f53462308098236f5c5d29117e37f1c7580a7e2a/config.go#L82
感觉可以定义个 exclude 来去掉某些表。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Cwgo
Development

Successfully merging a pull request may close this issue.

4 participants