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

Add namespacing/modules #579

Open
pkarw opened this issue Apr 23, 2021 · 6 comments
Open

Add namespacing/modules #579

pkarw opened this issue Apr 23, 2021 · 6 comments
Labels
enhancement New feature or request
Milestone

Comments

@pkarw
Copy link
Collaborator

pkarw commented Apr 23, 2021

Is your feature request related to a problem? If yes, please describe the problem.

When we'd like to implement a more broad set of the resources/integrations we'll encounter a namespacing issue, kind of modules/namespaces/groups would be a handy solution to it.

For example when we'd like to develop the resources for accessing MySQL and MongoDB both ORM modules could potentially have a method like mysql:findOne({}) / mongodb:findOne({}). There's actually no way for avoid resource overlapping other than naming convention (egmysql_findOne() - which actually is not an elegant solution)

@pkarw pkarw added the enhancement New feature or request label Apr 23, 2021
@pkarw
Copy link
Collaborator Author

pkarw commented Apr 23, 2021

... the simplest possible solution could be to extend the run() method on vm to let the officially registered resources return methods or return sub-resources (chaining) etc. we're not talking about the OOP methods - however this could potentially be a great solution too

@czerwinskilukasz1
Copy link
Collaborator

@pkarw , the issue I see here is that currently code like mysql:findOne() is just a syntactic sugar over findOne(mysql), which means that regardless what kind of variable mysql is, the very same findOne() function will be called.
The translation is not done in run() in vm, which is called when executing the parsed program, but much earlier - when parsing the AskScript source code into AST.

@czerwinskilukasz1
Copy link
Collaborator

On the other hand, what I think we could do is to have a way to return a MySQL object which has a number of fields, each of them being a function (e.g. field findOne being a function for finding a single row in a table etc.) and then run mysql.findOne().
Please note that here we use dot instead of the colon. In AskScript we used colon for the "method" syntax sugar and method chaining, but dot for accessing properties (see e.g. this sample .ask file: https://github.com/CatchTheTornado/askql/blob/master/src/askscript/__tests__/08-objects-records/objects-14-key_access.ask )

@czerwinskilukasz1
Copy link
Collaborator

This way we could have:

// mysql - a resource that has several fields with functions, e.g. connect 
conn = mysql.connect('host', 'user', 'pass')
conn.useDb('dbname')
row = conn.findOne('text to search for')

@pkarw
Copy link
Collaborator Author

pkarw commented May 3, 2021

@czerwinskilukasz1 good point. I think it's a great way to go for this FR; it's somewhat clarifying the #580 as well (I mean the "dot" notation could be used to have both #579 and #580 up)

@czerwinskilukasz1 czerwinskilukasz1 added this to the v2.0 (draft) milestone May 17, 2021
@mhagmajer
Copy link
Contributor

Blocked by #589

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

3 participants