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

Feature request: enable wrapping EdgeDB types #305

Open
lsdch opened this issue Mar 18, 2024 · 1 comment
Open

Feature request: enable wrapping EdgeDB types #305

lsdch opened this issue Mar 18, 2024 · 1 comment

Comments

@lsdch
Copy link
Contributor

lsdch commented Mar 18, 2024

AFAIK there are currently two ways to bind optional or non-primitive type values with EdgeDB:

  • using one of the provided types in edgedbtypes, e.g. OptionalStr, which cannot be extended with additional methods
  • implementing one of the EdgeDB{*}Marshaler interfaces, which is cumbersome when you have to do it for multiple types

Would it be possible to expose an interface that custom wrappers for EdgeDB-compatible types could implement ?
Something like:

type EdgeDBTypeWrapper[T any] interface {
  Value() *T
}

EdgeDBTypeWrapper.Value() could then be used internally to retrieve the wrapped type and marshal/unmarshal values when interacting with EdgeDB.

Example use-case:

type OptionalStrWrapper struct {
  edgedb.OptionalStr
}

func (o OptionalStrWrapper) Value() *edgedb.OptionalStr {
  return o.OptionalStr
}

func (o OptionalStrWrapper) SomeMethodUnrelatedToEdgeDB() {
  // ...
}

I would be willing to submit a PR for this, but I am not sure where to start. Would it be as simple as adding an extra case in codecs.*.Encode methods ?

@fmoor
Copy link
Member

fmoor commented Mar 18, 2024

I understand the friction. There may be room for improvement here. I'll have to think about this.

It seems like there should be an interface for decoding too.

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