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

questions about empty strings #114

Closed
liuzh825 opened this issue Jun 20, 2022 · 9 comments
Closed

questions about empty strings #114

liuzh825 opened this issue Jun 20, 2022 · 9 comments

Comments

@liuzh825
Copy link

Two questions about empty strings:

  1. Enumeration values currently do not support empty strings? (because there is a valid empty string case)
  2. The mysql type is varchar, default: "". In this case, the Scanner and Valuer interfaces can only be implemented manually?
@abice
Copy link
Owner

abice commented Jun 20, 2022

Do you mind expanding on the use case for an empty string enum value?

And if you need to implement a different sql/valuer interface methods, you can create a custom template and have the tool use that for your use case if the provided one doesn't do the right thing for you.

@Rain-JK
Copy link

Rain-JK commented Jul 1, 2022

I think "" maybe is useful for some table schema design like varchar, which is don't want to be null,

sometimes is easier for programing dont need deal with null

@dingyaguang117
Copy link

+1

1 similar comment
@emfadei
Copy link

emfadei commented Mar 21, 2023

+1

@abice
Copy link
Owner

abice commented Mar 21, 2023

With the addition of string enums, you should be able to do this by adding an entry empty = "", or whatever you want to call it.

Let me know if this doesn't work for you.

@emfadei
Copy link

emfadei commented Mar 22, 2023

You mean ENUM(empty = "", value1) ?
Is is not parsed
failed parsing the data part of enum value 'empty = ""': strconv.ParseUint: parsing """": invalid syntax

@abice
Copy link
Owner

abice commented Mar 22, 2023

I mean

//ENUM(empty="", value1)
type TestEnum string

The use case in question is about parsing empty strings as part of SQL, which would assume that there is no need for an integer part, so simply using strings would solve the problem at hand.

@abice
Copy link
Owner

abice commented May 7, 2023

Thanks again for the interest in the project... I'm going to close this ticket now, but if you have troubles with it still... please either reopen or open a new ticket and I'll see what I can do to resolve it for you.

Thanks!

@abice abice closed this as completed May 7, 2023
@nikki-dzhurov
Copy link

nikki-dzhurov commented Aug 14, 2024

Hey @abice, I have very similar case - is there something similar for number-based enum types ? Probably what I want to achieve is kind of related to: #207

Here is my example in which I want unset to allow empty strings in the Unmarshal/Scan methods:

// ENUM(unset, a,b,c).
type TestEnum uint8

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

6 participants