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

Replace the bind method with named parameter #3

Open
NicklasWallgren opened this issue Apr 5, 2022 · 4 comments
Open

Replace the bind method with named parameter #3

NicklasWallgren opened this issue Apr 5, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@NicklasWallgren
Copy link
Owner

It might be a good idea to replace the current {{bind .Id}} method with typical named parameters e.g. :id.

sqlx supports it https://github.com/jmoiron/sqlx/blob/a62bc6088664eb854c3d5ebbd08a1ffd59662ef1/named.go#L331

It would probably increase the memory usage as well as cpu utilization, but it might be worth with.

@NicklasWallgren NicklasWallgren added the enhancement New feature or request label Apr 5, 2022
@NicklasWallgren NicklasWallgren changed the title Replace the bind method with named parameters Replace the bind method with named parameter Apr 5, 2022
@pivaldi
Copy link
Collaborator

pivaldi commented Sep 28, 2023

If this this pull request is accepted, it will be easy to add any bindings engine as named placeholder.

@pivaldi
Copy link
Collaborator

pivaldi commented Sep 28, 2023

Having thought about it, I wonder what would be the point of making a binding when it would be enough to write down the named parameter yourself…
What is the gain to write {{bind .Id}} to obtain :id instead of directly write :id in the template ? 🤔

@NicklasWallgren
Copy link
Owner Author

What is the gain to write {{bind .Id}} to obtain :id instead of directly write :id in the template ? 🤔

You don't know beforehand which query params are to be expected, due to potential if-statements/conditionals in the template. We cannot deduce which query parameters the generated query expects without the bind method.

@pivaldi
Copy link
Collaborator

pivaldi commented Sep 29, 2023

OK, I understand, you expect a universal binding engine.

I don't think the actual bind engine should be replaced by a named bind because this will introduce a strong dependency with sqlx or other ORM-like.
Maybe an other type of binding ? nbind (for named bind)

Note that it will be impossible that {{nbind .Id}} gives :id because .Id is the value, not the field name…
Or use regexp replace, which will not be as reliable as default template parsing.

Why the binding engine will not replace {{nbind .Id}} by his own named binding :UNIQ_HASH and GetParams will return the corresponding map[string]any usable with sqlx ?

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

2 participants