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

generate types #16

Open
malikbenkirane opened this issue Jun 14, 2023 · 0 comments
Open

generate types #16

malikbenkirane opened this issue Jun 14, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@malikbenkirane
Copy link
Contributor

malikbenkirane commented Jun 14, 2023

I showcase here how we could create a type generator for your exported types in your adapter package. Some go machinery and other magic tricks and that should be it 😇

// your public types
type A struct {
	S string
}

// go generated private types
type (
	fA_S string

	fA_DocID surrealhigh.Id

	aDoc struct {
		S fA_S `json:"s"`

		DocId fA_DocID `json:"id"`
	}
)

func (doc aDoc) Id() surrealhigh.Field {return doc.DocID}
func (doc aDoc) Table() surrealhigh.Table {return "a"}

func (_ fA_S) Field() surrealhigh.Field {return "s"}
func (_ fA_DocID) Field() surrealhigh.Field {return "id"}
func (id fA_DocID) MarshalJSON() ([]byte, error) {
	sid := surrealhigh.Id(id)
	// marshal id to thing
}
func (id fA_DocID) UnmarshalJSON([]byte) (error) {
	// unmarshal thing to id [16]byte
}
@malikbenkirane malikbenkirane added the enhancement New feature or request label Jun 14, 2023
@malikbenkirane malikbenkirane self-assigned this Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant