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

FQL Query string interpolation #36

Closed
cynicaljoy opened this issue Feb 6, 2023 · 0 comments
Closed

FQL Query string interpolation #36

cynicaljoy opened this issue Feb 6, 2023 · 0 comments

Comments

@cynicaljoy
Copy link
Contributor

cynicaljoy commented Feb 6, 2023

I'm trying to sort out a good UX for creating a query, what do people think about:

var addr string
...
client.Query(FQL(`IndexedRead.byAddress(${address}) { name: .data.name }`, QueryArgs(Arugment("address", addr)))

This would change the Query method contract from:

type QueryArgs map[string]interface{}

func (c *Client) Query(fql string, args QueryArgs, obj interface{}, opts ...QueryOptFn) (*Response, error)

to:

func (c *Client) Query(query FQLQuery, obj interface{}, opts ...QueryOptFn) (*Response, error)

func FQL(input string, args QueryArg) FQLQuery

we'd parse the string for all ${vars} and iterate through all of the QueryArg and if any are missing we'd return an error. I like wrapping in ${} as it makes it a bit easier to read, it's easier to parse out (we can actually use os.Expand almost turnkey) and it's inline with the current proposal for adding string interpolation the language. Though, that's also a con IMO...feels like we'd eventually be trampling on std lib in a bit of a weird way, but that proposal might never be accepted so probably best to sort it out if it ever becomes an issue if we're otherwise happy with that pattern.

I'm not loving the naming though...maybe something like:

func (c *Client) Do(query QueryInput, obj interface{}, opts ...QueryOptFn) (*Response, error)

func Query(query string, args QueryArgs) QueryInput

I feel like Do is a little more idiomatic Go (see: http.Client.Do) and we avoid Query(<query>) or using the language acronym as a struct type.

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