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

MongoDB feature for marshalling and unmarshalling Option struct #1

Open
davidbayo10 opened this issue Jul 8, 2022 · 3 comments
Open

Comments

@davidbayo10
Copy link

Hi,

Just a little question. Could be possible to marshal and unmarshal MongoDB structs with Option properties?

If you try to Decode a Cursor result, It not fits the Option struct because of value property

e.g.

type Record struct {
	Date1 safetypes.Option[time.Time] `bson:"date1,omitempty"`
	Date2  safetypes.Option[time.Time] `bson:"date2,omitempty"`
}

Input:

[
  {
    date1: "2022-08-30T00:00:00.000Z"
  },
  {
    date2: "2022-09-30T00:00:00.000Z"
  }
]

Marshalled records have this struct:

Record { Date1 { value: nil } Date2 { value: nil } }

I would like to decode this array into

Desire:

records[0].Date1.IsSome() == true
records[0].Date2.IsNone() == true

records[1].Date1.IsNone() == true
records[1].Date2.IsSome() == true

I like this lib for allow go structs be "Rust Like". I hope this could be possible
Thank you all in advance

@eminarican
Copy link
Owner

Okay, I'll look into it today in my free time thanks for the issue ^^

@eminarican
Copy link
Owner

oopsie .d

@eminarican
Copy link
Owner

@davidbayo10 I've tested it using json, probably works fine but could you test using latest commit? I'm not at home currently so its a bit troublesome for me 😅

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

2 participants