go-enum icon indicating copy to clipboard operation
go-enum copied to clipboard

questions about empty strings

Open liuzh825 opened this issue 3 years ago • 3 comments

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?

liuzh825 avatar Jun 20 '22 03:06 liuzh825

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.

abice avatar Jun 20 '22 04:06 abice

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

Rain-JK avatar Jul 01 '22 06:07 Rain-JK

+1

dingyaguang117 avatar Sep 01 '22 12:09 dingyaguang117

+1

emfadei avatar Mar 21 '23 13:03 emfadei

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.

abice avatar Mar 21 '23 15:03 abice

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

emfadei avatar Mar 22 '23 13:03 emfadei

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 avatar Mar 22 '23 13:03 abice

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 avatar May 07 '23 17:05 abice