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 · 3 comments
Open

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

cindoralla opened this issue Jan 15, 2025 · 3 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.

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

2 participants