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

Can I generate model with pointer fields? gf gen dao #4119

Open
cindoralla opened this issue Jan 15, 2025 · 5 comments
Open

Can I generate model with pointer fields? gf gen dao #4119

cindoralla opened this issue Jan 15, 2025 · 5 comments

Comments

@cindoralla
Copy link

cindoralla commented Jan 15, 2025

Description

Thanks for the great work! When using "gf gen dao", the fields of mysql are not null, could you please add a config to make them as pointers? Because our system contains lots of nullable fields and existed logics using the nullable. So I cannot directly make them as not-null.

Additional

No response

@cindoralla
Copy link
Author

And now I manually edit the entity dao files to mark the fields as pointers, but it's a good idea.

@niluan304
Copy link
Contributor

good idea.

localTypeNameStr = string(localTypeName)
switch localTypeName {
case gdb.LocalTypeDate, gdb.LocalTypeTime, gdb.LocalTypeDatetime:
if in.StdTime {
localTypeNameStr = "time.Time"
} else {
localTypeNameStr = "*gtime.Time"
}
case gdb.LocalTypeInt64Bytes:

need to add new config field ?

	localTypeNameStr = string(localTypeName)
	nullToPtr := true // need new config field to enabled null to pointer.
	if nullToPtr && field.Null && !strings.HasPrefix(localTypeNameStr, "*") {
		localTypeNameStr = "*" + localTypeNameStr
	}
	switch localTypeName {
	case gdb.LocalTypeDate, gdb.LocalTypeTime, gdb.LocalTypeDatetime:

@cindoralla
Copy link
Author

good idea.

gf/cmd/gf/internal/cmd/gendao/gendao_structure.go

Lines 100 to 109 in e0f7348

localTypeNameStr = string(localTypeName)
switch localTypeName {
case gdb.LocalTypeDate, gdb.LocalTypeTime, gdb.LocalTypeDatetime:
if in.StdTime {
localTypeNameStr = "time.Time"
} else {
localTypeNameStr = "*gtime.Time"
}

case gdb.LocalTypeInt64Bytes:
need to add new config field ?

localTypeNameStr = string(localTypeName)
nullToPtr := true // need new config field to enabled null to pointer.
if nullToPtr && field.Null && !strings.HasPrefix(localTypeNameStr, "") {
localTypeNameStr = "
" + localTypeNameStr
}
switch localTypeName {
case gdb.LocalTypeDate, gdb.LocalTypeTime, gdb.LocalTypeDatetime:

Thanks! Let me have a try.

@gqcn
Copy link
Member

gqcn commented Feb 11, 2025

@cindoralla @niluan304 Hello, a configuration option is a good idea. A PR will be appreciated.

Copy link

Hello @cindoralla. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!
你好 @cindoralla。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants